正文

hash function2006-09-29 22:02:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/argol/18951.html

分享到:

经典字符串中出现的hash函数 (转载自http://www.ccw.com.cn/htm/app/aprog/01_8_22_3.asp) 1.  PHP中出现的字符串Hash函数 static unsigned long str_hash_function (char *arKey , unsigned int nKeyLength) { int h=0; int g; char *arEnd=arKey+nKeyLength; while (arKey<arEnd) {     h=(h<<4)+*arKey++;     if ((g=(h&0xF0000000))) {         h=h^(g>>24);         h=h^g; } } return h; } 2.  OpenSSL中出现的字符串Hash函数 unsigned long str_hash_function (char *str) { int i , l; unsigned long ret=0; unsigned short *s; if (str==NULL) return (0); l=(strlen(str)+1)/2; s=(unsigned short *) str; for (i=0;i<l;i++) { ret^=(s[i]<<(i&oxof)); return ret; } unsinged long str_hash_function2 (const char *str) {     unsigned long ret=0;     long n;     unsigned long v;     int r;     if ((c==NULL)||(*c==’\0’)) return ret;     n=0x100;             while (*c) {                v=n| (*c);                n+=0x100;                r=(int )((v>>2)^v)&0x0f;                ret=(ret<>(32-r));                ret&=0xFFFFFFFFL;                retu^=v*v;                c++;             } return ((ret>>16)^ret); } 3.  MySql中出现的字符串Hash函数(完全看不懂就不写了) 4.  很简单又好用的一个字符串的Hash函数 int  hash_function () {             int h=0;             int i;             for (i=0;b[i];i++) h=5*h+b[i];             return h; }

阅读(5798) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册