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