【发布时间】:2016-04-14 16:03:09
【问题描述】:
我正在做一个哈希表,并实现了以下哈希函数
int linesn=8;
int hash(char *str, int table_size)
{
int sum;
// Make sure a valid string passed in
if (str==NULL) return -1;
// Sum up all the characters in the string
for( ; *str; str++) sum += *str;
// Return the sum mod the table size
return sum % table_size;
}
char *str="Carlos";
int hashv=hash(str,linesn);
printf("\nThe hash value is: %d",hashv);
由于存在任何哈希函数冲突,如何实现重新哈希函数来防止这些冲突,我在 Google 上阅读,但示例对我来说很复杂,任何人都可以给我一个想法。
提前致谢
【问题讨论】:
-
你可能有一个稍微好一点的哈希函数;见this
标签: c hashtable hash-function