有人可以解释这些常量的重要性以及为什么选择它们?计算java.util.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);
}
来源:java的SE6库
没有重复,也不是答案,但你,如果你正在寻找这个东西可能会发现这个有趣的阅读:http://stackoverflow.com/questions/2538092/why-does-a-hashmap-rehash-在-哈希码提供的,由这关键对象 –
[了解陌生的Java哈希函数(http://stackoverflow.com/questions/9335169/understanding-strange-java-hash-function)的可能重复 – jhurtado
你是非常不可能在这个网站上得到这个问题的答案。最好的人来问将是'HashMap'类的设计者:Doug Lea的,乔希布洛赫,阿瑟·凡·霍夫,和Neal Gafter。尽管如果我不得不猜测我会说这些数字是凭经验确定的。 – Jeffrey