Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
UNIX下的字符串哈希函数UNIX下的字符串哈希函数 int ELFhash(char *key) /// 此乃UNIX系统使用的哈希,绝对有价值 { unsigned long h = 0; while (*key){ h = (h << 4) + *key++; unsigned long g = h & 0xf0000000L; // 1个f,7个0 if (g) h ^= g >> 24; h &= ~g; } return (h+M) % M; // M is Prime } int hashcode(const L&a) /// 把数字的转换为字符串,进行哈希,以后就不用费心思设计哈希了 { char str[32*8]; char *s = (char*)(&a.d[1]); int i; for (i = 0; i < k-1; i++){ str[i] = 'a' + s[i]; } str[i] = 0; return ELFhash(str); } 这样就ok了,我的代码跑了400+ms,不算快的。O(∩_∩)O~ Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator