structs.LinkedMap Extends
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

Inheritance

Constructor

goog.structs.LinkedMap(opt_maxCountopt_cache)

Parameters

opt_maxCount : number=
The maximum number of objects to store in the LinkedMap. If unspecified or 0, there is no maximum.
opt_cache : boolean=
When set, the LinkedMap stores items in order from most recently used to least recently used, instead of insertion order.

Instance Methods

Public Protected Private
clear()
Removes all entries in this object.
code »
contains(value) boolean
Tests whether a provided value is currently in the LinkedMap. This does not affect item ordering in cache-style LinkedMaps.
Arguments:
value : VALUE
The value to check for.
Returns: boolean  Whether the value is in the LinkedMap.
code »
containsKey(key) boolean
Tests whether a provided key is currently in the LinkedMap. This does not affect item ordering in cache-style LinkedMaps.
Arguments:
key : string
The key to check for.
Returns: boolean  Whether the key is in the LinkedMap.
code »
every(fopt_obj) boolean
Calls a function on each item in the LinkedMap and returns true only if every function call returns a true-like value.
Arguments:
f : Function
The function to call for each item. The function takes three arguments: the value, the key, and the Cache, and returns a boolean.
opt_obj : Object=
The object context to use as "this" for the function.
Returns: boolean  Whether f evaluates to true for every item in the Cache.
code »
findAndMoveToTop_(key) goog.structs.LinkedMap.Node_
Finds a node and updates it to be the most recently used.
Arguments:
key : string
The key of the node.
Returns: goog.structs.LinkedMap.Node_  The node or null if not found.
code »
forEach(fopt_obj)
Calls a function on each item in the LinkedMap.
Arguments:
f : Function
The function to call for each item. The function takes three arguments: the value, the key, and the LinkedMap.
opt_obj : Object=
The object context to use as "this" for the function.
code »
get(keyopt_val) VALUE
Retrieves the value for a given key. If this is a caching LinkedMap, the entry will become the most recently used.
Arguments:
key : string
The key to retrieve the value for.
opt_val : VALUE=
A default value that will be returned if the key is not found, defaults to undefined.
Returns: VALUE  The retrieved value.
code »
getCount() number
No description.
Returns: number  The number of items currently in the LinkedMap.
code »
getKeys() !Array.<string>
No description.
Returns: !Array.<string>  The list of the keys in the appropriate order for this LinkedMap.
code »
getValues() !Array.<VALUE>
No description.
Returns: !Array.<VALUE>  The list of the values in the appropriate order for this LinkedMap.
code »
insert_(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.
Arguments:
node : goog.structs.LinkedMap.Node_
The item to insert.
code »
isEmpty() boolean
No description.
Returns: boolean  True if the cache is empty, false if it contains any items.
code »
map(fopt_obj) !Array.<VALUE>
Calls a function on each item in the LinkedMap and returns the results of those calls in an array.
Arguments:
f : !Function
The function to call for each item. The function takes three arguments: the value, the key, and the LinkedMap.
opt_obj : Object=
The object context to use as "this" for the function.
Returns: !Array.<VALUE>  The results of the function calls for each item in the LinkedMap.
code »
peek() VALUE
Returns the value of the first node without making any modifications.
Returns: VALUE  The value of the first node or undefined if the map is empty.
code »
peekLast() VALUE
Returns the value of the last node without making any modifications.
Returns: VALUE  The value of the last node or undefined if the map is empty.
code »
peekValue(keyopt_val) VALUE
Retrieves the value for a given key without updating the entry to be the most recently used.
Arguments:
key : string
The key to retrieve the value for.
opt_val : VALUE=
A default value that will be returned if the key is not found.
Returns: VALUE  The retrieved value.
code »
pop() VALUE
Removes the last node from the list and returns its value.
Returns: VALUE  The value of the popped node, or undefined if the map was empty.
code »
popNode_(node) VALUE
Removes the node from the LinkedMap if it is not the head, and returns the node's value.
Arguments:
node : !goog.structs.LinkedMap.Node_
The item to remove.
Returns: VALUE  The value of the popped node.
code »
remove(key) boolean
Removes a value from the LinkedMap based on its key.
Arguments:
key : string
The key to remove.
Returns: boolean  True if the entry was removed, false if the key was not found.
code »
removeNode(node)
Removes a node from the LinkedMap. It can be overridden to do further cleanup such as disposing of the node value.
Arguments:
node : !goog.structs.LinkedMap.Node_
The node to remove.
code »
set(keyvalue)
Sets a value for a given key. If this is a caching LinkedMap, this entry will become the most recently used.
Arguments:
key : string
The key to retrieve the value for.
value : VALUE
A default value that will be returned if the key is not found.
code »
setMaxCount(maxCount)
Sets the maximum number of entries allowed in this object, truncating any excess objects if necessary.
Arguments:
maxCount : number
The new maximum number of entries to allow.
code »
shift() VALUE
Removes the first node from the list and returns its value.
Returns: VALUE  The value of the popped node, or undefined if the map was empty.
code »
some(fopt_obj) boolean
Calls a function on each item in the LinkedMap and returns true if any of those function calls returns a true-like value.
Arguments:
f : Function
The function to call for each item. The function takes three arguments: the value, the key, and the LinkedMap, and returns a boolean.
opt_obj : Object=
The object context to use as "this" for the function.
Returns: boolean  Whether f evaluates to true for at least one item in the LinkedMap.
code »
truncate_(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.
Arguments:
count : number
Number of elements to keep.
code »

Instance Properties

cache_ :
No description.
Code »
No description.
Code »
No description.
Code »
maxCount_ :
The maximum number of entries to allow, or null if there is no limit.
Code »

Package structs

Package Reference