Lets try some moew modern annotations for index key/value typing

This commit is contained in:
MarkBaker 2020-11-07 17:41:58 +01:00
parent 3f3a3174b5
commit 34d15b80de
1 changed files with 5 additions and 5 deletions

View File

@ -7,14 +7,14 @@ class HashTable
/** /**
* HashTable elements. * HashTable elements.
* *
* @var IComparable[] * @var array<string, IComparable>
*/ */
protected $items = []; protected $items = [];
/** /**
* HashTable key map. * HashTable key map.
* *
* @var string[] * @var array<int, string>
*/ */
protected $keyMap = []; protected $keyMap = [];
@ -115,7 +115,7 @@ class HashTable
*/ */
public function getIndexForHashCode($hashCode) public function getIndexForHashCode($hashCode)
{ {
return array_search($hashCode, $this->keyMap); return array_search($hashCode, $this->keyMap, true);
} }
/** /**
@ -125,7 +125,7 @@ class HashTable
* *
* @return IComparable * @return IComparable
*/ */
public function getByIndex($index) public function getByIndex(int $index)
{ {
if (isset($this->keyMap[$index])) { if (isset($this->keyMap[$index])) {
return $this->getByHashCode($this->keyMap[$index]); return $this->getByHashCode($this->keyMap[$index]);
@ -141,7 +141,7 @@ class HashTable
* *
* @return IComparable * @return IComparable
*/ */
public function getByHashCode($hashCode) public function getByHashCode(string $hashCode)
{ {
if (isset($this->items[$hashCode])) { if (isset($this->items[$hashCode])) {
return $this->items[$hashCode]; return $this->items[$hashCode];