In the HashMap implementation in Java, after computing the hash value of the key object, I guess that the function, hash(int hashvalue), is used on it to further randomize the hash values generated. As it does right shift, it randomizes the LSB bits more. Why don't they randomize the MSB too by performing left Shift?
Instead of doing like
h ^= (h >>> 20) ^ (h >>> 12); // Here the bits from 21 position bit from right are unchanged // Consider a case where the hash values of the inputs are in the range (2^21) -(2^22), the values will be distributed in the buckets with index from (2^21) -(2^22) and the remaining buckets in the hash map are unused.
return h ^ (h >>> 7) ^ (h >>> 4); // which randomizes the LSB part more.
Why can't they do something like
h ^= (h >>> 20) ^ (h >>> 12) ^ (h <<< 20) ^ (h <<< 12); // This randomizes both LSB bits and MSB bits
return h ^ (h >>> 7) ^ (h >>> 4) ^ (h <<< 7) ^ (h <<< 4);
As a result we will get a random number with random MSB and LSB bits .