You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
19 KiB
28 lines
19 KiB
<!DOCTYPE html><meta charset="UTF-8"><meta http-equiv="Content-Language" content="en" /><title>goog.structs.Map</title><link href="dossier.css" rel="stylesheet" type="text/css"><div id="main-wrapper"><input type="checkbox" id="sidenav-toggle" /><main><header><h1>Class goog.structs.Map.<code class="type"><K, V></code></h1><a class="source" href="source/lib/goog/structs/map.js.src.html#l45">code »</a></header><section><p>Class for Hash Map datastructure.<h2>Constructor</h2><div class="ctor wrap-details public"><div><div class="ctor"><span class="member">goog.structs.Map <span class="args">( opt_map, var_args )</span></span></div><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>opt_map: <code class="type">*=</code><dd>Map or Object to initialize the map with.<dt>var_args: <code class="type">...*</code><dd>If 2 or more arguments are present then they
|
|
will be used as key-value pairs.</dl></table></div></div></div></section><div id="visibility-controls"><b>Show:</b><label for="show-public"><span><input type="checkbox" id="show-public" checked/></span>Public</label><label for="show-protected"><span><input type="checkbox" id="show-protected"/></span>Protected</label><label for="show-private"><span><input type="checkbox" id="show-private"/></span>Private</label></div><section id="instance-methods"><h2>Instance Methods</h2><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/structs/map.js.src.html#l424">code »</a><span class="member"><a name="__iterator__">__iterator__</a> <span class="args">( opt_keys )</span> ⇒ <code class="type">!<a href="class_goog_iter_Iterator.html">goog.iter.Iterator</a></code></span></div><p>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.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>opt_keys: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a>=</code><dd>True to iterate over the keys. False to iterate
|
|
over the values. The default value is false.</dl><tr><th>Returns<tr><td><dl>An iterator over the values or keys in the map.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/structs/map.js.src.html#l319">code »</a><span class="member"><a name="addAll">addAll</a> <span class="args">( map )</span></span></div><p>Adds multiple key-value pairs from another goog.structs.Map or Object.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>map: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a></code><dd>Object containing the data to add.</dl></table></div></details></div></div><div class="wrap-details private"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/structs/map.js.src.html#l244">code »</a><span class="member"><a name="cleanupKeysArray_">cleanupKeysArray_</a> <span class="args">( )</span></span></div><p>Cleans up the temp keys array by removing entries that are no longer in the
|
|
map.</summary></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/structs/map.js.src.html#l207">code »</a><span class="member"><a name="clear">clear</a> <span class="args">( )</span></span></div><p>Removes all key-value pairs from the map.</summary></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/structs/map.js.src.html#l356">code »</a><span class="member"><a name="clone">clone</a> <span class="args">( )</span> ⇒ <code class="type">!<a href="class_goog_structs_Map.html">goog.structs.Map</a></code></span></div><p>Clones a map and returns a new map.</summary><div class="info"><table><tbody><tr><th>Returns<tr><td><dl>A new map with the same key-value pairs.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/structs/map.js.src.html#l134">code »</a><span class="member"><a name="containsKey">containsKey</a> <span class="args">( key )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code></span></div><p>Whether the map contains the given key.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>key: <code class="type">*</code><dd>The key to check for.</dl><tr><th>Returns<tr><td><dl>Whether the map contains the key.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/structs/map.js.src.html#l144">code »</a><span class="member"><a name="containsValue">containsValue</a> <span class="args">( val )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code></span></div><p>Whether the map contains the given value. This is O(n).</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>val: <code class="type">V</code><dd>The value to check for.</dl><tr><th>Returns<tr><td><dl>Whether the map contains the value.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/structs/map.js.src.html#l163">code »</a><span class="member"><a name="equals">equals</a> <span class="args">( otherMap, opt_equalityFn )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code></span></div><p>Whether this map is equal to the argument map.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>otherMap: <code class="type"><a href="class_goog_structs_Map.html">goog.structs.Map</a></code><dd>The map against which to test equality.<dt>opt_equalityFn: <code class="type">function(V, V): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a>=</code><dd>Optional equality function
|
|
to test equality of values. If not specified, this will test whether
|
|
the values contained in each map are identical objects.</dl><tr><th>Returns<tr><td><dl>Whether the maps are equal.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/structs/map.js.src.html#l342">code »</a><code class="type"><T></code> <span class="member"><a name="forEach">forEach</a> <span class="args">( f, opt_obj )</span></span></div><p>Calls the given function on each entry in the map.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>f<dt>opt_obj: <code class="type">T=</code><dd>The value of "this" inside f.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/structs/map.js.src.html#l290">code »</a><code class="type"><DEFAULT></code> <span class="member"><a name="get">get</a> <span class="args">( key, opt_val )</span> ⇒ <code class="type">(V|DEFAULT)</code></span></div><p>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</code>.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>key: <code class="type">*</code><dd>The key to get the value for.<dt>opt_val: <code class="type">DEFAULT=</code><dd>The value to return if no item is found for the
|
|
given key, defaults to undefined.</dl><tr><th>Returns<tr><td><dl>The value for the given key.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/structs/map.js.src.html#l98">code »</a><span class="member"><a name="getCount">getCount</a> <span class="args">( )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code></span></div></summary><div class="info"><table><tbody><tr><th>Returns<tr><td><dl>The number of key-value pairs in the map.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/structs/map.js.src.html#l401">code »</a><span class="member"><a name="getKeyIterator">getKeyIterator</a> <span class="args">( )</span> ⇒ <code class="type">!<a href="class_goog_iter_Iterator.html">goog.iter.Iterator</a></code></span></div><p>Returns an iterator that iterates over the keys in the map. Removal of keys
|
|
while iterating might have undesired side effects.</summary><div class="info"><table><tbody><tr><th>Returns<tr><td><dl>An iterator over the keys in the map.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/structs/map.js.src.html#l123">code »</a><span class="member"><a name="getKeys">getKeys</a> <span class="args">( )</span> ⇒ <code class="type">!<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>></code></span></div><p>Returns the keys of the map.</summary><div class="info"><table><tbody><tr><th>Returns<tr><td><dl>Array of string values.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/structs/map.js.src.html#l411">code »</a><span class="member"><a name="getValueIterator">getValueIterator</a> <span class="args">( )</span> ⇒ <code class="type">!<a href="class_goog_iter_Iterator.html">goog.iter.Iterator</a></code></span></div><p>Returns an iterator that iterates over the values in the map. Removal of
|
|
keys while iterating might have undesired side effects.</summary><div class="info"><table><tbody><tr><th>Returns<tr><td><dl>An iterator over the values in the map.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/structs/map.js.src.html#l107">code »</a><span class="member"><a name="getValues">getValues</a> <span class="args">( )</span> ⇒ <code class="type">!<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<V></code></span></div><p>Returns the values of the map.</summary><div class="info"><table><tbody><tr><th>Returns<tr><td><dl>The values in the map.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/structs/map.js.src.html#l199">code »</a><span class="member"><a name="isEmpty">isEmpty</a> <span class="args">( )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code></span></div></summary><div class="info"><table><tbody><tr><th>Returns<tr><td><dl>Whether the map is empty.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/structs/map.js.src.html#l222">code »</a><span class="member"><a name="remove">remove</a> <span class="args">( key )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code></span></div><p>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.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>key: <code class="type">*</code><dd>The key to remove.</dl><tr><th>Returns<tr><td><dl>Whether object was removed.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/structs/map.js.src.html#l304">code »</a><span class="member"><a name="set">set</a> <span class="args">( key, value )</span> ⇒ <code class="type">*</code></span></div><p>Adds a key-value pair to the map.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>key: <code class="type">*</code><dd>The key.<dt>value: <code class="type">V</code><dd>The value to add.</dl><tr><th>Returns<tr><td><dl>Some subclasses return a value.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/structs/map.js.src.html#l385">code »</a><span class="member"><a name="toObject">toObject</a> <span class="args">( )</span> ⇒ <code class="type">!<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a></code></span></div></summary><div class="info"><table><tbody><tr><th>Returns<tr><td><dl>Object representation of the map.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/structs/map.js.src.html#l370">code »</a><span class="member"><a name="transpose">transpose</a> <span class="args">( )</span> ⇒ <code class="type">!<a href="class_goog_structs_Map.html">goog.structs.Map</a></code></span></div><p>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)}.</summary><div class="info"><table><tbody><tr><th>Returns<tr><td><dl>The transposed map.</dl></table></div></details></div></div></section><section id="instance-properties"><h2>Instance Properties</h2><div class="wrap-details private"><div><details><summary><div><a class="source" href="source/lib/goog/structs/map.js.src.html#l72">code »</a><span class="member"><a name="count_">count_</a> : <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code></span></div><p>The number of key value pairs in the map.</summary></details></div></div><div class="wrap-details private"><div><details><summary><div><a class="source" href="source/lib/goog/structs/map.js.src.html#l66">code »</a><span class="member"><a name="keys_">keys_</a> : <code class="type">!<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>.<<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>></code></span></div><p>An array of keys. This is necessary for two reasons:
|
|
1. Iterating the keys using for (var key in this.map_) allocates an
|
|
object for every key in IE which is really bad for IE6 GC perf.
|
|
2. Without a side data structure, we would need to escape all the keys
|
|
as that would be the only way we could tell during iteration if the
|
|
key was an internal key or a property of the object.
|
|
|
|
This array can contain deleted keys so it's necessary to check the map
|
|
as well to see if the key is still in the map (this doesn't require a
|
|
memory allocation in IE).</summary></details></div></div><div class="wrap-details private"><div><details><summary><div><a class="source" href="source/lib/goog/structs/map.js.src.html#l51">code »</a><span class="member"><a name="map_">map_</a> : <code class="type">!<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a></code></span></div><p>Underlying JS object used to implement the map.</summary></details></div></div><div class="wrap-details private"><div><details><summary><div><a class="source" href="source/lib/goog/structs/map.js.src.html#l78">code »</a><span class="member"><a name="version_">version_</a> : <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code></span></div><p>Version used to detect changes while iterating.</summary></details></div></div></section><section id="static-functions"><h2>Static Functions</h2><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/structs/map.js.src.html#l191">code »</a><span class="member"><a name="goog.structs.Map.defaultEquals">goog.structs.Map.defaultEquals</a> <span class="args">( a, b )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code></span></div><p>Default equality test for values.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>a: <code class="type">*</code><dd>The first value.<dt>b: <code class="type">*</code><dd>The second value.</dl><tr><th>Returns<tr><td><dl>Whether a and b reference the same object.</dl></table></div></details></div></div><div class="wrap-details private"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/structs/map.js.src.html#l459">code »</a><span class="member"><a name="goog.structs.Map.hasKey_">goog.structs.Map.hasKey_</a> <span class="args">( obj, key )</span> ⇒ <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code></span></div><p>Safe way to test for hasOwnProperty. It even allows testing for
|
|
'hasOwnProperty'.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>obj: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a></code><dd>The object to test for presence of the given key.<dt>key: <code class="type">*</code><dd>The key to check for.</dl><tr><th>Returns<tr><td><dl>Whether the object has the key.</dl></table></div></details></div></div></section></main><nav id="topnav"><div><div id="menubutton"><label for="sidenav-toggle">Menu</label></div><form id="searchbox"><div><input type="search" placeholder="Search" tabindex="1"></div></form></div></nav><nav id="sidenav"><input type="checkbox" id="sidenav-types-ctrl" /><input type="checkbox" id="sidenav-files-ctrl" /><input type="checkbox" id="sidenav-modules-ctrl" /><a id="sidenav-overview"><div><h4>Overview</h4></div></a><div id="sidenav-types"><label for="sidenav-types-ctrl"><h4>Types</h4></label><i>No data</i></div><div id="sidenav-modules"><label for="sidenav-modules-ctrl"><h4>Modules</h4></label><i>No data</i></div><div id="sidenav-files"><label for="sidenav-files-ctrl"><h4>Files</h4></label><i>No data</i></div><a href="license.html"><div><h4>License</h4></div></a></nav><div id="push-footer"></div></div><footer><a href="https://github.com/jleyba/js-dossier">Generated by dossier</a></footer><script src="types.js"></script><script src="dossier.js"></script> |