Class AbstractTrieAbstract

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.

class MyTrie extends AbstractTrie {
// Implement abstract methods
}

Hierarchy (View Summary)

Constructors

Accessors

Methods

  • Makes the AbstractTrie iterable.

    Parameters

    • reversed: boolean

      If true, words are yielded in reverse insertion order.

    Returns Generator<string, void, void>

    An iterator for the trie's entries.

  • Adds a word to the trie. If the word already exists, it will not create duplicates and the original insertion order is preserved.

    Parameters

    • word: string

      The word to add.

    Returns void

  • Removes a word from the trie.

    Parameters

    • word: string

      The word to remove.

    Returns boolean

    true if the word was found and removed, false if not found.

  • Returns an iterator for the words in the trie.

    Parameters

    • reversed: boolean

      If true, words are yielded in reverse insertion order.

    Returns Generator<string, void, void>

    An iterator of the trie's entries.

  • Finds all words that start with the given prefix.

    Parameters

    • prefix: string

      The prefix to search for.

    Returns string[]

    An array of matching words.

  • Executes a callback function for each word in the trie.

    Parameters

    • callback: (word: string, trie: AbstractTrie) => void
        • (word: string, trie: AbstractTrie): void
        • Parameters

          • word: string

            The word of the current entry.

          • trie: AbstractTrie

            The trie instance being traversed.

          Returns void

    • OptionalthisArg: any

      Optional value to use as this in the callback.

    Returns void

  • Checks if a word exists in the trie.

    Parameters

    • word: string

      The word to check.

    Returns boolean

    true if the exact word exists, false otherwise.