@@ -92,8 +92,7 @@ private function initializeBucket() {
92
92
* @throws UnsupportedKeyTypeException
93
93
*/
94
94
public function addNode (Node $ node ): bool {
95
- $ added = $ this ->add ($ node ->getKey (), $ node ->getValue ());
96
- return $ added ;
95
+ return $ this ->add ($ node ->getKey (), $ node ->getValue ());
97
96
}
98
97
99
98
/**
@@ -120,7 +119,7 @@ public function add($key, $value): bool {
120
119
}
121
120
$ list ->add ($ key , $ value );
122
121
$ this ->bucket [$ arrayIndex ] = $ list ;
123
- $ this ->keySet [$ key ] = $ key ;
122
+ $ this ->keySet [] = $ key ;
124
123
return true ;
125
124
}
126
125
@@ -147,9 +146,8 @@ private function getBucketIndex($key) {
147
146
*
148
147
* Doing this avoids hash collisions.
149
148
*/
150
- $ hash = $ this ->getHash ($ key );
151
- $ arrayIndex = $ this ->getArrayIndex ($ hash );
152
- return $ arrayIndex ;
149
+ $ hash = $ this ->getHash ($ key );
150
+ return $ this ->getArrayIndex ($ hash );
153
151
}
154
152
155
153
/**
@@ -259,7 +257,7 @@ public function containsValue($value): bool {
259
257
* @return bool
260
258
*/
261
259
public function containsKey ($ key ): bool {
262
- return true === isset ( $ this ->keySet [ $ key ] );
260
+ return true === in_array ( $ key , $ this ->keySet );
263
261
}
264
262
265
263
/**
@@ -332,7 +330,9 @@ public function remove($key): bool {
332
330
*/
333
331
if ($ list ->size () == 1 && $ head ->getKey () === $ key ) {
334
332
unset($ this ->bucket [$ arrayIndex ]);
335
- unset($ this ->keySet [$ key ]);
333
+ foreach (array_keys ($ this ->keySet , $ key ) as $ keyKey ) {
334
+ unset($ this ->keySet [$ keyKey ]);
335
+ }
336
336
return true ;
337
337
}
338
338
return $ list ->remove ($ key );
@@ -381,7 +381,7 @@ public function toArray(): array {
381
381
* @return array
382
382
*/
383
383
public function keySet (): array {
384
- return $ this ->keySet ;
384
+ return array_values ( $ this ->keySet ) ;
385
385
}
386
386
387
387
/**
0 commit comments