[fpc-pascal] Pointer hashing
Ryan Joseph
ryan at thealchemistguild.com
Mon Jan 30 03:37:06 CET 2017
I’m trying to hash a pointer value and found some example of hash function but not sure about translations and the process in general.
1) Should I cast “pointer” as PtrUInt to get an integer from a pointer? I’m looking for the memory address I guess and casting seems to return a unique value. Btw, these functions are for a 32 bit integer but I’m building for 64 bit. How do I deal with that? Can I remove the upper 32bits which are typically not used.
2) I’m getting incompatible type errors on my translation. What did I do wrong there? The fact the function is 32 bit may be the problem?
unsigned int hash(unsigned int x) {
x = ((x >> 16) ^ x) * 0x45d9f3b;
x = ((x >> 16) ^ x) * 0x45d9f3b;
x = (x >> 16) ^ x;
return x;
}
function Hash (x: PtrUInt): PtrUInt;
begin
x := (Power((x shr 16), x)) * $45d9f3b;
x := (Power((x shr 16), x)) * $45d9f3b;
x := Power((x shr 16), x);
result := x;
end;
Thanks for any ideas you have.
Regards,
Ryan Joseph
More information about the fpc-pascal
mailing list