扩容
()
| 108 | * 扩容 |
| 109 | */ |
| 110 | private void resize() { |
| 111 | Entry<K, V>[] oldTable = table; |
| 112 | table = (Entry<K, V>[]) new Entry[table.length * 2]; |
| 113 | use = 0; |
| 114 | for (int i = 0; i < oldTable.length; i++) { |
| 115 | if (oldTable[i] == null || oldTable[i].next == null) { |
| 116 | continue; |
| 117 | } |
| 118 | Entry<K, V> e = oldTable[i]; |
| 119 | while (e.next != null) { |
| 120 | e = e.next; |
| 121 | int index = hash(e.key); |
| 122 | if (table[index] == null) { |
| 123 | use++; |
| 124 | // 创建哨兵节点 |
| 125 | table[index] = new Entry<>(null, null, null); |
| 126 | } |
| 127 | table[index].next = new Entry<>(e.key, e.value, table[index].next); |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * 删除 |