Skip to content

Commit 65ac826

Browse files
Merge pull request wangzheng0822#405 from damianzhenxiaozhi/patch-3
removing all e in bucket, "use" should decrease
2 parents e1257d7 + d4eac2f commit 65ac826

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

java/18_hashtable/HashTable.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,14 @@ public void remove(K key) {
142142
}
143143

144144
Entry pre;
145+
Entry<K, V> headNode = table[index];
145146
do {
146147
pre = e;
147148
e = e.next;
148149
if (key == e.key) {
149150
pre.next = e.next;
150151
size--;
152+
if (headNode.next == null) use--;
151153
return;
152154
}
153155
} while (e.next != null);

0 commit comments

Comments
 (0)