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 f30e24f commit 48c58c7Copy full SHA for 48c58c7
Exercise_27/Exercise_27_03/MyHashMap.class
115 Bytes
Exercise_27/Exercise_27_03/MyHashMap.java
@@ -230,9 +230,15 @@ private void removeEntries() {
230
231
/** Rehash the map */
232
private void rehash() {
233
+ java.util.Set<Entry<K, V>> set = entrySet();
234
capacity <<= 1; // Same as capacity *= 2. <= is more efficient
- for (int i = size + 1; i < capacity; i++) {
235
+ size = 0; // Reset size
236
+ table.clear();
237
+ for (int i = 0; i < capacity; i++)
238
table.add(null);
239
+
240
+ for (Entry<K, V> entry : set) {
241
+ put(entry.getKey(), entry.getValue());
242
}
243
244
0 commit comments