UNPKG

compact-prefix-tree

Version:

A serializable compact prefix trie

43 lines (42 loc) 957 B
export interface Trie { [prefix: string]: Trie | null; } export declare class CompactPrefixTree { words: Set<string>; private T; /** * Create a CompactPrefixTree from the given list of words */ constructor(words?: string[]); /** * Add a word to the trie */ add(word: string): this; /** * Get the longest prefix of word */ prefix(word: string): { prefix: string; isProper: boolean; }; /** * Get all entries from the trie */ readonly items: Set<string>; } export default CompactPrefixTree; /** * Add a word to Trie */ export declare function add(word: string, T: Trie | null): void; /** * Get longest prefix of given word in Trie */ export declare function getPrefix(word: string, T: Trie | null): { prefix: string; isProper: boolean; }; /** * Get all entries from the trie */ export declare function getWordsFromTrie(T: Trie): Set<string>;