Can anyone explain me the logic behind this hash-function?.
static int hash(int h) {
h ^= (h >>> 20) ^ (h >>> 12);
return h ^ (h >>> 7) ^ (h >>> 4);
}
I pass the key.hashCode()
to this function which gives me the hash value. Based on this value and the Array size, i calculate the index of the array. I am just not understanding the operator used here in this method.
- What does this
^
operator do here in this context. Does it check for != - What does Unsigned right shift >>> do?. We don't have Unsigned int's in Java right?.
- How are the values 20, 12, 7 and 4 chosen for this function?. Is it pre defined or user defined?.
The key.hashCode()
passed to this hash function is 79847235
. Can anyone explain on what happens inside to return the final hash value.