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 key
String the lookup key to check Returns:
Type Description Boolean true
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 value
any the value to check useStrict
Boolean optional if true
entry-values are checked against param value with===
. Iffalse
or omitted, values are compared with each other using==
.Returns:
Type Description Boolean true
if an entry exists, otherwisefalse
-
get(key){any}
-
Get the value for a key.
Name Type Description key
String the lookup key with was used to store the entry/value. Returns:
Type Description any the value for the key, or undefined
if 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:
Type Description Array.<String> a 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 key
String the key (without the internal key prefix) Returns:
Type Description String the key prefixed with the internal key prefix -
put(key, value)
-
Put / add an entry to the dictionary.
Name Type Description key
String the lookup key for the value value
any 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 key
String the lookup key for the entry to remove Returns:
Type Description Boolean true
if the entry was removed. If there was no entry for the key and nothing was removed,false
is returned. -
size(){Number}
-
Get the size of the dictionary.
Returns:
Type Description Number the count of entries in the dictionary