Skip to content

Commit

Permalink
Merge pull request #1 from fatrbaby/main
Browse files Browse the repository at this point in the history
Simplify containsKey & simplify code with containsKey
  • Loading branch information
isszz authored Aug 3, 2023
2 parents 0185057 + bb62980 commit e5c1aa7
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/HashMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class HashMap
*/
public function put($key, $value)
{
if (! array_key_exists($key, $this->hashTable)) {
if (! $this->containsKey($key)) {
$this->hashTable[$key] = $value;
return null;
}
Expand All @@ -40,7 +40,7 @@ public function put($key, $value)
*/
public function get($key)
{
if (array_key_exists($key, $this->hashTable)) {
if ($this->containsKey($key)) {
return $this->hashTable[$key];
}

Expand All @@ -55,7 +55,7 @@ public function get($key)
*/
public function remove($key)
{
if (array_key_exists($key, $this->hashTable)) {
if ($this->containsKey($key)) {
$tempTable = [];
$tempValue = $this->hashTable[$key];
foreach ($this->hashTable as $k => $v) {
Expand Down Expand Up @@ -145,11 +145,7 @@ public function containsValue($value)
*/
public function containsKey($key)
{
if (array_key_exists($key, $this->hashTable)) {
return true;
} else {
return false;
}
return array_key_exists($key, $this->hashTable);
}

/**
Expand Down

0 comments on commit e5c1aa7

Please sign in to comment.