Foundry Virtual Tabletop - API Documentation - Version 14
    Preparing search index...

    Class WordTree

    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 (View Summary)

    Index

    Accessors

    • get leaves(): symbol

      The key symbol that stores the leaves of any given node.

      Returns symbol

    Methods

    • Insert an entry into the tree.

      Parameters

      • string: string

        The string key for the entry.

      • entry: WordTreeEntry

        The entry to store.

      Returns any

      The node the entry was added to.

    • Return entries that match the given string prefix.

      Parameters

      • prefix: string

        The prefix.

      • Optionaloptions: { filterEntries?: StringTreeEntryFilter; limit?: number } = {}

        Additional options to configure behaviour.

        • OptionalfilterEntries?: StringTreeEntryFilter

          A filter function to apply to each candidate entry.

        • Optionallimit?: number

          The maximum number of items to retrieve. It is important to set this value as very short prefixes will naturally match large numbers of entries.

      Returns WordTreeEntry[]

      A number of entries that have the given prefix.

    • Returns the node at the given prefix.

      Parameters

      • prefix: string

        The prefix.

      Returns any

    • Protected

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

      Parameters

      • node: any

        The starting node.

      • entries: any[]

        The accumulated entries.

      • queue: any[]

        The working queue of nodes to search.

      • Optionaloptions: { filterEntries?: StringTreeEntryFilter; limit?: number } = {}
        • OptionalfilterEntries?: StringTreeEntryFilter

          A filter function to apply to each candidate entry.

        • Optionallimit?: number

          The maximum number of entries to retrieve before stopping.

      Returns void