private void rehash ( ) { // Increase the table size, to keep the load factory < 0.5. int newSize = hashTableSize ; if ( hashTableSize < ( count * 2 ) ) { newSize = hashTableSize * 2 ; if ( newSize > maxSize ) { throw new IllegalStateException ( "'newSize' of " + newSize + " would put the table over the maximum size limit of " + maxSize ) ; } } // Keep hold of the old table, until a new one is succesfully buily. Entry < K > [ ] oldTable = hashTable ; hashTableSize = newSize ; length = hashTable . length ; // Keep rehashing the table until it is succesfully rebuilt. boolean rehashedOk ; do { // Start by assuming that this will work. rehashedOk = true ; // Alter the hash functions. changeHashFunctions ( ) ; // Create a new table from the old one, to rehash everything into. hashTable = ( Entry < K > [ ] ) new Entry [ hashTableSize ] ; for ( Entry < K > entry : oldTable ) { if ( entry != null ) { // Add the entry to the new table, dropping out if this fails. if ( applyWithEntry ( entry . key , entry , false ) == null ) { rehashedOk = false ; break ; } } } } while ( ! rehashedOk ) ; }
Creates a new hashtable that is twice the size of the old one then re - hashes everything from the old table into the new table .