一个简单的英文字符串哈希函数
#include <string.h>
typedef unsigned long u_long;
u_long hash_string(const char* s, int len)
{
u_long h = 0;
int i = 0;
if (len < 0)
len = (s ? (int) strlen(s) : 0);
while ( i++ < len)
{
h = 17 * h + * s++;
}
return h;
}
从别处转来的,找不到转载地址了。- -
经过测试,在大容量数组中定位,插入50000个字符串,冲突大部分能控制在2、3个左右,效果还是不错的。
-------------------------------------------------
本博客中凡是未标明【转】字样的文章均为原创,作者保留版权,转载请务必保留原文地址。
博客地址:http://xuxn.cnblogs.com
如有问题请联系:xuxin1123@gmail.com
本博客中凡是未标明【转】字样的文章均为原创,作者保留版权,转载请务必保留原文地址。
博客地址:http://xuxn.cnblogs.com
如有问题请联系:xuxin1123@gmail.com

浙公网安备 33010602011771号