Sujet : Re: Good hash for pointers
De : richard.nospam (at) *nospam* gmail.invalid (Richard Harnden)
Groupes : comp.lang.cDate : 23. May 2024, 15:37:44
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v2nkbq$1pt1p$1@dont-email.me>
References : 1
User-Agent : Mozilla Thunderbird
On 23/05/2024 12:11, Malcolm McLean wrote:
What is a good hash function for pointers to use in portable ANSI C?
All your pointers from malloc are going to be unique.
All of their low bits are going to be zero, because they need to align on some n-bit boundary.
All of their high bit are going to be the same, because that's just how it works.
So just take the middle: hash = ((intptr_t) ptr) >> 4 & 0xffff;
Good enough?