We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 48c58c7 commit 8ac4506Copy full SHA for 8ac4506
Exercise_27/Exercise_27_04/MyHashMap.class
115 Bytes
Exercise_27/Exercise_27_04/MyHashMap.java
@@ -223,9 +223,15 @@ private void removeEntries() {
223
224
/** Rehash the map */
225
private void rehash() {
226
+ java.util.Set<Entry<K, V>> set = entrySet();
227
capacity <<= 1; // Same as *= 2. <= is more efficient
- for (int i = size + 1; i < capacity; i++) {
228
+ size = 0; // Reset size
229
+ table.clear();
230
+ for (int i = 0; i < capacity; i++)
231
table.add(null);
232
+
233
+ for (Entry<K, V> entry : set) {
234
+ put(entry.getKey(), entry.getValue());
235
}
236
237
0 commit comments