繁体   English   中英

hash map 中的单独链接

[英]Separate chaining in hash map

我对分离链的理解是,我们将一个大数转换成一个小数,这样我们就可以将它用作索引。 但是我们如何处理大索引呢? 比如我的hash_map当前的大小是10,一个新的索引由hash function计算出来是55。那么每次新索引太大时我需要重新调整我的hash_map的大小吗?

谢谢!

A common technique is to have a hash function that computes some integer (typically 32-bit or 64-bit) and then to reduce the number to a valid index in the hash table by modding that integer by the table size. 例如,如果您有一个包含 10 个元素的 hash 表,并且您的 hash 代码为 55,则您将计算 55 mod 10 = 5 并将项目放在索引 5 处。

根据您的编程语言,这里可能需要处理一些边缘情况(例如,如果 hash 代码可能是负数,您需要确保您的索引是正数),但是这个一般想法非常有效,并且在许多常见的hash 表实现。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM