Class: HashMultiMap

js_cols. HashMultiMap

new HashMultiMap(opt_map, var_args)

This file contains an implementation of a Hash Mutli Map structure. A Mutli Map can contain more values for one key. It is based on goog.structs.Map from the google closure library, but has been modified to accept any kind of objects as keys (not only Strings or Numbers). Hence, the functionality is similar to that of java.util.HashMap. WARNING: keys that are either Objects or Functions will be modified, a property named something like "js_cols_uid_2kczq5" will be added. This liberates the user of implementing a getHashCode function, and improves performance as hashing collisions are avoided. The assymptotic running time for important operations are below:

  Method                 big-O
----------------------------------------------------------------------------
- clear                  O(1)
- clone                  O(n logn)
- contains               O(1)
- containsAll            O(m) m is the cardinality of the supplied collection
- every                  O(n * O(f)) f is the function supplied as argument
- filter                 O(n * O(f)) f is the function supplied as argument
- forEach                O(n * O(f)) f is the function supplied as argument
- get                    O(1)
- getValues              O(n)
- insert                 O(1)
- insertAll              O(m) m is the cardinality of the supplied collection
- map                    O(n * O(f)) f is the function supplied as argument
- remove                 O(1)
- removeAll              O(m logn) m is the cardinality of the supplied collection
- some                   O(n * O(f)) f is the function supplied as argument
- contains               O(n * O(f)) f is the function supplied as argument
Parameters:
Name Type Argument Description
opt_map * <optional>

Map or Object to initialize the map with.

var_args * <repeatable>

If 2 or more arguments are present then they will be used as key-value pairs.

Methods

clear()

Removes all key-value pairs from the map.

clone() → {js_cols.HashMultiMap}

Clones a multi map and returns a new multi map.

Returns:

A new map with the same key-value pairs.

Type
js_cols.HashMultiMap

contains(key) → {boolean}

This operation is identical to containsKey Whether the map contains the given key.

Parameters:
Name Type Description
key *

The key to check for.

Returns:

Whether the map contains the key.

Type
boolean

containsAll(col) → {Boolean}

Checks that all values contained in the collection are also contained as keys in the tree

Parameters:
Name Type Description
col
Returns:
Type
Boolean

containsKey(key) → {Integer}

Whether the map contains the given key.

Parameters:
Name Type Description
key *

The key to check for.

Returns:

Number of values for the key.

Type
Integer

containsValue(val) → {boolean}

Whether the map contains the given value. This is O(n).

Parameters:
Name Type Description
val *

The value to check for.

Returns:

Whether the map contains the value.

Type
boolean

defaultEquals(a, b) → {boolean}

Default equality test for values.

Parameters:
Name Type Description
a *

The first value.

b *

The second value.

Returns:

Whether a and b reference the same object.

Type
boolean

equals(otherMap, opt_equalityFn) → {boolean}

Whether this map is equal to the argument map.

Parameters:
Name Type Description
otherMap js_cols.HashMap

The map against which to test equality.

opt_equalityFn function

Optional equality function to test equality of values. If not specified, this will test whether the values contained in each map are identical objects.

Returns:

Whether the maps are equal.

Type
boolean

every(f, opt_obj) → {boolean}

Calls a function on each item in the HashMultiMap and returns true only if every function call returns a true-like value.

Parameters:
Name Type Argument Description
f function

The function to call for each item. The function takes three arguments: the value, the key, and the HashMultiMap, and returns a boolean.

opt_obj Object <optional>

The object context to use as "this" for the function.

Returns:

Whether f evaluates to true for every item in the HashMultiMap.

Type
boolean

filter(f, opt_obj) → {js_cols.HashMultiMap}

Calls a function on each item in the HashMultiMap, if the function returns true, the key/value pair is inserted into an object that is returned when the tree is fully traversed

Parameters:
Name Type Argument Description
f function

The function to call for each item. The function takes three arguments: the value, the key, and the HashMultiMap.

opt_obj Object <optional>

The object context to use as "this" for the function.

Returns:

a new multi map with the key / value pairs that evaluated to true in the function calls

Type
js_cols.HashMultiMap

forEach(f, opt_obj)

Calls a function on each item in the HashMultiMap.

Parameters:
Name Type Argument Description
f function

The function to call for each item. The function takes three arguments: the value, the key, and the HashMultiMap.

opt_obj Object <optional>

The object context to use as "this" for the function.

get(key, opt_val) → {*}

Returns the most recently inserted value for the given key. If the key is not found and the default value is not given this will return {@code undefined}.

Parameters:
Name Type Argument Description
key *

The key to get the value for.

opt_val * <optional>

The value to return if no item is found for the given key, defaults to undefined.

Returns:

The value for the given key.

Type
*

getAllValuesForKey(key, opt_val) → {Array}

Returns all values for the given key in an Array. If the key is not found and the default value is not given this will return {@code undefined}.

Parameters:
Name Type Argument Description
key *

The key to get the values for.

opt_val * <optional>

The value to return if no item is found for the given key, defaults to undefined.

Returns:

The values for the given key.

Type
Array

getCount() → {number}

Returns:

The number of key-value pairs in the map.

Type
number

getKeys() → {Array}

Returns the keys of the map.

Returns:

Array of key values.

Type
Array

getValues() → {Array}

Returns the values of the map.

Returns:

The values in the map.

Type
Array

insert(key, value)

Adds a key-value pair to the map.

Parameters:
Name Type Description
key *

The key.

value *

The value to add.

insertValuesForKey(key, values)

Associates all ellements of the values Array to the key in this map.

Parameters:
Name Type Description
key *

The key.

values Array

The values to add.

isEmpty() → {boolean}

Returns:

Whether the map is empty.

Type
boolean

map(f, opt_obj) → {Array}

Calls a function on each item in the HashMultiMap and returns the results of those calls in an array.

Parameters:
Name Type Argument Description
f function

The function to call for each item. The function takes three arguments: the value, the key, and the HashMultiMap.

opt_obj Object <optional>

The object context to use as "this" for the function.

Returns:

The results of the function calls for each item in the HashMultiMap.

Type
Array

remove(key) → {boolean}

Removes a key-value pair based on the key. If more than one entry for the key are present in the map, the most recently inserted will be removed

Parameters:
Name Type Description
key *

The key to remove.

Returns:

Whether object was removed.

Type
boolean

removeAll(col)

Removes a all values contained in the collection from the tree If the collection has no notion of keys (i.e. an Array or a Set), the values of the collection will be treated as keys in this map.

Parameters:
Name Type Description
col

removeAllValuesForKey(key) → {boolean}

Removes all values associated with the key.

Parameters:
Name Type Description
key *

The key to remove.

Returns:

Whether one or more objects were removed.

Type
boolean

some(f, opt_obj) → {boolean}

Calls a function on each item in the HashMultiMap and returns true if any of those function calls returns a true-like value.

Parameters:
Name Type Argument Description
f function

The function to call for each item. The function takes three arguments: the value, the key and the HashMultiMap, and returns a boolean.

opt_obj Object <optional>

The object context to use as "this" for the function.

Returns:

Whether f evaluates to true for at least one item in the RedBlackSet.

Type
boolean
js_cols - powerful collection classes for JavaScript
js_cols Copyright © 2010-2015 Thomas Stjernegaard Jeppesen.
Documentation generated by JSDoc 3.3.0-alpha13 on Sat Dec 27th 2014 using the DocStrap template.