参考文章 :http://www.iteye.com/topic/754887
/** * 扩展散列表的容量 * @param newCapacity */ void resize(int newCapacity) { Entry[] oldTable = table; int oldCapacity = oldTable.length; Entry[] newTable = new Entry[newCapacity]; transfer(newTable); table = newTable; threshold = (int) (newCapacity * loadFactor); } /** * 重新进行散列 * @param newTable */ void transfer(Entry[] newTable) { Entry[] src = table; int newCapacity = newTable.length; for (int j = 0; j < src.length; j++) { Entry<K, V> e = src[j]; if (e != null) { src[j] = null; do { Entry<K, V> next = e.next; int i = indexFor(e.hash, newCapacity); e.next = newTable[i]; newTable[i] = e; e = next; } while (e != null); } } }
时间: 2024-11-29 08:34:25