The goog.structs Namespace

The goog.structs.AvlTree Class

Constructs an AVL-Tree, which uses the specified comparator to order its values. The values can be accessed efficiently in their sorted order since the tree enforces a O(logn) maximum height. … more

The goog.structs.CircularBuffer Class

Class for CircularBuffer. … more

The goog.structs.Collection Interface

An interface for a collection of values. @interface … more

The goog.structs.Heap Class

Class for a Heap datastructure. … more

The goog.structs.InversionMap Class

Maps ranges to values using goog.structs.Inversion. … more

The goog.structs.LinkedMap Class

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
 
… more

The goog.structs.Map Class

Class for Hash Map datastructure. … more

The goog.structs.Node Class

A generic immutable node. This can be used in various collections that require a node object for its item (such as a heap). … more

The goog.structs.Pool Class

A generic pool class. If min is greater than max, an error is thrown. … more

The goog.structs.PriorityPool Class

A generic pool class. If max is greater than min, an error is thrown. … more

The goog.structs.PriorityQueue Class

Class for Priority Queue datastructure. … more

The goog.structs.QuadTree Class

Constructs a new quad tree. … more

The goog.structs.Queue Class

Class for FIFO Queue data structure. … more

The goog.structs.Set Class

A set that can contain both primitives and objects. Adding and removing elements is O(1). Primitives are treated as identical if they have the same type and convert to the same string. Objects are treated as identical only if they are references to the same object. WARNING: A goog.structs.Set can contain both 1 and (new Number(1)), because they are not the same. WARNING: Adding (new Number(1)) twice will yield two distinct elements, because they are two different objects. WARNING: Any object that is added to a goog.structs.Set will be modified! Because goog.getUid() is used to identify objects, every object in the set will be mutated. … more

The goog.structs.SimplePool Class

A generic pool class. Simpler and more efficient than goog.structs.Pool because it doesn't maintain a list of objects that are in use. This class has constant overhead and doesn't create any additional objects as part of the pool management after construction time. IMPORTANT: If the objects being pooled are arrays or maps that can have unlimited number of properties, they need to be cleaned before being returned to the pool. Also note that {@see goog.object.clean} actually allocates an array to clean the object passed to it, so simply using this function would defy the purpose of using the pool. … more

The goog.structs.StringSet Class

Creates a set of strings. … more

The goog.structs.TreeNode Class

Generic tree node data structure with arbitrary number of child nodes. It is possible to create a dynamic tree structure by overriding {@link #getParent} and {@link #getChildren} in a subclass. All other getters will automatically work. … more

The goog.structs.Trie Class

Class for a Trie datastructure. Trie data structures are made out of trees of Trie classes. … more

.clear(col)

Removes all the elements from the collection.

col {Object}
The collection-like object.

.contains(col, val)

Whether the collection contains the given value. This is O(n) and uses equals (==) to test the existence.

col {Object}
The collection-like object.
val {*}
The value to check for.
returns {boolean}
True if the map contains the value.

.every(col, f, opt_obj)

Calls f for each value in a collection. If all calls return true this return true this returns true. If any returns false this returns false at this point and does not continue to check the remaining values.

col {Object}
The collection-like object.
f {Function}
The function to call for every value. This function takes 3 arguments (the value, the key or undefined if the collection has no notion of keys, and the collection) and should return a Boolean.
opt_obj {Object=}
The object to be used as the value of 'this' within {@code f}.
returns {boolean}
True if all key-value pairs pass the test.

.filter(col, f, opt_obj)

Calls a function for every value in the collection. When a call returns true, adds the value to a new collection (Array is returned by default).

col {Object}
The collection-like object.
f {Function}
The function to call for every value. This function takes 3 arguments (the value, the key or undefined if the collection has no notion of keys, and the collection) and should return a Boolean. If the return value is true the value is added to the result collection. If it is false the value is not included.
opt_obj {Object=}
The object to be used as the value of 'this' within {@code f}.
returns {!Object|!Array}
A new collection where the passed values are present. If col is a key-less collection an array is returned. If col has keys and values a plain old JS object is returned.

.forEach(col, f, opt_obj)

Calls a function for each value in a collection. The function takes three arguments; the value, the key and the collection.

col {Object}
The collection-like object.
f {Function}
The function to call for every value. This function takes 3 arguments (the value, the key or undefined if the collection has no notion of keys, and the collection) and the return value is irrelevant.
opt_obj {Object=}
The object to be used as the value of 'this' within {@code f}.

.getCount(col)

Returns the number of values in the collection-like object.

col {Object}
The collection-like object.
returns {number}
The number of values in the collection-like object.

.getKeys(col)

Returns the keys of the collection. Some collections have no notion of keys/indexes and this function will return undefined in those cases.

col {Object}
The collection-like object.
returns {!Array|undefined}
The keys in the collection.

.getValues(col)

Returns the values of the collection-like object.

col {Object}
The collection-like object.
returns {!Array}
The values in the collection-like object.

.isEmpty(col)

Whether the collection is empty.

col {Object}
The collection-like object.
returns {boolean}
True if empty.

.map(col, f, opt_obj)

Calls a function for every value in the collection and adds the result into a new collection (defaults to creating a new Array).

col {Object}
The collection-like object.
f {Function}
The function to call for every value. This function takes 3 arguments (the value, the key or undefined if the collection has no notion of keys, and the collection) and should return something. The result will be used as the value in the new collection.
opt_obj {Object=}
The object to be used as the value of 'this' within {@code f}.
returns {!Object|!Array}
A new collection with the new values. If col is a key-less collection an array is returned. If col has keys and values a plain old JS object is returned.

.some(col, f, opt_obj)

Calls f for each value in a collection. If any call returns true this returns true (without checking the rest). If all returns false this returns false.

col {Object|Array|string}
The collection-like object.
f {Function}
The function to call for every value. This function takes 3 arguments (the value, the key or undefined if the collection has no notion of keys, and the collection) and should return a Boolean.
opt_obj {Object=}
The object to be used as the value of 'this' within {@code f}.
returns {boolean}
True if any value passes the test.