Constructor
new BiMap(entries?)
Initialize a bidirectional map.
Parameters:
Name | Type | Description |
---|---|---|
entries? |
Iterable | An iterable yielding all key-value tuples that will be fed into the Map. Without this, the Map is initialized to empty. |
- Source:
Example
const biMap1 = new BiMap(existingMap);
const biMap2 = new BiMap(existingBiMap);
const biMap3 = new BiMap([["a", 1]]);
const biMap4 = new BiMap(Object.entries({"a": 1}));
Extends
- Map
Members
reversed
Access the reversed map.
This makes some operations very simple, like biMap.reversed.entries()
to get a list of value-to-key tuples for downstream processing.
- Source:
Methods
clear()
Removes all key/value pairs from the BiMap object.
- Source:
delete(key)
Delete the key-value pair associated with key
.
Does nothing if that entry is not present.
Parameters:
Name | Type | Description |
---|---|---|
key |
K | The key to delete. |
- Source:
Returns:
true
if an element in the Map object existed and has been removed, false
if the element does not exist.
deleteVal(val)
Delete the key-value pair associated with val
.
Do nothing if that entry is not present.
Parameters:
Name | Type | Description |
---|---|---|
val |
T | The value to delete. |
- Source:
Returns:
true
if an element in the Map object existed and has been removed, false
if the element does not exist.
getKey(val)
Return the key associated to value
, or undefined
if there is none.
Parameters:
Name | Type | Description |
---|---|---|
val |
T | The value to look up. |
- Source:
hasVal(val)
Check for the presence of a value in the Map.
Parameters:
Name | Type | Description |
---|---|---|
val |
The value to look up. |
- Source:
Returns:
A boolean asserting whether a key has been associated to val
in the Map object or not.
set(key, val)
Set the value for the key in the BiMap object. Returns the BiMap object.
Parameters:
Name | Type | Description |
---|---|---|
key |
K | The key to set. |
val |
T | The value to set at that key. |
- Source: