【发布时间】:2019-02-28 23:45:49
【问题描述】:
我看到以下哈希函数。但我不知道为什么它们是这样定义的。有人知道我在哪里可以找到这些哈希函数的解释吗?谢谢。
https://github.com/attractivechaos/klib/blob/master/khash.h#L368
#define kh_int64_hash_func(key) (khint32_t)((key)>>33^(key)^(key)<<11)
static kh_inline khint_t __ac_X31_hash_string(const char *s)
{
khint_t h = (khint_t)*s;
if (h) for (++s ; *s; ++s) h = (h << 5) - h + (khint_t)*s;
return h;
}
static kh_inline khint_t __ac_Wang_hash(khint_t key)
{
key += ~(key << 15);
key ^= (key >> 10);
key += (key << 3);
key ^= (key >> 6);
key += ~(key << 11);
key ^= (key >> 16);
return key;
}
【问题讨论】: