Options
All
  • Public
  • Public/Protected
  • All
Menu

A data structure for quickly retrieving objects by a string prefix. Note that this works well for languages with alphabets (latin, cyrillic, korean, etc.), but may need more nuanced handling for languages that compose characters and letters.

Hierarchy

  • WordTree

Index

Constructors

Accessors

Methods

  • Insert an entry into the tree.

    Parameters

    • string: string

      The string key for the entry.

    • entry: WordTreeEntry

      The entry to store.

    Returns WordTreeNode

    The node the entry was added to.

  • lookup(prefix: string, [options]?: { limit: number }): WordTreeEntry[]
  • Return entries that match the given string prefix.

    Parameters

    • prefix: string

      The prefix.

    • [options]: { limit: number } = {}

      Additional options to configure behaviour.

      • limit: number

    Returns WordTreeEntry[]

    A number of entries that have the given prefix.

  • Returns the node at the given prefix.

    Parameters

    • prefix: string

      The prefix.

    Returns WordTreeNode

  • Perform a breadth-first search starting from the given node and retrieving any entries along the way, until we reach the limit.

    Parameters

    • node: WordTreeNode

      The starting node.

    • entries: WordTreeEntry[]

      The accumulated entries.

    • queue: WordTreeNode[]

      The working queue of nodes to search.

    • [options]: { limit: number } = {}

      Additional options for the search.

      • limit: number

    Returns void

Properties

#root: WordTreeNode = ...

The tree's root.