【发布时间】:2020-04-01 22:19:30
【问题描述】:
在给出的代码中,它试图通过使用另一种方法 linearprobe 检查任何冲突来为哈希表提供有效索引。我只是对为什么我们需要检查 index
private int getHashIndex(K key)
{
//1.convert key to hashcode, then get the index;
//2. then use linear probing to check for the correct index;
int index = key.hashCode() % hashTable.length;
if(index < 0) { //So a hash code can be negative?
index += hashTable.length;
}
index = linearProbe(index,key);
return index;
}
【问题讨论】:
标签: java hash hashtable hashcode