据说使折叠法:

int hashcode(int *v, int k) {
int i, p = 0;
for(i = 0; i < k; ++i) {
p = ((p << 2) + (v[i] >> 4))^(v[i] << 10);
}
p %= MOD;
if(p < 0) p += MOD;
return p;
}

 

ELFhash UNIX系统处理字符串使用的哈希

 

//UNIX系统使用的哈希

int ELFhash(char *key) {
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);
}



相关文章:

  • 2021-04-13
  • 2021-07-11
  • 2021-06-16
  • 2021-11-11
  • 2021-10-02
  • 2021-05-21
  • 2021-08-09
猜你喜欢
  • 2021-07-06
  • 2021-10-12
  • 2021-04-02
  • 2022-01-06
相关资源
相似解决方案