/** * Rehashes the contents of this map into a new <tt>ConcurrentHashMap</tt> * instance with a larger capacity. This method is called automatically when * the number of keys in this map exceeds its capacity and load factor. * * @param newCapacity the new capacity, MUST be a power of two. */ private void resize(int newCapacity) { // assert(newCapacity & -newCapacity) == newCapacity; // power of 2 Entry[] oldTable = table; int oldCapacity = oldTable.length; // check if needed if (size < threshold || oldCapacity > newCapacity) return; Entry[] newTable = new Entry[newCapacity]; int mask = newCapacity - 1; for (int i = oldCapacity; i-- > 0;) { for (Entry e = oldTable[i]; e != null; e = e.next) { Entry clone = (Entry) e.clone(); int j = clone.hash & mask; clone.next = newTable[j]; newTable[j] = clone; } } table = newTable; threshold = (int) (newCapacity * loadFactor); }
/** * Rehashes the contents of this map into a new <tt>ConcurrentHashMap</tt> * instance with a larger capacity. This method is called automatically when * the number of keys in this map exceeds its capacity and load factor. * * @param newCapacity the new capacity, MUST be a power of two. */ private void resize(int newCapacity) { // assert(newCapacity & -newCapacity) == newCapacity; // power of 2 Entry[] oldTable = table; int oldCapacity = oldTable.length; // check if needed if (size < threshold || oldCapacity > newCapacity) return; Entry[] newTable = new Entry[newCapacity]; int mask = newCapacity - 1; for (int i = oldCapacity; i-- > 0;) { for (Entry e = oldTable[i]; e != null; e = e.next) { Entry clone = (Entry) e.clone(); int j = clone.hash & mask; clone.next = newTable[j]; newTable[j] = clone; } } table = newTable; threshold = (int) (newCapacity * loadFactor); }
/** * Rehashes the contents of this map into a new <tt>ConcurrentHashMap</tt> * instance with a larger capacity. This method is called automatically when * the number of keys in this map exceeds its capacity and load factor. * * @param newCapacity the new capacity, MUST be a power of two. */ private void resize(int newCapacity) { // assert(newCapacity & -newCapacity) == newCapacity; // power of 2 Entry[] oldTable = table; int oldCapacity = oldTable.length; // check if needed if (size < threshold || oldCapacity > newCapacity) return; Entry[] newTable = new Entry[newCapacity]; int mask = newCapacity - 1; for (int i = oldCapacity; i-- > 0;) { for (Entry e = oldTable[i]; e != null; e = e.next) { Entry clone = (Entry) e.clone(); int j = clone.hash & mask; clone.next = newTable[j]; newTable[j] = clone; } } table = newTable; threshold = (int) (newCapacity * loadFactor); }