Collections-C
Collections-C copied to clipboard
Q: purpose of hashtable_hash_ptr
Newbie here, so please bear with me, but I think I am missing something obvious.
What is the purpose of hashtable_hash_ptr
@ https://github.com/srdja/Collections-C/blob/master/src/hashtable.c#L918 ? My understanding is that it would take a pointer value and compute a hash of it.
But since a pointer is 4-8 bytes in most systems, would it not be more convenient to just use the pointer value itself as the "hash" and save the hashing operations?
Thanks.
Usually you want your hash function to distribute the values evenly in the hashtable. Values of pointers tend to be clumped together. Also pointers are usually aligned to N-bytes, so the last log2(N) bits are zero, therefore after doing modulo of the hash table size, even more values would clump together.