File tree Expand file tree Collapse file tree 2 files changed +8
-6
lines changed
Exercise_27/Exercise_27_03 Expand file tree Collapse file tree 2 files changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -166,16 +166,18 @@ public void remove(K key) {
166
166
int index = hash1 ;
167
167
int j = 0 ;
168
168
169
- while (table .get (index ) == null ) {
169
+ // Remove the first entry that matched the key
170
+ while (table .get (index ) != null ) {
171
+ if (table .get (index ).getKey ().equals (key )) {
172
+ table .remove (index );
173
+ size --; // Decrease size
174
+ break ; // Remove just one entry that matches the key
175
+ }
176
+
170
177
// Secondary hash: (k + j * h'(key)) % N
171
178
index = hash1 + j ++ * hash2 (hash1 );
172
179
index %= capacity ;
173
180
}
174
-
175
- if (table .get (index ).getKey () == key ) {
176
- table .remove (index );
177
- size --; // Decrease size
178
- }
179
181
}
180
182
181
183
@ Override /** Return the number of entries in this map */
You can’t perform that action at this time.
0 commit comments