Hashtable 实现中使用的算法?
java是否使用开放寻址或链接来实现Hashtable?
某些规范/认证是否需要其中一种方法?
Does java use open addressing or chaining to implementing Hashtable?
Is one method or the other required by some specification/certification?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您查看Hashtable 的 Javadoc,您会注意到它没有指定它使用哪种哈希方案。这意味着任何兼容的 Java 实现都可以以它认为合适的方式实现该对象,只要它遵守接口中指定的复杂性保证。只要满足接口中指定的保证,兼容的实现就可以使用链式、二次散列、Robin hood 散列、动态完美散列、Cuckoo 散列等。
不过,从客户的角度来看,您不必担心这一点。
If you look at the Javadoc for
Hashtable
, you'll notice that it doesn't specify which hash scheme it uses. This means that any compliant Java implementation could implement this object however it sees fit, as long as it obeys the complexity guarantees specified in the interface. A compliant implementation could use chaining, quadratic hashing, Robin hood hashing, dynamic perfect hashing, Cuckoo hashing, etc. as long as the guarantees specified in the interface were met.From a client perspective, you shouldn't need to worry about this, though.
java.util.HashMap 和 java.util.Hashtable 都使用某种链接,至少在 Sun/Oracle JRE 和 OpenJDK 中使用的实现中是这样。
Both
java.util.HashMap
andjava.util.Hashtable
use some sort of chaining, at least in the implementation used in the Sun/Oracle JRE and the OpenJDK one.该规范位于 Javadoc 中。
The specification is in the Javadoc.