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