Abstract
Abstract
sizeGets the number of words stored in the trie.
The total count of words.
Abstract
[iterator]Makes the AbstractTrie
iterable.
If true
, words are yielded in reverse insertion order.
An iterator for the trie's entries.
Abstract
addAdds a word to the trie. If the word already exists, it will not create duplicates and the original insertion order is preserved.
The word to add.
Abstract
clearRemoves all words from the trie, resetting it to an empty state.
Abstract
deleteRemoves a word from the trie.
The word to remove.
true
if the word was found and removed, false
if not found.
Abstract
entriesReturns an iterator for the words in the trie.
If true
, words are yielded in reverse insertion order.
An iterator of the trie's entries.
Abstract
findFinds all words that start with the given prefix.
The prefix to search for.
An array of matching words.
Abstract
forExecutes a callback function for each word in the trie.
The word of the current entry.
The trie instance being traversed.
Optional
thisArg: anyAbstract
hasChecks if a word exists in the trie.
The word to check.
true
if the exact word exists, false
otherwise.
Abstract base class for implementing trie (prefix tree) data structures. Provides the core interface for storing and retrieving strings efficiently.
A trie is a tree-like data structure that enables fast string operations by storing characters as nodes, where all descendants share a common prefix.
Example