src/Datastructure/Maps/HashMap.php
public function add($key, $value): bool {
        $arrayIndex = $this->getBucketIndex($key);
        if (isset($this->bucket[$arrayIndex])) {
            $list = $this->bucket[$arrayIndex];
        } else {
            $list = new SinglyLinkedList();
        }
        if ($list->containsKey($key)) {
            $list->replaceValue($key, $value);
            return true;
        }
        $list->add($key, $value);
        $this->bucket[$arrayIndex] = $list;
        return true;
    }
public function add($key, $value): bool {
        $arrayIndex = $this->getBucketIndex($key);
        if (isset($this->bucket[$arrayIndex])) {
            $list = $this->bucket[$arrayIndex];
        } else {
            $list = new SinglyLinkedList();
        }
        if ($list->containsKey($key)) {
            $list->replaceValue($key, $value);
            return true;
        }
        $list->add($key, $value);
        $this->bucket[$arrayIndex] = $list;
        return true;
    }
public function add ( $ key , $ value ) : bool { $ arrayIndex = $ this -> getBucketIndex ( $ key ) ; if ( isset ( $ this -> bucket [ $ arrayIndex ] ) ) { $ list = $ this -> bucket [ $ arrayIndex ] ; } else { $ list = new SinglyLinkedList ( ) ; } if ( $ list -> containsKey ( $ key ) ) { $ list -> replaceValue ( $ key , $ value ) ; return true ; } $ list -> add ( $ key , $ value ) ; $ this -> bucket [ $ arrayIndex ] = $ list ; return true ; }
adds a new value assigned to a key. The key has to be a scalar
value otherwise the method throws an InvalidKeyTypeException.

@param $key
@param $value
@return bool
@throws \doganoo\PHPAlgorithms\Common\Exception\InvalidKeyTypeException
@throws \doganoo\PHPAlgorithms\Common\Exception\UnsupportedKeyTypeException
adds a new value assigned to a key . The key has to be a scalar value otherwise the method throws an InvalidKeyTypeException .