各种哈希函数的C语言程序代码

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

¸½£º¸÷ÖÖ¹þÏ£º¯ÊýµÄCÓïÑÔ³ÌÐò´úÂë{unsignedinthash=0;while(*str){//equivalentto:hash=65599*hash+(*str++);hash=(*str++)+(hash6)+(hash16)-hash;}return(hash&0x7FFFFFFF);}//RSHashunsignedintRSHash(char*str){unsignedintb=378551;unsignedinta=63689;unsignedinthash=0;while(*str){hash=hash*a+(*str++);a*=b;}return(hash&0x7FFFFFFF);}//JSHashunsignedintJSHash(char*str){unsignedinthash=1315423911;while(*str){hash^=((hash5)+(*str++)+(hash2));}return(hash&0x7FFFFFFF);}//P.J.WeinbergerHashunsignedintPJWHash(char*str){unsignedintBitsInUnignedInt=(unsignedint)(sizeof(unsignedint)*8);unsignedintThreeQuarters=(unsignedint)((BitsInUnignedInt*3)/4);unsignedintOneEighth=(unsignedint)(BitsInUnignedInt/8);unsignedintHighBits=(unsignedint)(0xFFFFFFFF)(BitsInUnignedIntunsignedintSDBMHash(char*str)-OneEighth);unsignedinthash=0;unsignedinttest=0;while(*str){hash=(hashOneEighth)+(*str++);if((test=hash&HighBits)!=0){hash=((hash^(testThreeQuarters))&(~HighBits));}}return(hash&0x7FFFFFFF);}//ELFHashunsignedintELFHash(char*str){unsignedinthash=0;unsignedintx=0;while(*str){hash=(hash4)+(*str++);if((x=hash&0xF0000000L)!=0){hash^=(x24);hash&=~x;}}return(hash&0x7FFFFFFF);}//BKDRHashunsignedintBKDRHash(char*str){unsignedintseed=131;//31131131313131131313etc..unsignedinthash=0;while(*str){hash=hash*seed+(*str++);}return(hash&0x7FFFFFFF);}//DJBHashunsignedintDJBHash(char*str){unsignedinthash=5381;while(*str){hash+=(hash5)+(*str++);}return(hash&0x7FFFFFFF);}//APHashunsignedintAPHash(char*str){unsignedinthash=0;inti;for(i=0;*str;i++){if((i&1)==0){hash^=((hash7)^(*str++)^(hash3));}else{hash^=(~((hash11)^(*str++)^(hash5)));}}return(hash&0x7FFFFFFF);}

1 / 4
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功