Class AbstractTrieMap<V>Abstract

Abstract base class for implementing trie-based map data structures. Provides the core interface for associating values with string keys efficiently.

A trie-map combines the prefix-matching capabilities of tries with key-value storage, similar to how a Map associates values with keys, but optimized for string-based keys.

class MyTrieMap extends AbstractTrieMap {
// Implement abstract methods
}

Type Parameters

  • V extends unknown = unknown

    The type of values stored in the trie-map.

Hierarchy (View Summary)

Constructors

Accessors

Methods

  • Makes the AbstractTrieMap iterable.

    Parameters

    • reversed: boolean

      If true, entries are yielded in reverse insertion order.

    Returns Generator<[string, V], void, void>

    An iterator for the trie-map's entries.

  • Removes an entry from the trie-map.

    Parameters

    • word: string

      The key of the entry to remove.

    Returns boolean

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

  • Returns an iterator for the entries in the trie-map.

    Parameters

    • reversed: boolean

      If true, entries are yielded in reverse order.

    Returns Generator<[string, V], void, void>

    An iterator of the trie's entries.

  • Finds all entries whose keys start with the given prefix.

    Parameters

    • prefix: string

      The prefix to search for.

    Returns [string, V][]

    An array of matching [word, value] pairs.

  • Executes a callback function for each entry in the trie-map.

    Parameters

    • callback: (value: V, word: string, trieMap: AbstractTrieMap<V>) => void
        • (value: V, word: string, trieMap: AbstractTrieMap<V>): void
        • Parameters

          • value: V

            The value of the current entry.

          • word: string

            The word of the current entry.

          • trieMap: AbstractTrieMap<V>

            The trie-map instance being traversed.

          Returns void

    • OptionalthisArg: any

      Optional value to use as this in the callback.

    Returns void

  • Retrieves the value associated with a given key.

    Parameters

    • word: string

      The key to look up.

    Returns undefined | V

    The associated value if found, undefined otherwise.

  • Checks if an entry with the specified key exists in the trie-map.

    Parameters

    • word: string

      The key to check.

    Returns boolean

    true if an entry with the key exists, false otherwise.

  • Returns an iterator for the keys of the entries in the trie-map.

    Parameters

    • reversed: boolean

      If true, keys are yielded in reverse order.

    Returns Generator<string, void, void>

    An iterator of the trie-map's entries keys.

  • Adds or updates an entry in the trie-map.

    Parameters

    • word: string

      The key for the entry.

    • value: V

      The value to associate with the key.

    Returns void

  • Returns an iterator for the values of the entries in the trie-map.

    Parameters

    • reversed: boolean

      If true, values are yielded in reverse order.

    Returns Generator<V, void, void>

    An iterator of the trie-map's entries values.