简单地说,我有一个单词字典,我将它们添加到哈希表中。
我正在使用双散列(不是传统方法),以下是产生最好的结果。
public static int getHashKey(String word) {
int index = 0;
for(int i = 0; i<word.length(); i++){
index += Math.pow(4, i)*((int)word.charAt(i));
index = index % size;
}
return index;
}
public static int getDoubleHashKey(String word) {
int jump = 1;
for(int i = 0; i<word.length(); i++){
jump = jump * word.charAt(i);
jump = jump % size;
}
return jump;
}
这给了我 127,000 次碰撞。我还有一个 2 倍的素数哈希表大小,它无法更改。
有什么办法可以改进双散列算法?(上述两种方法中的任何一种)。
我知道这取决于我们在哈希表中存储的内容等,但是是否有任何直观的方法或一些更普遍适用的技巧,这样我就可以避免更多的冲突。