Hacker News new | ask | show | jobs
by jp3141 2079 days ago
Javas implementation of HashMap uses a tree on hash collision.

[0] https://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/...

2 comments

If the bin is big enough to warrant it, according to your link.

Thanks for the link!

I imagine they do this as the user space can define hash algorithms and someone is gonna just return zero every now and then out of laziness :-)

You also need a comparable() key presumably - which you often have, but not always (a comparable() key is not strictly required by a hashtable).