mirror of
https://github.com/furyfire/trueskill.git
synced 2025-01-15 17:37:39 +00:00
Quicker hash
This commit is contained in:
@ -19,16 +19,16 @@ class HashMap
|
||||
*/
|
||||
private array $hashToKey = [];
|
||||
|
||||
public function getValue(string|object $key): mixed
|
||||
public function getValue(object $key): object
|
||||
{
|
||||
$hash = self::getHash($key);
|
||||
$hash = spl_object_id($key);
|
||||
|
||||
return $this->hashToValue[$hash];
|
||||
}
|
||||
|
||||
public function setValue(string|object $key, mixed $value): self
|
||||
public function setValue(object $key, mixed $value): self
|
||||
{
|
||||
$hash = self::getHash($key);
|
||||
$hash = spl_object_id($key);
|
||||
$this->hashToKey[$hash] = $key;
|
||||
$this->hashToValue[$hash] = $value;
|
||||
|
||||
@ -55,13 +55,4 @@ class HashMap
|
||||
{
|
||||
return count($this->hashToKey);
|
||||
}
|
||||
|
||||
private static function getHash(string|object $key): string
|
||||
{
|
||||
if (is_object($key)) {
|
||||
return spl_object_hash($key);
|
||||
}
|
||||
|
||||
return $key;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user