Menu

#144 trove hashmap fail when size approaching half int max value

Future
moved
nobody
None
1
2013-02-24
2012-11-08
No

Hi all,
When a hashmap fulled, the hash map try to double its capacity and find next prime number. However, this behavior is problematic when the size is approaching the half of int max value. It results int overflow, while actually data can be filled in the int max value and Int.MaxValue is actually a prime number needed by the algorithm.

The offending code is in

gnu.trove.impl.hash.THash line 387 in

protected final void [More ...] postInsertHook( boolean usedFreeSlot ) {

int newCapacity = _size > _maxSize ? PrimeFinder.nextPrime( capacity() << 1 ) : capacity();

here the new capacity is not checked against Int overflow. and do not even ensure newCapacity is larger than original.

Thanks,
Jiacheng Guo

Discussion

  • Rob Eden

    Rob Eden - 2013-02-24
     
  • Rob Eden

    Rob Eden - 2013-02-24
    • status: open --> moved