new mmir.tools.Dictionary()
A dictionary (or map) for key-value storage and access.
Example
var Dictionary = new mmir.require('mmirf/dictionary');
var d = new Dictionary();
Methods
-
clear()
-
Remove all entries from the dictionary.
NOTE that this may execute rather slowly, with O(n).
-
containsKey(key){Boolean}
-
Check if the dictionary contains an entry for a key.
Name Type Description keyString the lookup key to check Returns:
Type Description Boolean trueif an entry exists, otherwisefalse -
containsValue(value, useStrict){Boolean}
-
Check if the dictionary contains an entry with the value.
NOTE that this function may execute rather slowly, with O(n).
Name Type Description valueany the value to check useStrictBoolean optional if trueentry-values are checked against param value with===. Iffalseor omitted, values are compared with each other using==.Returns:
Type Description Boolean trueif an entry exists, otherwisefalse -
get(key){any}
-
Get the value for a key.
Name Type Description keyString the lookup key with was used to store the entry/value. Returns:
Type Description any the value for the key, or undefinedif the dictionary has no entry for the key. -
Get a list of the keys for all entries in the dictionary.
The returned list has no specific ordering.
NOTE that this may execute rather slowly, with O(n).
NOTE that the returned list is no "view" for the keys, i.e. changes on this list will not be reflected by the dictionary's key-list.
Returns:
Type Description Array.<String> a list of all keys -
put(key, value)
-
Put / add an entry to the dictionary.
Name Type Description keyString the lookup key for the value valueany the value to store -
remove(key){Boolean}
-
Remove an entry from the dictionary.
NOTE that this may execute rather slowly, with O(n).
Name Type Description keyString the lookup key for the entry to remove Returns:
Type Description Boolean trueif the entry was removed. If there was no entry for the key and nothing was removed,falseis returned. -
size(){Number}
-
Get the size of the dictionary.
Returns:
Type Description Number the count of entries in the dictionary