If we have a set of pointers we know are aligned to sizeof(void *)
whats that fastest way to hash them?
Notes:
Example use case is taking elements of a pointer array or memory allocations and storing in a hash-map. Noting this because this question isn't about the kind of cryptographic hashing needed for passwords, security etc.
By fixed size int, I mean we know the exact size of the int and it wont vary (perhaps this is important since some hashing libraries use
intptr_t
orsize_t
for their hashing return values which might give a different answer to this question).By portable, this should work for 32, 64 bit, big & little endian.
(uint32_t)(((intptr_t)p) >> 2)
gives good results for 32bit, big endian, however I imagine it looses significant bits for 64bit systems, and I'm not sure if this gives a usable distribution for little endian.