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 c9b16dd commit f30e24fCopy full SHA for f30e24f
Exercise_27/Exercise_27_02/MyHashMap.class
115 Bytes
Exercise_27/Exercise_27_02/MyHashMap.java
@@ -217,9 +217,15 @@ private void removeEntries() {
217
218
/** Rehash the map */
219
private void rehash() {
220
+ java.util.Set<Entry<K, V>> set = entrySet();
221
capacity <<= 1; // Same as capacity *= 2. <= is more efficient
- for (int i = (size + 1); i < capacity; i++) {
222
+ size = 0;
223
+ table.clear();
224
+ for (int i = 0; i < capacity; i++)
225
table.add(null);
226
+
227
+ for (Entry<K, V> entry : set) {
228
+ put(entry.getKey(), entry.getValue());
229
}
230
231
0 commit comments