什么是好的哈希函数? [英] What is a good Hash Function?

查看:283
本文介绍了什么是好的哈希函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是好的哈希函数?我看到了很多散列函数,并应用在我的大学数据结构课程,但我大多了,它是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.

<一个href="http://www.azillionmonkeys.com/qed/hash.html">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.

这篇关于什么是好的哈希函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆