我看到以下哈希函数。但我不知道为什么要这样定义它们。有谁知道我在哪里可以找到这些哈希函数的解释?谢谢。
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;
}
最佳答案
这个哈希函数似乎最初是由 Thomas Wang 发布的。原来的网站已经不存在了,但是你可以在Wayback Machine上找到它。 。还有一个reformatted version of the same text在 gist.github.com 上,我看到它的链接来自 another hashtable library 。评论还链接了这个avalanche analysis on Wang's function您可能会觉得有趣。
关于c - 关于hashmap(khash)中使用的哈希函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54936008/