java-ds-algorithms icon indicating copy to clipboard operation
java-ds-algorithms copied to clipboard

HashMap capacity doesn't refresh keys after capacity change

Open droptablestar opened this issue 8 years ago • 0 comments
trafficstars

This bug can be duplicated by adding the following code to testPutAndGet in HashTableTest.java:

for (int i = 0; i < 2048; i++) { classUnderTest.put(i+4096, i); }                                                                                                                                             
for (int i = 0; i < 2048; i++) { assertEquals(classUnderTest.get(i+4096), i); }

The issue here is that the hashed key is dependant on the capacity of the table and the values for the keys aren't update after a capacity change. If the capacity changes those keys could hash to different values. Specifically this happens when keys are added which hash to a number larger than the current capacity.

droptablestar avatar Jun 26 '17 20:06 droptablestar