Object buckets.Dictionary
Dictionaries map keys to values, each key can map to at most one value. This implementation accepts any kind of objects as keys.
If the keys are custom objects, a function that converts keys to unique strings must be provided at construction time.
Example:
function petToString(pet) { return pet.name; }
Constructor Name and Description |
---|
buckets.Dictionary(toStrFunction)
Creates an empty dictionary.
|
Method Name and Description |
---|
buckets.Dictionary.clear()
Removes all keys and values from the dictionary.
|
buckets.Dictionary.containsKey(key)
Returns true if the dictionary contains a mapping for the specified key.
|
buckets.Dictionary.equals(other, equalsFunction)
Returns true if the dictionary is equal to another dictionary.
|
buckets.Dictionary.forEach(callback)
Executes the provided function once per key-value pair
present in the dictionary.
|
buckets.Dictionary.get(key)
Returns the value associated with the specified key in the dictionary.
|
buckets.Dictionary.isEmpty()
Returns true if the dictionary contains no keys.
|
buckets.Dictionary.keys()
Returns an array containing all the keys in the dictionary.
|
buckets.Dictionary.remove(key)
Removes the value associated with the specified key from the dictionary if it exists.
|
buckets.Dictionary.set(key, value)
Associates the specified value with the specified key in the dictionary.
|
buckets.Dictionary.size()
Returns the number of key-value pais in the dictionary.
|
buckets.Dictionary.values()
Returns an array containing all the values in the dictionary.
|
Object Detail
buckets.Dictionary(toStrFunction)
Creates an empty dictionary.
- Parameters:
- {function(Object):string=} toStrFunction
- Optional function used to convert keys to unique strings. If the keys aren't strings or if toString() is not appropriate, a custom function which receives a key and returns a unique string must be provided.
Method Detail
<static>
buckets.Dictionary.clear()
Removes all keys and values from the dictionary.
<static>
{boolean}
buckets.Dictionary.containsKey(key)
Returns true if the dictionary contains a mapping for the specified key.
- Parameters:
- {Object} key
- The key.
- Returns:
- {boolean} True if the dictionary contains a mapping for the specified key.
<static>
{boolean}
buckets.Dictionary.equals(other, equalsFunction)
Returns true if the dictionary is equal to another dictionary.
Two dictionaries are equal if they have the same key-value pairs.
- Parameters:
- {buckets.Dictionary} other
- The other dictionary.
- {function(Object|Object):boolean=} equalsFunction
- Optional function to check if two values are equal. If the values in the dictionaries are custom objects you should provide a custom equals function, otherwise the === operator is used to check equality between values.
- Returns:
- {boolean} True if the dictionary is equal to the given dictionary.
<static>
buckets.Dictionary.forEach(callback)
Executes the provided function once per key-value pair
present in the dictionary.
- Parameters:
- {function(Object|Object):*} callback
- Function to execute. Receives 2 arguments: key and value. To break the iteration you can optionally return false inside the callback.
<static>
{*}
buckets.Dictionary.get(key)
Returns the value associated with the specified key in the dictionary.
- Parameters:
- {Object} key
- The key.
- Returns:
- {*} The mapped value or undefined if the dictionary contains no mapping for the provided key.
<static>
{boolean}
buckets.Dictionary.isEmpty()
Returns true if the dictionary contains no keys.
- Returns:
- {boolean} True if this dictionary contains no mappings.
<static>
{Array}
buckets.Dictionary.keys()
Returns an array containing all the keys in the dictionary.
- Returns:
- {Array} An array containing all the keys in the dictionary.
<static>
{*}
buckets.Dictionary.remove(key)
Removes the value associated with the specified key from the dictionary if it exists.
- Parameters:
- {Object} key
- The key.
- Returns:
- {*} Removed value associated with the specified key, or undefined if there was no mapping for the key.
<static>
{*}
buckets.Dictionary.set(key, value)
Associates the specified value with the specified key in the dictionary.
If the dictionary previously contained a mapping for the key, the old
value is replaced by the specified value.
- Parameters:
- {Object} key
- The key.
- {Object} value
- Value to be mapped with the specified key.
- Returns:
- {*} Previous value associated with the provided key, or undefined if there was no mapping for the key or the key/value is undefined.
<static>
{number}
buckets.Dictionary.size()
Returns the number of key-value pais in the dictionary.
- Returns:
- {number} The number of key-value mappings in the dictionary.
<static>
{Array}
buckets.Dictionary.values()
Returns an array containing all the values in the dictionary.
- Returns:
- {Array} An array containing all the values in the dictionary.