关于计算正确的哈希大小的困惑
我对选择正确的哈希大小有点困惑。举例来说,如果我想对 2^32 个值进行哈希处理,可以使用 32 位的哈希大小吗?会不会造成更多的碰撞?我在某处读到过有关平方根规则的内容。这是否意味着理想情况下我应该选择 64 位哈希大小?但这是否意味着存储哈希表所需的空间将用于存储 2^64 个值。 这是让我困惑的部分。根据定义,散列是减少密钥空间,但如果我在臃肿的 2^64 值空间中存储 2^32 个值……这听起来不太正确。我正在增加密钥空间。我想我误解了一些东西......任何帮助澄清这一点将不胜感激。
谢谢!
I am a bit confused on choosing the right hash size. Say for example if I want to hash 2^32 values, is it okay to use hash size of 32 bits? Would it cause more collisions? I read somewhere about the rule of square roots..Does it mean ideally I should choose a 64bit hash size? But then doesn't it imply that the space required for storing hashtable will be for ~ storing 2^64 values.
This is the part that confuses me. Hashing by definition is reducing the key space, but if I am storing 2^32 values in the bloated 2^64 values space...that doesn't sound right. I am increasing the keyspace. I guess I am misunderstanding something...any help to clarify this would be much appreciated.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
维基百科说得最好:
听起来这不像是您想要做的。听起来您正在尝试将 32 位键映射到 32 位值。哈希函数有许多可能的用途。您所描述的似乎不是哈希函数的理想用例。
Wikipedia says it best:
It does not sound like this is what you are trying to do. It sounds like you are trying to map a 32-bit keys to 32-bit values. There are many possible uses for a hash function. What you are describing doesn't seem like an ideal use case for a hash function.