Are there any HashMap implementations that expose hook methods for profiling the performance of the Map (average chain length, best / worst / average access time, #rehashes, etc.).
It seems quite common to use HashMap and "hope for the best" with regards to ~O(1) access time, without analysing whether this is really the case but I'd like to measure the performance at runtime (at least during development), so anything that hooks into JMX or profiling software would also be good.
Also, Is anyone aware of HashMap implementations where the chains are based on binary trees instead of linked lists?
Thanks in advance.
A hashmap is always an array where the hashcode can be determined to get the index of the array element(In jdk this is the entry) . Therefore, it should take a contiguous memory as well.
A HashMap stores data into multiple singly linked lists of entries (also called buckets or bins). All the lists are registered in an array of Entry (Entry<K,V>[] array) and the default capacity of this inner array is 16.
Just like vectors, hash maps store their data on the heap. This HashMap has keys of type String and values of type i32 .
Since the String class is immutable, you cannot modify the value of a String once it is created. Therefore, it is recommended to use a String variable to hold keys in hash a map.
There's a new Java profiler that goes some way towards doing what you're after. CollectionSpy (www.collectionspy.com) tracks the number of internal rehashes of any hashing container, and also has a graph visualization of the bucket list lenghts. Doesn't (yet) provide any timing info though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With