private void resize ( int newCapacity ) { // assert (newCapacity & -newCapacity) == newCapacity; // power of 2 int newLength = newCapacity * 2 ; long [ ] oldTable = table ; int oldLength = oldTable . length ; if ( oldLength == 2 * MAXIMUM_CAPACITY ) { // can't expand any further if ( threshold == MAXIMUM_CAPACITY - 1 ) throw new IllegalStateException ( "Capacity exhausted." ) ; threshold = MAXIMUM_CAPACITY - 1 ; // Gigantic map! return ; } if ( oldLength >= newLength ) return ; long [ ] newTable = new long [ newLength ] ; threshold = ( newCapacity * 3 ) / 4 ; for ( int j = 0 ; j < oldLength ; j += 2 ) { long key = oldTable [ j ] ; if ( key != 0 ) { long value = oldTable [ j + 1 ] ; int i = hash ( key , newLength ) ; while ( newTable [ i ] != 0 ) i = nextKeyIndex ( i , newLength ) ; newTable [ i ] = key ; newTable [ i + 1 ] = value ; } } table = newTable ; }
Resize the table to hold given capacity .