Class: Dictionary

Dictionary

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

Remove all entries from the dictionary.

NOTE that this may execute rather slowly, with O(n).

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, otherwise false

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 ===. If false or omitted, values are compared with each other using ==.
Returns:
Type Description
Boolean true if an entry exists, otherwise false
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.
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 / add an entry to the dictionary.
Name Type Description
key String the lookup key for the value
value any the value to store
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.
Get the size of the dictionary.
Returns:
Type Description
Number the count of entries in the dictionary