java 创建您自己的哈希图和哈希表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15460868/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
creating your own hashmap and hashtable
提问by Tuntun Gdfhjf
In a recent interview I was being asked how to write your own HashMap
/Hashtable
implementation in Java.
在最近的一次采访中,我被问到如何用 Java编写自己的HashMap
/Hashtable
实现。
I have no idea of this so the only thing I said as a answer was that we can implement HashMap
by using Array, because only this provides constant time access, if you know the index. Key is to writing hash function to minimize collision.
我不知道这一点,所以我作为答案说的唯一一件事是我们可以HashMap
通过使用 Array来实现,因为只有它提供恒定时间访问,如果您知道索引。关键是编写散列函数以减少冲突。
Can you please advise me how we can write our own Hashmap
/Hashtable
?
你能告诉我如何写我们自己的Hashmap
/Hashtable
吗?
回答by bsiamionau
Look sources to get more about how do they work.
查看资源以获取有关它们如何工作的更多信息。
Also, there are some good explanations at SO:
此外,SO 有一些很好的解释: