MultiMap
Provides a multi-level Map implementation that mirrors the Map API except for exclusion of forEach
.
Each method takes a variable list of parameters. By not including any parameters when invoking methods of
MultiLevelMap
the base Map is the target. A list of comma separated parameters will index into the backing
multi-level map structure.
Errors will be thrown for methods that require a minimum number of keys including:
delete(1), get(1), has(1), set(2)
. In particular set requires the actual value being set in addition to any
number of keys. Another caveat of set()
is that if at any level of indexed keys a value is already set for the
given key index an Error will be thrown due to the pre-existing value not being a Map.
Example:
const map = new MultiMap();
map.set('key1', 'key2', 1); // creates a 2nd level Map indexed by 'key1' with value '1' indexed by 'key2'.
map.get('key1'); // returns the 2nd level Map.
map.get('key1', 'key2'); // returns '1'; 'key1' indexes into the 2nd level map with 'key2'.
map.has('key1', 'key2'); // is true.
Constructor Summary
Public Constructor | ||
public |
Initializes the MultiLevelMap |
Method Summary
Public Methods | ||
public |
clear(keys: *) The |
|
public |
The |
|
public |
entries(keys: *): Iterator The |
|
public |
get(keys: *): * The |
|
public |
The |
|
public |
The |
|
public |
keys(keys: *): Iterator The |
|
public |
The |
|
public |
The |
|
public |
values(keys: *): Iterator The |
Public Constructors
Public Methods
public clear(keys: *) source
The clear()
method removes all elements from a Map object. If no keys are provided then the base map is cleared.
Subsequent keys will attempt to index into additional levels of the MultiLevelMap.
Params:
Name | Type | Attribute | Description |
keys | * | A variable list of keys to index subsequent levels of the MultiLevelMap. |
public delete(keys: *): boolean source
The delete()
method removes the specified element from a Map object. If one key is provided then the base map
is the target. Subsequent keys will attempt to index into additional levels of the MultiLevelMap.
Params:
Name | Type | Attribute | Description |
keys | * | A variable list of keys to index subsequent levels of the MultiLevelMap. |
public entries(keys: *): Iterator source
The entries()
method returns a new Iterator object that contains the [key, value] pairs for each element in the
Map object in insertion order. If one key is provided then the base map is the target. Subsequent keys will
attempt to index into additional levels of the MultiLevelMap. If no Map is found then an empty iterator is
returned.
Params:
Name | Type | Attribute | Description |
keys | * | A variable list of keys to index subsequent levels of the MultiLevelMap. |
Return:
Iterator |
public get(keys: *): * source
The get()
method returns a specified element from a Map object. If one key is provided then the base map is the
target. Subsequent keys will attempt to index into additional levels of the MultiLevelMap. If no indexed Map is
found then undefined
is returned.
Params:
Name | Type | Attribute | Description |
keys | * | A variable list of keys to index subsequent levels of the MultiLevelMap. |
Return:
* |
public has(keys: *): boolean source
The has()
method returns a boolean indicating whether an element with the specified key exists or not. If one
key is provided then the base map is the target. Subsequent keys will attempt to index into additional levels of
the MultiLevelMap. If no indexed Map is found then false
is returned.
Params:
Name | Type | Attribute | Description |
keys | * | A variable list of keys to index subsequent levels of the MultiLevelMap. |
public isMap(keys: *): boolean source
The isMap()
method returns a boolean indicating whether specified sequence of keys resolves to an existing Map.
If one key is provided then the base map is the target. Subsequent keys will attempt to index into additional
levels of the MultiLevelMap. If no indexed Map is found then false
is returned.
Params:
Name | Type | Attribute | Description |
keys | * | A variable list of keys to index subsequent levels of the MultiLevelMap. |
public keys(keys: *): Iterator source
The keys()
method returns a new Iterator object that contains the keys for each element in the Map object in
insertion order. If one key is provided then the base map is the target. Subsequent keys will attempt to index
into additional levels of the MultiLevelMap. If no Map is found then an empty iterator is returned.
Params:
Name | Type | Attribute | Description |
keys | * | A variable list of keys to index subsequent levels of the MultiLevelMap. |
Return:
Iterator |
public set(params: *): Map | undefined source
The set()
method adds a new element with a specified key and value to a Map object. If one key is provided then
the base map is the target. Subsequent keys will attempt to index into additional levels of the MultiLevelMap.
New Maps are automatically created at each level for the given key parameters. The target Map that the value
is added to is returned.
Params:
Name | Type | Attribute | Description |
params | * | A variable list of keys to index subsequent levels of the MultiLevelMap with the last entry being the value to be set / added. |
public size(keys: *): number source
The size()
method returns an integer representing how many entries the Map object has. If no key is provided
then the base map is the target. Subsequent keys will attempt to index into additional levels of the
MultiLevelMap. If no indexed Map is found then 0
is returned.
Params:
Name | Type | Attribute | Description |
keys | * | A variable list of keys to index subsequent levels of the MultiLevelMap. |
public values(keys: *): Iterator source
The values()
method returns a new Iterator object that contains the values for each element in the Map object in
insertion order. If one key is provided then the base map is the target. Subsequent keys will attempt to index
into additional levels of the MultiLevelMap. If no Map is found then an empty iterator is returned.
Params:
Name | Type | Attribute | Description |
keys | * | A variable list of keys to index subsequent levels of the MultiLevelMap. |
Return:
Iterator |