[英]Internal implementation of data structures in java?
有没有可以在Java(HashMaps,TreeSets等)中找到各种数据结构的详细实现信息的来源。 eg:hash function 用于不同类型是什么? 是开放寻址还是其他? 类似的东西。
PS:我知道我可以通过源代码 go 。 但我会离开其他一天:)
由于 Java 是开源的,因此实现本身是最好看的。
如果您使用的是 Eclipse 并已配置源代码,只需 ctrl+左键单击所需的数据结构声明。 tt 将为此开源。
API 文档没有提供实现细节。
从Javadoc开始,然后在需要时继续查看源代码!
我不知道你是什么级别的细节?
我可以告诉你什么对我来说足够了。 我总是从 NetBeans 得到它。 在那里,我可以按住 CTRL,单击任何 class 名称,它会将我带到它的代码。 这样一来,您就可以将文档和代码放在您面前的一个地方,并且您可以看到它们是如何实现的,以及它们在文档中的描述。
希望能帮助到你。
编辑:
HashMap 中的第 247 行,在 HashSet 中创建然后在其中使用,描述了 hash function 也许这就是你想要的?
/**
* Applies a supplemental hash function to a given hashCode, which
* defends against poor quality hash functions. This is critical
* because HashMap uses power-of-two length hash tables, that
* otherwise encounter collisions for hashCodes that do not differ
* in lower bits. Note: Null keys always map to hash 0, thus index 0.
*/
static int hash(int h) {
// This function ensures that hashCodes that differ only by
// constant multiples at each bit position have a bounded
// number of collisions (approximately 8 at default load factor).
h ^= (h >>> 20) ^ (h >>> 12);
return h ^ (h >>> 7) ^ (h >>> 4);
}
You can use documentation on Collections: http://download.oracle.com/javase/tutorial/collections/index.html
没有。API 文档定义了集合类的外部行为,但没有定义实现细节,这可能是特定于供应商的。 如果您想知道这些类是如何在特定 VM 中实现的,您别无选择,只能查看源代码。
至少 AFAIK,没有 Java API 的实现,以及用于此类特定细节的附加文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.