UNPKG

@figliolia/data-structures

Version:

Efficient data structures for every day programming

49 lines (48 loc) 1.19 kB
/** * Trie * * A graph-like data structure for optimized search over multiple * strings * * ```typescript * import { Trie } from "@figliolia/data-structures"; * * const dictionary = new Trie(); * dictionary.add("hello"); * dictionary.add("goodbye"); * dictionary.add("helpful"); * dictionary.search("hello"); // true * dictionary.search("help", false); // true * ``` */ export declare class Trie { value: string; isWord: boolean; dictionary: Record<string, Trie>; constructor(value: string); /** * Add * * Adds a word to the current Trie */ add(value: string, root?: Trie): void; /** * Search * * Searches for a word in the current Trie. Specifying `Trie.search(word, false)` allows * you to search for prefixes within multiple words in the Trie */ search(value: string, isWord?: boolean, root?: Trie): boolean; /** * Has Adjacent * * Returns true a if the provided character proceeds the current Trie */ hasAdjacent(value: string): boolean; /** * Get * * Returns a reference to a Trie with the provided character */ get(value: string): Trie; }