@linkdotnet/stringoperations
Version:
Collection of string utilities. Edit-Distances, Search and Data structures. Offers for example trie, levenshtein distance.
42 lines (40 loc) • 1.51 kB
TypeScript
export declare class Trie {
private ignoreCase;
private children;
private isLeaf;
constructor(ignoreCase?: boolean);
/**
* Adds a word to the trie
* @param word Word to add to the trie
*/
addWord(word: string): void;
/**
* Check whether a word is contained in the trie
* @param word Word to check whether it exists in the trie
* @returns Returns true when the word is contained, otherwise false
*/
contains(word: string): boolean;
/**
* Determines whether this trie starts with the specified character
* @param text Character to compare
* @returns True, when the text matches the beginning of the trie, otherwise false
*/
startsWith(text: string): boolean;
/**
* Returns all words in the trie which starts with the given prefix
* @param prefix Starting sequence which all returned words have to match
* @returns All words in the trie which start with the given prefix
*/
getWordsWithPrefix(prefix: string): string[];
/**
* Deletes the key out of the trie. When multiple words matches this key all of them get deleted
* @param key Word to delete
* @remarks If trie contains out of 'Hello', 'Helsinki' and delete('Hel') is called, the trie is empty
*/
delete(key: string): void;
private createOrGetNode;
private findNode;
private stringToCharArray;
private collect;
private static deleteInternal;
}