Trie

Trie

Trie (prefix tree) representation

Constructor

new Trie()

Example
const trie = new Collections.Trie();
// FOR ALL EXAMPLES BELOW. ASSUME trie IS CLEARED BEFORE EACH EXAMPLE

Methods

addWord(word) → {undefined}

Converts the given data to string and adds it to trie
Parameters:
Name Type Description
word * The word to add into trie
Returns:
Type
undefined

containsWord(data) → {boolean}

Reports whether the trie contains the given word
Parameters:
Name Type Description
data * The data to search for
Returns:
True if the trie contains @param data.toString() or false if it does not
Type
boolean

prefixAll(prefix, prefix) → {Array}

Gives all of the words in the trie with the given prefix
Example
trie.addWord("apple");
trie.addWord.("app");
trie.prefixAll("app"); // returns only apple because app is equal to prefix
Parameters:
Name Type Description
prefix * The prefix to search for
prefix
Returns:
An array with all the words that are prefixed by
Type
Array