有没有资源可以找到Java中各种数据结构(HashMaps、TreeSets等)的详细实现信息。例如:不同类型使用的哈希函数是什么?它是开放寻址还是别的什么?类似的东西。
附言:我知道我可以通过源代码。但我会改天离开:)
发布于 2011-05-27 00:39:56
因为Java是开源的,所以实现本身是最值得一看的。
如果您使用的是Eclipse并配置了源代码,那么只需在ctrl+left上单击所需的数据结构声明即可。tt将为此开源。
API文档没有提供实现细节。
发布于 2011-05-27 00:33:18
从Javadoc开始,如果需要的话,继续到源代码!
发布于 2011-05-27 00:48:15
我不知道你是经过什么层次的详细介绍?
我可以告诉你什么对我来说是足够的。我总是从NetBeans那里得到它。在那里,我可以按住CTRL键,单击任何类名,它会将我带到它的代码。这样,您就可以将文档和代码放在您面前的一个地方,您可以看到它们是如何实现的,以及它们在文档中所描述的内容。
希望能有所帮助。
编辑:
HashMap中的第247行是在HashSet中创建的,然后在其中使用,它描述了一个散列函数,也许这就是您想要的?
/**
* 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);
}https://stackoverflow.com/questions/6141932
复制相似问题