Trie
An implementation of a Trie
The Trie can either be created string by string or from an array of strings.
Example
import { Trie } from "trie-structure";
const trie = new Trie();
const strings = ["he", "hello", "helios", "woof", "dog", "doom"];
trie.addMany(strings);
const allWords = trie.getAllWords();
const helPrefixedWords = trie.findWords("he");
Usage
public methods:
class Trie {
public add(word: string): void;
public addMany(words: string[]): void;
public remove(word: string): boolean;
public findWords(prefix: string): string[];
public size(): number;
public getAllWords(): string[];
public contains(word: string): boolean;
public findNode(prefix: string): TrieNode | undefined;
}
The items in the Trie
are stored as TrieNodes
these should not need to be directly referenced
class TrieNode {
public isLeaf: boolean;
public readonly children: Map<string, TrieNode>;
public constructor(public readonly char: string) {}
}