33 算法。
作用:将字符串映射成一个整数
用法:顾名思义,每次用ANSIC值乘 33,做法类似进制。
hash(i) = hash(i-1) * 33 + str[i]
下面是优化的代码:
unsigned int DJBHash(const char* str, unsigned int length) { unsigned int hash = 5381; unsigned int i = 0; for (i = 0; i < length; ++str, ++i) { hash = ((hash << 5) + hash) + (*str); } return hash; } 参考文献:
http://www.partow.net/programming/hashfunctions/#top
http://guyot.blog.163.com/blog/static/120574021201011374439716/