Class for a LinkedMap datastructure, which combines O(1) map access for key/value pairs with a linked list for a consistent iteration order. Sample usage:
var m = new LinkedMap();
m.set('param1', 'A');
m.set('param2', 'B');
m.set('param3', 'C');
alert(m.getKeys()); // param1, param2, param3
var c = new LinkedMap(5, true);
for (var i = 0; i < 10; i++) {
c.set('entry' + i, false);
}
alert(c.getKeys()); // entry9, entry8, entry7, entry6, entry5
c.set('entry5', true);
c.set('entry1', false);
alert(c.getKeys()); // entry1, entry5, entry9, entry8, entry7
| Instance Method Summary | |
clear()Removes all entries in this object. | |
contains(?Object value) ⇒ booleanTests whether a provided value is currently in the LinkedMap. This does not affect item ordering in cache-style LinkedMaps. | |
containsKey(string key) ⇒ booleanTests whether a provided key is currently in the LinkedMap. This does not affect item ordering in cache-style LinkedMaps. | |
every(?Function f, ?Object= opt_obj) ⇒ booleanCalls a function on each item in the LinkedMap and returns true only if every function call returns a true-like value. | |
findAndMoveToTop_(string key) ⇒ ?goog.structs.LinkedMap.Node_Finds a node and updates it to be the most recently used. | |
forEach(?Function f, ?Object= opt_obj)Calls a function on each item in the LinkedMap. | |
get(string key, <Any Type> opt_val) ⇒ <Any Type>Retrieves the value for a given key. If this is a caching LinkedMap, the entry will become the most recently used. | |
getCount() ⇒ number | |
getKeys() ⇒ ?Array | |
getValues() ⇒ !Array | |
insert_(?goog.structs.LinkedMap.Node_ node)Appends a node to the list. LinkedMap in cache mode adds new nodes to the head of the list, otherwise they are appended to the tail. If there is a maximum size, the list will be truncated if necessary. | |
isEmpty() ⇒ boolean | |
map(!Function f, ?Object= opt_obj) ⇒ !ArrayCalls a function on each item in the LinkedMap and returns the results of those calls in an array. | |
peek() ⇒ <Any Type>Returns the value of the first node without making any modifications. | |
peekLast() ⇒ <Any Type>Returns the value of the last node without making any modifications. | |
peekValue(string key, <Any Type> opt_val) ⇒ <Any Type>Retrieves the value for a given key without updating the entry to be the most recently used. | |
pop() ⇒ <Any Type>Removes the last node from the list and returns its value. | |
popNode_(!goog.structs.LinkedMap.Node_ node) ⇒ <Any Type>Removes the node from the LinkedMap if it is not the head, and returns the node's value. | |
remove(string key) ⇒ booleanRemoves a value from the LinkedMap based on its key. | |
removeNode(!goog.structs.LinkedMap.Node_ node)Removes a node from the {@code LinkedMap}. It can be overridden to do further cleanup such as disposing of the node value. | |
set(string key, <Any Type> value)Sets a value for a given key. If this is a caching LinkedMap, this entry will become the most recently used. | |
setMaxCount(number maxCount)Sets the maximum number of entries allowed in this object, truncating any excess objects if necessary. | |
shift() ⇒ <Any Type>Removes the first node from the list and returns its value. | |
some(?Function f, ?Object= opt_obj) ⇒ booleanCalls a function on each item in the LinkedMap and returns true if any of those function calls returns a true-like value. | |
truncate_(number count)Removes elements from the LinkedMap if the given count has been exceeded. In cache mode removes nodes from the tail of the list. Otherwise removes nodes from the head. | |
| Static Method Summary | |
Node_(string key, <Any Type> value)Internal class for a doubly-linked list node containing a key/value pair. | |