Why the capacity must be a multiple or 2?
Why use “&” in the indexFor functions?
Why recompute the hash in the hash function instead of directly using the key’s hash code?
I think there are some important differences between the this implementation and the description on the “Introduction to Algorithm”.
What does “>>>” mean?
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);
}
Can anyone give me some guide ? I appreciate If some one can explain the hash algorithm.
Thanks a lot!
This is a performance optimization. The usual way to map a hash code to a table index is
The
%operator is expensive. Iftable_lengthis a power of 2, then the calculation:is equivalent to the (much) more expensive modulo operation.