Internal implementation of data structures in java?
Is there a source where I can find detailed implementation information of various data structures in 开发者_运维知识库Java (HashMaps, TreeSets etc.). e.g: What is the hash function used for different types? Is it open addressing or something else? Similar stuff.
PS: I am aware that I can go through the source code. But that I will leave for some other day :)Since Java is open source, the implementation itself is the best thing to look at.
If you are using Eclipse and have configured source code, just do ctrl+left click on required data structure declaration. tt will open source for that.
The API Documentation DOES NOT give implementation details.
Start with the Javadoc and then carry on to the source if need be!
I do not know after what level of details you are?
I can tell you what is sufficient for me. I get it always from NetBeans. There I can, holding CTRL, click on any class name and it takes me to its code. This way you have documentation and code in one place in front of you and you can see how they have implemented, what they describe in the doc.
Hope it helps.
EDIT:
The line 247 in HashMap, which is created in HashSet then used in it, describes a hash function maybe this is what you want?.
/**
* 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
No. The API documentation defines the external behaviour of the collection classes, but not the implementation details, which probably are vendor specific. If you want to know how the classes are implemented in a specific VM, you have no other choice but to check the source code.
At least AFAIK, there is no implementation of the Java API with additional documentation available for such specific details.
精彩评论