static int hash(int h) {这个是他的HASH算法,通过这个把这个KV放到数组下,然后,在他取值的时候,他会调用INDEXFOR方法
// 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);
}
static int indexFor(int h, int length) {。我想问的是,为什么以上两端代码要这样写?
return h & (length-1);
}
------解决思路----------------------
单独研究这个
h ^= (h >>> 20) ^ (h >>> 12);
通过位移之后,数值已经均匀分布到不同位段之上,再异或,结果就会尽可能不同