Moved UnitTests to tests/ and Skills to src/

This commit is contained in:
Alexander Liljengård
2016-05-24 13:53:56 +02:00
parent 11b5033c8a
commit 4ab0c5d719
64 changed files with 0 additions and 0 deletions

55
src/HashMap.php Normal file
View File

@ -0,0 +1,55 @@
<?php
namespace Moserware\Skills;
/**
* Basic hashmap that supports object keys.
*/
class HashMap
{
private $_hashToValue = array();
private $_hashToKey = array();
public function &getValue(&$key)
{
$hash = self::getHash($key);
$hashValue = &$this->_hashToValue[$hash];
return $hashValue;
}
public function setValue(&$key, &$value)
{
$hash = self::getHash($key);
$this->_hashToKey[$hash] = &$key;
$this->_hashToValue[$hash] = &$value;
return $this;
}
public function &getAllKeys()
{
$keys = &\array_values($this->_hashToKey);
return $keys;
}
public function getAllValues()
{
$values = &\array_values($this->_hashToValue);
return $values;
}
public function count()
{
return \count($this->_hashToKey);
}
private static function getHash(&$key)
{
if(\is_object($key))
{
return \spl_object_hash($key);
}
return $key;
}
}
?>