@@ -92,8 +92,7 @@ private function initializeBucket() {
9292 * @throws UnsupportedKeyTypeException
9393 */
9494 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 ());
9796 }
9897
9998 /**
@@ -120,7 +119,7 @@ public function add($key, $value): bool {
120119 }
121120 $ list ->add ($ key , $ value );
122121 $ this ->bucket [$ arrayIndex ] = $ list ;
123- $ this ->keySet [$ key ] = $ key ;
122+ $ this ->keySet [] = $ key ;
124123 return true ;
125124 }
126125
@@ -147,9 +146,8 @@ private function getBucketIndex($key) {
147146 *
148147 * Doing this avoids hash collisions.
149148 */
150- $ hash = $ this ->getHash ($ key );
151- $ arrayIndex = $ this ->getArrayIndex ($ hash );
152- return $ arrayIndex ;
149+ $ hash = $ this ->getHash ($ key );
150+ return $ this ->getArrayIndex ($ hash );
153151 }
154152
155153 /**
@@ -259,7 +257,7 @@ public function containsValue($value): bool {
259257 * @return bool
260258 */
261259 public function containsKey ($ key ): bool {
262- return true === isset ( $ this ->keySet [ $ key ] );
260+ return true === in_array ( $ key , $ this ->keySet );
263261 }
264262
265263 /**
@@ -332,7 +330,9 @@ public function remove($key): bool {
332330 */
333331 if ($ list ->size () == 1 && $ head ->getKey () === $ key ) {
334332 unset($ this ->bucket [$ arrayIndex ]);
335- unset($ this ->keySet [$ key ]);
333+ foreach (array_keys ($ this ->keySet , $ key ) as $ keyKey ) {
334+ unset($ this ->keySet [$ keyKey ]);
335+ }
336336 return true ;
337337 }
338338 return $ list ->remove ($ key );
@@ -381,7 +381,7 @@ public function toArray(): array {
381381 * @return array
382382 */
383383 public function keySet (): array {
384- return $ this ->keySet ;
384+ return array_values ( $ this ->keySet ) ;
385385 }
386386
387387 /**
0 commit comments