goog.structs.Trie
Classgoog.structs.Trie(opt_trie)
Class for a Trie datastructure. Trie data structures are made out of trees of Trie classes.
opt_trie
{Object
=}
.add(key, value)
Adds the given key/value pair in the trie. Throw an exception if the key already exists in the trie. O(L), where L is the length of the key.
key
{string
}
value
{*}
.clear()
Completely empties a trie of all keys and values. ~O(1)
.clone()
Clones a trie and returns a new trie. O(N), where N is the number of nodes in the trie.
goog.structs.Trie
}
.containsKey(key)
Checks to see if a certain key is in the trie. O(L), where L is the length of the key.
key
{string
}
boolean
}
.containsValue(value)
Checks to see if a certain value is in the trie. Worst case is O(N) where N is the number of nodes in the trie.
value
{*}
boolean
}
.get(key)
Retrieves a value from the trie given a key. O(L), where L is the length of the key.
key
{string
}
.getCount()
Returns the number of key value pairs in the trie. O(N), where N is the number of nodes in the trie. TODO: This could be optimized by storing a weight (count below) in every node.
number
}
.getKeyAndPrefixes(key, opt_keyStartIndex)
Retrieves all values from the trie that correspond to prefixes of the given input key. O(L), where L is the length of the key.
key
{string
}
opt_keyStartIndex
{?number
=}
Object
}
.getKeys(opt_prefix)
Gets the keys of the trie. Not returned in any reliable order. O(N) where N is the number of nodes in the trie (or prefix subtree).
opt_prefix
{string
=}
Array
}
.getValues()
Gets the values of the trie. Not returned in any reliable order. O(N) where N is the number of nodes in the trie. Calls getValuesInternal_.
Array
}
.isEmpty()
Returns true if this trie contains no elements. ~O(1).
boolean
}
.remove(key)
Removes a key from the trie or throws an exception if the key is not in the trie. O(L), where L is the length of the key.
key
{string
}
.set(key, value)
Sets the given key/value pair in the trie. O(L), where L is the length of the key.
key
{string
}
value
{*}
.setAll(trie)
Adds multiple key/value pairs from another goog.structs.Trie or Object. O(N) where N is the number of nodes in the trie.
trie
{Object
|goog.structs.Trie
}