Source of 22.16.java


  1: // Precondition: checkInitialization has been called.
  2: private void enlargeHashTable()
  3: {
  4:    TableEntry<K, V>[] oldTable = hashTable;
  5:    int oldSize = hashTable.length;
  6:    int newSize = getNextPrime(oldSize + oldSize);
  7:    checkSize(newSize);
  8: 
  9:    // The cast is safe because the new array contains null entries
 10:    @SuppressWarnings("unchecked")
 11:    TableEntry<K, V>[] temp = (TableEntry<K, V>[])new TableEntry[newSize]; // Increase size of array
 12:    hashTable = temp;
 13:    numberOfEntries = 0; // Reset number of dictionary entries, since
 14:                         // it will be incremented by add during rehash
 15: 
 16:    // Rehash dictionary entries from old array to the new and bigger array;
 17:    // skip both null locations and removed entries
 18:    for (int index = 0; index < oldSize; index++)
 19:    {
 20:       if ( (oldTable[index] != null) && oldTable[index].isIn() )
 21:          add(oldTable[index].getKey(), oldTable[index].getValue());
 22:    } // end for
 23: } // end enlargeHashTable
 24: // Version 4.0