什么是好的哈希函数?函数

2023-09-10 22:33:41 作者:忘川秋叶

什么是好的哈希函数?我看到了很多散列函数,并应用在我的大学数据结构课程,但我大多了,它是pretty的努力使一个好的哈希函数。作为一个经验法则,以避免冲突我的教授说:

What is a good Hash function? I saw a lot of hash function and applications in my data structures courses in college, but I mostly got that it's pretty hard to make a good hash function. As a rule of thumb to avoid collisions my professor said that:

function Hash(key)
  return key mod PrimeNumber
end

(MOD是%运营商C和类似的语言)

(mod is the % operator in C and similar languages)

与素数是哈希表的大小。我得到的是一个比较不错的功能,以避免碰撞和一个快速的,但我怎样才能使一个更好的?有没有更好的散列函数对数字键字符串键?

with the prime number to be the size of the hash table. I get that is a somewhat good function to avoid collisions and a fast one, but how can I make a better one? Is there better hash functions for string keys against numeric keys?

推荐答案

有关上做基本上任何类型的数据正常的哈希表查询 - 这一个由保罗·谢是我用过的最好

For doing "normal" hash table lookups on basically any kind of data - this one by Paul Hsieh is the best I've ever used.

http://www.azillionmonkeys.com/qed/hash.html

如果你关心加密安全或其他任何东西更先进的,那么情况因人而异。如果你只是想踢屁股通用哈希函数哈希表查找,那么这就是你要找的内容。

If you care about cryptographically secure or anything else more advanced, then YMMV. If you just want a kick ass general purpose hash function for a hash table lookup, then this is what you're looking for.