0

Is there any way to get a list of all the collisions which occurred after inserting a number of elements into a HashMap/HashTable/HashSet?

For example:

<1, 3> collided with <4, 2>, <4, 5> collided with <57, 6> ...

Michael
  • 791
  • 2
  • 12
  • 32
  • 2
    You cannot do it without looking at the implementation and knowing the number of hash buckets used by the set/map in the current state. A little reflection can help you figure it out, though. – Sergey Kalinichenko Jun 03 '15 at 21:48
  • Could you provide some pointers on how reflection could help? Thanks! – Michael Jun 03 '15 at 21:56
  • 1
    If you look at implementation of HashMap for instance, you can see how value is inserted in method putVal. Test on table index being null is done, and if it is null, new AVL is created there, otherwise is node added to existing AVL. Via reflection, you can load the class, and override protection on inner table and access it. Then iterating over it and meassuring size of each AVL will give you number of collisions. If you are not familiar with reflection, see this [tutorial](http://www.programcreek.com/2013/09/java-reflection-tutorial/). – Vojtěch Kaiser Jun 03 '15 at 23:58

0 Answers0