Skip to content

Commit f30e24f

Browse files
author
jsquared21
committed
Fix method MyHashMap.rehash()
1 parent c9b16dd commit f30e24f

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed
115 Bytes
Binary file not shown.

Exercise_27/Exercise_27_02/MyHashMap.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,15 @@ private void removeEntries() {
217217

218218
/** Rehash the map */
219219
private void rehash() {
220+
java.util.Set<Entry<K, V>> set = entrySet();
220221
capacity <<= 1; // Same as capacity *= 2. <= is more efficient
221-
for (int i = (size + 1); i < capacity; i++) {
222+
size = 0;
223+
table.clear();
224+
for (int i = 0; i < capacity; i++)
222225
table.add(null);
226+
227+
for (Entry<K, V> entry : set) {
228+
put(entry.getKey(), entry.getValue());
223229
}
224230
}
225231

0 commit comments

Comments
 (0)