基本上,它对long的高32位与低32位进行异或。这是分解版本:
// Unsigned shift by 32 bits, so top 32 bits of topBits will be 0,// bottom 32 bits of topBits will be the top 32 bits of llong topBits = l >>> 32;// XOR topBits with l; the top 32 bits will effectively be left// alone, but that doesn't matter because of the next step. The// bottom 32 bits will be the XOR of the top and bottom 32 bits of llong xor = l ^ topBits;// Convert the long to an int - this basically ditches the top 32 bitsint hash = (int) xor;
回答您的评论:您有一个long值,必须将其转换为int才能作为哈希的一部分(结果必须仅为32位)。你打算怎么做?您 可以 只使用低32位-但这意味着
仅 高32位的更改将被忽略,这不会使其成为一个很好的哈希。这样,输入的单个位的改变 总是 导致哈希的单个位的改变。诚然,您仍然可以轻松地发生冲突-
例如,将第7位和第39位 都 更改,或者将其他任何一对32位位置分开-但是,既然您将要从2 64个可能的值更改为2 32。



