new Dictionary()
A dictionary (or map) for key-value storage and access.
Members
-
private,constantKEY_PREFIX
-
Prefix for keys in internal MAP object, for avoiding overwrite of existing Object properties/functions
-
privatekeyList
-
This list contains the "keys" of all current entries in map.
-
privatemap
-
"map" for the 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:
if 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:
if 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:
value for the key, orundefinedif the dictionary has no entry for the key.
-
getKeys(){Array.<String>}
-
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:
list of all keys
-
privatelookupKey(key){String}
-
Helper function that creates the actual lookup key. The "lookup key" is original key with applied key-prefix.
Name Type Description keyString the key (without the internal key prefix) Returns:
key prefixed with the internal key prefix
-
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:
if 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:
count of entries in the dictionary