Why I Stopped High Performance Living

By most societal definitions, I am a high performer. I was top of my class in kindergarten, I received a full scholarship for my undergraduate from the Singapore government, I was promoted very…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Improved HashMap performance in Java 8

If you are reading this one which means you are already aware of Java’s the most fast, versatile and most used data structure HashMap. It completely works on a system where the index of the (key, value) stored(or to be stored) will be computed based on two methods hashCode() and equals().

By far everyone knows that it operates at an asymptotic complexity of O(1) with the best hashCode implementation. But there could be collisions occurred by generating the same bucket position for different hashes and could end up forming a LinkedList inside the bucket. In worst case if all the hashes are mapped to the same bucket then all the (key, value) would form a linked list and would result the search operations performed to be O(n).

Here is the answer, HashMap buckets are now binary trees instead of earlier LinkedLists. If the same bucket is mapped to different hashes then the one considered bigger goes to the right and the smaller goes to the left forming a binary tree.

Also HashMap assumes that keys are comparable and so that it can decide an order and insert the elements as along. But if the keys are not Comparable then do not expect a performance improvement rather would be the same way as earlier if there is a heavy hash collision.

Thanks for reading the article !! Hope this helps !!

Add a comment

Related posts:

The Value of Keeping Your Clients Goal Oriented

As a User Experience Designer and the first creative on my team to interact with clients, it is my responsibility to get the project started off on the right foot. This requires documentation…

TELL HIM

Tell him maybe when tomorrow comes and darkness engulfs his being and haunts him of yesterday’s past, with regrets that shreds his future, I’d be the girl he seeks but never finds.

This is the One Game That Will Help You in Life

There are plenty of games out there, many just leisure activities that will not translate to real-world success. But, there are a few games out there that are legitimate aids to the path of life. My…