Closed evpav closed 6 years ago
You can create one very easily.
class BiMap
{
protected $map;
public function __construct()
{
$this->map = new \Ds\Map();
}
public function put($key, $value)
{
$this->map->put($key, $value);
$this->map->put($value, $key);
}
public function get($key)
{
return $this->map->get($key);
}
}
Or am I missing something here?
The ideal is to provide fundamental structures that allow for easy composition.
Or am I missing something here?
length, keys, values would be 2x; few corner cases and specifics; room for memory optimization (2 maps/tree).
The ideal is to provide fundamental structures that allow for easy composition.
I'm ok with that, just thought it would be convenient for users to have a good implementation(s) of the bimap here, because I haven't seen one for php yet.
Good points, especially around length being 2x. Could you compose using 2 maps instead and override length? What would length return anyway; max(k.length, v.length)
?
I'll take a closer look at BiMaps because I don't know much about them.
I am not convinced of the practical benefits at this stage, might reconsider later on.
https://en.wikipedia.org/wiki/Bidirectional_map