time33 hash
/**************************************************
* time33哈希函数,又叫DJBX33A,Bernstein's hash
* 小写英文词汇适合33, 大小写混合使用65。
* time33比较适合的是英文词汇的hash.
**************************************************/
#include <stdio.h>
#include <string.h>
unsigned long time33(const char *str) {
unsigned long hash = 0;
unsigned int len = strlen(str);
for (int i = 0; i < len; i++)
hash = ((hash <<5) + hash) + (unsigned long) str[i];
return hash;
}
int main(int argc, const char *argv[]) {
char *str = "this is a test string";
printf("Hash:%lu",time33(str));
return 0;
}