【问题标题】:About hash function used in hashmap (khash)?关于 hashmap (khash) 中使用的散列函数?
【发布时间】: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;
}

【问题讨论】:

    标签: c hashmap hashtable


    【解决方案1】:

    这个哈希函数似乎最初是由 Thomas Wang 发表的。原网站不再可用,但您可以在Wayback Machine 上找到它。 gist.github.com 上还有一个reformatted version of the same text,我已经看到它与another hashtable library 链接。 cmets 还会链接此avalanche analysis on Wang's function,您可能会觉得有趣。

    【讨论】:

      猜你喜欢
      • 2016-11-12
      • 2013-01-04
      • 1970-01-01
      • 2019-01-10
      • 2020-10-19
      • 2018-08-31
      • 1970-01-01
      • 1970-01-01
      • 2018-12-10
      相关资源
      最近更新 更多