Possible Duplicate:
Understanding strange Java hash function
static int hash(int h) {
// This function ensures that hashCodes that differ only by
// constant multiples at each bit position have a bounded
// number of collisions (approximately 8 at default load factor).
h ^= (h >>> 20) ^ (h >>> 12);
return h ^ (h >>> 7) ^ (h >>> 4);
}
I don't quite understand the algorithm principle of this implementation. Any explanation or any resouce I could refer to ? Thanks !
UPDATE
Thanks all for the answers and resouces. Actually I understand how hash works, yet but not konw why this code will ensure a bounded number of collisions
, as the comment says. Is there any theoretical verification?
The main goal is to generate very different values for similar input parameters and minimize number of collisions. http://en.wikipedia.org/wiki/Hash_function
This implementation is just one satisfactory option of many possible functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With