private void ensureCapacity(int numMappings){
  int newCapacity=Collections.roundUpToPowerOfTwo(capacityForInitSize(numMappings));
  HashMapEntry<K,V>[] oldTable=table;
  int oldCapacity=oldTable.length;
  if (newCapacity <= oldCapacity) {
    return;
  }
  if (newCapacity == oldCapacity * 2) {
    doubleCapacity();
    return;
  }
  HashMapEntry<K,V>[] newTable=makeTable(newCapacity);
  if (size != 0) {
    int newMask=newCapacity - 1;
    for (int i=0; i < oldCapacity; i++) {
      for (HashMapEntry<K,V> e=oldTable[i]; e != null; ) {
        HashMapEntry<K,V> oldNext=e.next;
        int newIndex=e.hash & newMask;
        HashMapEntry<K,V> newNext=newTable[newIndex];
        newTable[newIndex]=e;
        e.next=newNext;
        e=oldNext;
      }
    }
  }
}

private void ensureCapacity ( int numMappings ) { int newCapacity = Collections . roundUpToPowerOfTwo ( capacityForInitSize ( numMappings ) ) ; HashMapEntry < K , V > [ ] oldTable = table ; int oldCapacity = oldTable . length ; if ( newCapacity <= oldCapacity ) { return ; } if ( newCapacity == oldCapacity * 2 ) { doubleCapacity ( ) ; return ; } HashMapEntry < K , V > [ ] newTable = makeTable ( newCapacity ) ; if ( size != 0 ) { int newMask = newCapacity - 1 ; for ( int i = 0 ; i < oldCapacity ; i ++ ) { for ( HashMapEntry < K , V > e = oldTable [ i ] ; e != null ; ) { HashMapEntry < K , V > oldNext = e . next ; int newIndex = e . hash & newMask ; HashMapEntry < K , V > newNext = newTable [ newIndex ] ; newTable [ newIndex ] = e ; e . next = newNext ; e = oldNext ; } } } }
ensures that the hash table has sufficient capacity to store the specified number of mappings , with room to grow . if not , it increases the capacity as appropriate . like doublecapacity , this method moves existing entries to new buckets as appropriate . unlike doublecapacity , this method can grow the table by factors of 2 ^ n for n > 1 . hopefully , a single call to this method will be faster than multiple calls to doublecapacity . < p > this method is called only by putall .
