mirror of
https://github.com/furyfire/trueskill.git
synced 2025-04-13 18:04:01 +00:00
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
59 lines
1.0 KiB
PHP
59 lines
1.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace DNW\Skills;
|
|
|
|
/**
|
|
* Basic hashmap that supports object keys.
|
|
*/
|
|
class HashMap
|
|
{
|
|
/**
|
|
* @var mixed[] $hashToValue
|
|
*/
|
|
private array $hashToValue = [];
|
|
|
|
/**
|
|
* @var mixed[] $hashToKey
|
|
*/
|
|
private array $hashToKey = [];
|
|
|
|
public function getValue(object $key): mixed
|
|
{
|
|
$hash = spl_object_id($key);
|
|
|
|
return $this->hashToValue[$hash];
|
|
}
|
|
|
|
public function setValue(object $key, mixed $value): self
|
|
{
|
|
$hash = spl_object_id($key);
|
|
$this->hashToKey[$hash] = $key;
|
|
$this->hashToValue[$hash] = $value;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return mixed[]
|
|
*/
|
|
public function getAllKeys(): array
|
|
{
|
|
return array_values($this->hashToKey);
|
|
}
|
|
|
|
/**
|
|
* @return mixed[]
|
|
*/
|
|
public function getAllValues(): array
|
|
{
|
|
return array_values($this->hashToValue);
|
|
}
|
|
|
|
public function count(): int
|
|
{
|
|
return count($this->hashToKey);
|
|
}
|
|
}
|