HashMap in the hash table location algorithm:

int hash = hash(key.hashCode()); int i = indexFor(hash, table.length);

One indexFor and hash source as follows:

/** * Applies a supplemental hash function to a given hashCode, which * defends against poor quality hash functions. This is critical * because HashMap uses power-of-two length hash tables, that * otherwise encounter collisions for hashCodes that do not differ * in lower bits. Note: Null keys always map to hash 0, thus index 0. */ 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); } /** * Returns index for hash code h. */ static int indexFor(int h, int length) { return h & (length-1); }

indexFor forum this method has been analyzed, there is no longer analysis.

Now analysis of hash algorithms:

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

Suppose key.hashCode () value: 0x7FFFFFFF, table.length to the default value of 16.

The implementation of the above algorithm is as follows:

Be i = 15

Among

h ^ (h>>> 7) ^ (h>>> 4) results in the bit run identification is to h>>> 7 replaced by h>>> 8 run.

Final h ^ (h>>> 8) ^ (h>>> 4) After computing the value of each hashCode values are as follows:

8 = 8

7 = 7 ^ 8

6 = 6 ^ 7 ^ 8

5 = 5 ^ 8 ^ 7 ^ 6

4 = 4 ^ 7 ^ 6 ^ 5 ^ 8

3 = 3 ^ 8 ^ 6 ^ 5 ^ 8 ^ 4 ^ 7

2 = 2 ^ 7 ^ 5 ^ 4 ^ 7 ^ 3 ^ 8 ^ 6

1 = 1 ^ 6 ^ 4 ^ 3 ^ 8 ^ 6 ^ 2 ^ 7 ^ 5

Results in duplication of 2,3-two-bit computing ^

3 = 3 ^ 8 ^ 6 ^ 5 ^ 8 ^ 4 ^ 7 -> 3 ^ 6 ^ 5 ^ 4 ^ 7

2 = 2 ^ 7 ^ 5 ^ 4 ^ 7 ^ 3 ^ 8 ^ 6 -> 2 ^ 5 ^ 4 ^ 3 ^ 8 ^ 6

Uehara hashCode lowest of eight are involved in the ^ operator, so table.length the case for the default values of 16 below, hashCode any position changes can be reflected in the final hash table positioning algorithm.

Algorithm is used (h>>> 7) rather than (h>>> 8) of the algorithm, I do not know whether it is considered a duplication of the two-bit ^ 2,3 computing situation.

Use (h>>> 7) If the default value of 16 in table.length where the first three original hashCode high a change will not respond to the results, namely: 0x7FFFF7FF of i = 15.