create an empty invertible map.
optionally provide an initial forward_map
to populate the forward mapping, and then automatically deriving the reverse mapping from it.
or provide an initial reverse_map
to populate the reverse mapping, and then automatically deriving the froward mapping from it.
if both forward_map
and reverse_map
are provided, then it will be up to YOU to make sure that they are actual inverses of each other.
Optional
forward_map: Map<K, Set<V>>initiallize by populating with an optional initial forward map (the reverse map will be automatically computed if reverse_map === undefined
)
Optional
reverse_map: Map<V, Set<K>>initiallize by populating with an optional initial reverse map (the forward map will be automatically computed if forward_map === undefined
)
forward mapping. not intended for direct access, since manually mutating it will ruin the invertibility with the reverse map if you're not careful.
reverse mapping. not intended for direct access, since manually mutating it will ruin the invertibility with the forward map if you're not careful.
size of the forward map
size of the reverse map
at a specific key
in the forward map, add the list of items
,
and then also assign key
to the list of items in the reverse map to maintain invertibility.
at a specific key
in the reverse map, add the list of items
,
and then also assign key
to the list of items in the forward map to maintain invertibility.
clear out both forward and reverse maps completely of all their entries
delete a key
in the forward map, and also remove its mentions from the reverse map's entries.
if keep_key
is optionally set to true
, we will only clear out the set of items held by the forward map at the key,
and keep the key itself intact (along with the original (now mutated and clear) Set<V>
which the key refers to)
delete a key
in the reverse map, and also remove its mentions from the forward map's entries.
if keep_key
is optionally set to true
, we will only clear out the set of items held by the reverse map at the key,
and keep the key itself intact (along with the original (now mutated and clear) Set<V>
which the key refers to)
at a specific key
in the forward map, remove/delete the list of items
,
and then also remove key
from the list of items in the reverse map to maintain invertibility.
at a specific key
in the reverse map, remove/delete the list of items
,
and then also remove key
from the list of items in the forward map to maintain invertibility.
Executes a provided function once per each key/value pair in the Map, in insertion order.
Returns a specified element from the Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map.
boolean indicating whether an element with the specified key exists or not.
Adds a new element with a specified key and value to the Map. If an element with the same key already exists, the element will be updated.
Returns an iterable of key, value pairs for every entry in the map.
Returns an iterable of keys in the map
Returns an iterable of values in the map
an invertible map maintains a bidirectional one-to-many mapping between
keys
(of kindK
) and collection of values (of kindSet<V>
).the reverse mapping is also a one-to-many between
keys
(of kindV
) and collection of values (of kindSet<K>
).the dual map model of this class allows for quick lookups and mutations both directions.
this data structure highly resembles a directed graph's edges.
Example