#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++能编译,但无法链接接到库
本文介绍了一个基于C语言的ELF哈希算法实现,并提供了一个简单的命令行工具用于演示如何计算字符串的ELF哈希值。该工具使用gcc进行编译,并且展示了如何链接到标准C++库。
1349

被折叠的 条评论
为什么被折叠?



