unsigned long hash(unsigned char *str)
{
unsigned long hash = 5381;
int c;
while (c = *str++)
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
return hash;
}
用这个函数hash几张图片,得到了同样的值,应该是遇到了0,改进一下
把while循环改成for循环就可以了,不过需要知道字符串的长度
unsigned long hash(unsigned char *str, int size)
{
unsigned long hash = 5381;
int i;
for (i = 0; i < size; i++)
{
int c = (int)str[i];
hash = hash * 33 + c;
}
return hash;
}