The goog.structs.Map Class

goog.structs.Map(opt_map, var_args)

Class for Hash Map datastructure.

opt_map {*=}
Map or Object to initialize the map with.
var_args {...*}
If 2 or more arguments are present then they will be used as key-value pairs.

.__iterator__(opt_keys)

Returns an iterator that iterates over the values or the keys in the map. This throws an exception if the map was mutated since the iterator was created.

opt_keys {boolean=}
True to iterate over the keys. False to iterate over the values. The default value is false.
returns {!goog.iter.Iterator}
An iterator over the values or keys in the map.

.addAll(map)

Adds multiple key-value pairs from another goog.structs.Map or Object.

map {Object}
Object containing the data to add.

.clear()

Removes all key-value pairs from the map.

.clone()

Clones a map and returns a new map.

returns {!goog.structs.Map}
A new map with the same key-value pairs.

.containsKey(key)

Whether the map contains the given key.

key {*}
The key to check for.
returns {boolean}
Whether the map contains the key.

.containsValue(val)

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

val {*}
The value to check for.
returns {boolean}
Whether the map contains the value.

.defaultEquals(a, b)

Default equality test for values.

a {*}
The first value.
b {*}
The second value.
returns {boolean}
Whether a and b reference the same object.

.equals(otherMap, opt_equalityFn)

Whether this map is equal to the argument map.

otherMap {goog.structs.Map}
The map against which to test equality.
opt_equalityFn {function(?, ?) : boolean=}
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 {boolean}
Whether the maps are equal.

.get(key, opt_val)

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

key {*}
The key to get the value for.
opt_val {*=}
The value to return if no item is found for the given key, defaults to undefined.
returns {*}
The value for the given key.

.getCount()

returns {number}
The number of key-value pairs in the map.

.getKeyIterator()

Returns an iterator that iterates over the keys in the map. Removal of keys while iterating might have undesired side effects.

returns {!goog.iter.Iterator}
An iterator over the keys in the map.

.getKeys()

Returns the keys of the map.

returns {!Array.<string>}
Array of string values.

.getValueIterator()

Returns an iterator that iterates over the values in the map. Removal of keys while iterating might have undesired side effects.

returns {!goog.iter.Iterator}
An iterator over the values in the map.

.getValues()

Returns the values of the map.

returns {!Array}
The values in the map.

.isEmpty()

returns {boolean}
Whether the map is empty.

.remove(key)

Removes a key-value pair based on the key. This is O(logN) amortized due to updating the keys array whenever the count becomes half the size of the keys in the keys array.

key {*}
The key to remove.
returns {boolean}
Whether object was removed.

.set(key, value)

Adds a key-value pair to the map.

key {*}
The key.
value {*}
The value to add.
returns {*}
Some subclasses return a value.

.toObject()

returns {!Object}
Object representation of the map.

.transpose()

Returns a new map in which all the keys and values are interchanged (keys become values and values become keys). If multiple keys map to the same value, the chosen transposed value is implementation-dependent. It acts very similarly to {goog.object.transpose(Object)}.

returns {!goog.structs.Map}
The transposed map.