while(temp1!=NULL){ temp2=temp1;temp1=temp1->next; delete temp2; }
head[i]=NULL; }
count=0; }
unsigned int MyHash(char *str){//自己设计哈希函数具体实现 unsigned int hashcount=0; unsigned int x=0; int i=0; while(*str){
if((i&1)==0){
hashcount=((hashcount<<3)+*(str++)); }else{
hashcount=((hashcount<<5)+~(*str++)); }
if((x=hashcount&0xF0000000)!=0){ hashcount=hashcount^(x>>24); hashcount=hashcount&(~x); } }
return (hashcount&0x7FFFFFF); }
unsigned int APHash(char *str){//AP哈希函数 unsigned int hashcount=0; int i;
for(i=0;*str;i++){ if((i&1)==0){
hashcount^=((hashcount<<7)^(*str++)^(hashcount>>3)); }else{
hashcount^=(~((hashcount<<11)^(*str++)^(hashcount>>5))); } }
return (hashcount&0x7FFFFFFF); }
unsigned int BKDRHash(char *str){//BKDR哈希函数 unsigned int seed=131; unsigned int hashcount=0; while(*str){
hashcount=hashcount*seed+(*str++); }
return (hashcount&0x7FFFFFF); }
unsigned int ELFHash(char *str){//ELF哈希函数 unsigned int hashcount=0; unsigned int x=0; while(*str){
hashcount=(hashcount<<4)+(*str++); if((x=hashcount&0xF0000000)!=0){ hashcount^=(x>>24); hashcount&=~x; } }
return hashcount; } private:
Node**head;//哈希表头 int length;//哈希表长
int count;//读入字符串数量
FILE*file;//数据读入文件头指针 float backet_usage;//桶的使用率 float avg_backet_len;//平均桶长 };
int main()
{
Hash hash(90000);
hash.SetFile(90000);//进行10000个随机数据哈希函数性能的比较 hash.HashTest(0);//BKDR,
hash.HashTest(1);//ELF
hash.HashTest(2);//AP
hash.HashTest(3);//自己设计哈希函数 return 0; }