atomic-fns
Version:
Like Lodash, but for ESNext and with types. Stop shipping code built for browsers from 2015.
43 lines (42 loc) • 1.4 kB
TypeScript
import { Collection } from './abc.js';
/**
* A Trie is a tree for efficient storing and retrieval of strings such as words in a dictionary. They are useful for checking all the strings that have a common prefix.
* Insertions, lookups and removals in `O(s)` where `s` is the search term.
* @see {@link https://en.wikipedia.org/wiki/Trie Trie}
*/
export declare class Trie extends Collection {
private root;
private count;
constructor(words?: string[]);
/**
* Adds the given string to the tree.
* @param word A string
*/
add(word: string): this;
/**
* Removes the given string from the tree.
* @param word The string to remove
* @returns {boolean} Returns `true` if the string was found and removed.
*/
remove(word: string): boolean;
private findNode;
/**
* Generates all results that start with the given string.
* @param word A prefix string
* @param {number} [limit=20] The number of results to return.
*/
matches: (word: string, limit?: number) => Generator<any, void, any>;
/**
* Returns `true` if the given string is found in the tree.
* @param {string} word
*/
contains(word: string): boolean;
/**
* Removes all strings from the tree.
*/
clear(): void;
/**
* Returns the total number of strings in the tree.
*/
get size(): number;
}