这是 Java HashTable 类的 hashCode() 实现。如果哈希表中的元素数量很大并且哈希码超过 INTEGER MAX LIMIT -2,147,483,648 到 2,147,483,647 怎么办?我假设 hashCodes 将是正整数。
public synchronized int hashCode() {
int h = 0;
if (count == 0 || loadFactor < 0)
return h; // Returns zero
loadFactor = -loadFactor; // Mark hashCode computation in progress
Entry[] tab = table;
for (int i = 0; i < tab.length; i++)
for (Entry e = tab[i]; e != null; e = e.next)
h += e.key.hashCode() ^ e.value.hashCode();
loadFactor = -loadFactor; // Mark hashCode computation complete
return h;
}