0

In HashMap.java method hash

        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);
        } 

// method hash

after calculating the hash code, there are few right shifts and bit-wise "exclusive-or" operators, Is there any reason to choose the number ("20"&"12") then "7"&"4"

        h ^= (h >>> 20) ^ (h >>> 12);
        return h ^ (h >>> 7) ^ (h >>> 4);

Definately the h is scrambling, can some help to explain this what exactly is getting solved?

4

0 回答 0