Liste des Groupes | Revenir à cl c |
Richard Harnden <richard.nospam@gmail.invalid> writes:I have a tree structure which represents an XML document. So potentaiily very large, though the code is for the Baby X resource compiler, and people are not want to embed absolutely massive XML data files into C source.On 23/05/2024 12:11, Malcolm McLean wrote:I'd use uintptr_t, not intptr_t. I prefer not to think about howWhat 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;
bitwise operations work on signed values unless I have to.
You're assuming a 16-bit hash. I have no idea whether that suits
Malcolm's requirements.
Another approach might be to divide the pointer representation into
N-bit chunks and xor them together.
Les messages affichés proviennent d'usenet.