`

一个对字符串很好的Hash函数ELFHHash

阅读更多
#include<stdio.h>
#define M 10000

int ELFHash(char *key){
	unsigned long h = 0;
	unsigned long g;
	while(*key){
		h = (h<<4) + *key++;
		g= h & 0xf0000000L;
		if(g) h ^= g >> 24;
		h &= ~g;
	}
	return h % M;
}

int main(){
	char s[100];
	while(scanf("%s",s)){
		printf("hash %s=%d\n",s,ELFHash(s));
	}
	return 0;
}

 BTW:用gcc编译C++方法 gcc -o test.out test.cpp -lstdc++

如果没有-lstdc++能编译,但无法链接接到库

2
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics