private void rehash ( int newCapacity ) { long [ ] oldKeys = keys ; V [ ] oldVals = values ; keys = new long [ newCapacity ] ; @ SuppressWarnings ( { "unchecked" , "SuspiciousArrayCast" } ) V [ ] temp = ( V [ ] ) new Object [ newCapacity ] ; values = temp ; maxSize = calcMaxSize ( newCapacity ) ; mask = newCapacity - 1 ; // Insert to the new arrays. for ( int i = 0 ; i < oldVals . length ; ++ i ) { V oldVal = oldVals [ i ] ; if ( oldVal != null ) { // Inlined put(), but much simpler: we don't need to worry about // duplicated keys, growing/rehashing, or failing to insert. long oldKey = oldKeys [ i ] ; int index = hashIndex ( oldKey ) ; for ( ; ; ) { if ( values [ index ] == null ) { keys [ index ] = oldKey ; values [ index ] = oldVal ; break ; } // Conflict, keep probing. Can wrap around, but never reaches startIndex again. index = probeNext ( index ) ; } } } }
Rehashes the map for the given capacity .