Type Parameters

  • T

Hierarchy (view full)

Constructors

Query

Modify

Hierarchy / Ancestors

Hierarchy / Children

Hierarchy / Descendents

Hierarchy / Leaves

Hierarchy / Parent

Hierarchy / Root

Hierarchy / Siblings

Properties

Traversal / Deep

Traversal / Flat Path

Traversal / Path

Traversal / Wide

Utility

Constructors

Query

  • Checks if the tree contains a node with the given value.

    Parameters

    • value: T

      The value to check.

    Returns boolean

    True if a node with the given value exists in the tree; otherwise, false.

  • Calculates the depth of the node with the given key in the tree. The depth is the number of ancestors a node has.

    Parameters

    • key: string

      The key of the node to calculate the depth for.

    Returns number

    The depth of the node.

  • Gives access to the Tree Entry directly for reference reasons; Warning: cannot be modified, lest something get messed up with three internal state.

    Parameters

    • key: string

      The key of the node to get the entry of.

    Returns undefined | ReadonlyTreeEntry<T>

    the tree entry

  • returns the index of a given key using the searcher predicate, or -1 if not found

    Parameters

    Returns number

  • Returns the key of the first node that satisfies the given discriminator function.

    Parameters

    Returns undefined | string

    The key of the first node that satisfies the discriminator function, or undefined if not found.

  • Gets the value associated with the node of the given key.

    Parameters

    • key: string

      The key of the node to get the value of.

    Returns undefined | T

    The value associated with the node.

  • Checks if the tree contains the specified key.

    Parameters

    • key: string

      The key to check.

    Returns boolean

    True if the key exists in the tree; otherwise, false.

  • returns the index of a given key, or -1 if the key is not present

    Parameters

    • key: string

    Returns number

  • Checks if the node with the given key is a leaf node (has no children).

    Parameters

    • key: string

      The key of the node to check.

    Returns boolean

    True if the node is a leaf; otherwise, false.

  • Checks if the node with the given key is a root of the tree.

    Parameters

    • key: string

      The key of the node to check.

    Returns boolean

    True if the node is the root; otherwise, false.

  • returns the key at a given index or undefined if index is out of bounds.

    Parameters

    • index: number

    Returns undefined | string

  • Returns the key associated with the given value in the tree.

    Parameters

    • value: T

      The value to find the key for.

    Returns undefined | string

    The key associated with the value, or undefined if not found.

  • Gives access to the sorted Tree keys directly for reference reasons; Warning: cannot be modified, lest something get messed up with three internal state.

    Returns readonly string[]

    the tree keys, in order

  • How many entries are in the tree

    Returns number

    The number of entries.

  • Checks if any node in the tree satisfies the given discriminator function.

    Parameters

    Returns boolean

    True if any node satisfies the discriminator function; otherwise, false.

  • How many subtrees are in the tree

    Returns number

    The number of subtrees

  • returns the value at a given index or undefined if index is out of bounds.

    Parameters

    • index: number

    Returns undefined | T

Modify

  • Adds a new node to the tree with the given key, parent, and value. If a node with the given key already exists in the tree, this method does nothing.

    Parameters

    • key: string

      The key of the new node to add.

    • parent: null | string

      The key of the parent node for the new node. Use null if the node is a root node.

    • value: T

      The value associated with the new node.

    Returns void

  • Adds a new node to the tree with the given key, parent, and value. If a node with the given key already exists in the tree, this method does nothing.

    Parameters

    • key: string

      The key of the new node to add.

    • parent: string

      The key of the parent node for the new node.

    • value: T

      The value associated with the new node.

    Returns void

  • Adds a new root to the tree with the given key, and value. If a node with the given key already exists in the tree, this method does nothing.

    Parameters

    • key: string

      The key of the new node to add.

    • value: T

      The value associated with the new node.

    Returns void

  • Condenses the tree by merging nodes with one child with that one child using the provided merger function. The merger function takes two adjacent nodes 'parent' and 'child', and if applicable, returns a new merged node 'r'. If the merger function returns void, no merge is performed between 'parent' and 'child'.

    Parameters

    • merger: ((a, b) => void | {
          key: string;
          value: T;
      })

      The function to merge adjacent nodes with single children.

        • (a, b): void | {
              key: string;
              value: T;
          }
        • Parameters

          Returns void | {
              key: string;
              value: T;
          }

    Returns void

  • Detaches a part of a tree at the given key, and makes that node the root of a new subtree within this tree.

    Parameters

    • key: null | string

      The key of the node to be detatched - the new root of it's own subtree.

    Returns void

  • Adds a node to a given parent if it doesn't exist, otherweise will update an existing node and move the node to be a child of the designated parent

    Parameters

    • key: string

      The key of the node to update.

    • parent: null | string

      If the node is to be inserted, it will become a child of this node, otherwise it is ignored

    • value: T

      The new value to set for the node.

    Returns void

  • Adds a node to a given parent if it doesn't exist, otherweise will update an existing node and move the node to be a child of the designated parent

    Parameters

    • key: string

      The key of the node to update.

    • parent: null | string

      If the node is to be inserted, it will become a child of this node, otherwise it is ignored

    • updater: Updater<undefined | T, T>

      The callback that will take in the previous value and return the new value.

    Returns void

  • Grafts a sapling tree into the current tree, connecting it to a specific node. The sapling tree will be added as a subtree rooted at the graft point in the current tree.

    Parameters

    • sapling: Tree<T>

      The sapling tree to graft into the current tree.

    • saplingRoot: string

      The key of the root node of the sapling tree to graft.

    • graftPoint: string

      The key of the node in the current tree where the sapling will be grafted.

    Returns void

  • Will move a node, and by extension its children, to under the designated new parent If the node does not exist, this method does nothing.

    Parameters

    • key: string

      The key of the node to update.

    • parent: null | string

      The new parent node.

    Returns void

  • Removes the node with the given key from the tree. that node's childrens become detached within the original tree as additional roots.

    Parameters

    • key: string

      The key of the node to be removed from the tree.

    Returns undefined | T

    The value of the node that was removed, or undefined if the node does not exist.

  • Given a list of nodes, allocate them into the forest.

    Type Parameters

    • F

    Parameters

    • list: Iterable<F>
    • allocator: ((data) => void | IterableOr<{
          key: string;
          parent: null | string;
          value: T;
      }>)
        • (data): void | IterableOr<{
              key: string;
              parent: null | string;
              value: T;
          }>
        • Parameters

          • data: F

          Returns void | IterableOr<{
              key: string;
              parent: null | string;
              value: T;
          }>

    Returns void

  • Given a list of nodes, allocate them into the forest, but asynchronously

    Type Parameters

    • F

    Parameters

    • list: Iterable<F>
    • allocator: ((data) => Promise<void | IterableOr<{
          key: string;
          parent: null | string;
          value: T;
      }>>)
        • (data): Promise<void | IterableOr<{
              key: string;
              parent: null | string;
              value: T;
          }>>
        • Parameters

          • data: F

          Returns Promise<void | IterableOr<{
              key: string;
              parent: null | string;
              value: T;
          }>>

    Returns Promise<void>

  • Creates a new tree by pruning the subtree rooted at the node with the given key from the original tree. The pruned tree includes the node and its descendants as a new tree instance. Items are removed from the original tree.

    Parameters

    • key: string

      The key of the node that serves as the root of the subtree to be pruned.

    Returns SortedTree<T>

    A new Tree instance representing the pruned subtree.

  • Sorts the tree in place.

    Parameters

    • Optional comparator: Comparator<[string, T]>

      override the default comparator with this comparator

    Returns void

  • Removes the node with the given key from the tree and splices its children into its parent's children list.

    Parameters

    • key: string

      The key of the node to be spliced.

    Returns undefined | T

    The value of the node that was spliced, or undefined if the node does not exist.

  • Adds multiple child nodes to an existing node in the tree with the given key. If the node does not exist, this method does nothing.

    Parameters

    • key: string

      The key of the node to which children should be added.

    • generation: Iterable<[string, T]> | {
          [key: string]: T;
      } | Iterable<{
          key: string;
          value: T;
      }>

      An iterable of [string, T] pairs, or an object with key-value pairs, or an iterable of { key: string, value: T } objects.

    Returns void

  • Removes a node so long as it has no children, otherwise, does nothing.

    Parameters

    • key: string

      The key of the node to be removed.

    Returns undefined | T

    The value removed or undefined if it was not removed or the node was not present.

  • Truncates the subtree rooted at the node with the given key from the tree and returns a key-value collection of those removed. The original tree will no longer include the node and its descendants.

    Parameters

    • key: string

      The key of the node that serves as the root of the subtree to be truncated.

    Returns undefined | {
        [key: string]: T;
    }

    An object representing the truncated subtree, where the keys are the keys of the nodes, and the values are the values associated with each node (or undefined if the node was not present)

  • Updates the value of an existing node in the tree with the given key. If the node does not exist, this method does nothing.

    Parameters

    • key: string

      The key of the node to update.

    • value: T | Updater<T>

      The new value to set for the node.

    Returns void

  • Updates the value of an existing node in the tree with the given key. If the node does not exist, this method does nothing.

    Parameters

    • key: string

      The key of the node to update.

    • updater: Updater<T>

      The callback that will take in the previous value and return the new value

    Returns void

  • Adds a node to a given parent if it doesn't exist, otherweise will update an existing node and ignore parent

    Parameters

    • key: string

      The key of the node to update.

    • parent: null | string

      If the node is to be inserted, it will become a child of this node, otherwise it is ignored

    • value: T

      The new value to set for the node.

    Returns void

  • Adds a node to a given parent if it doesn't exist, otherweise will update an existing node and ignore parent

    Parameters

    • key: string

      The key of the node to update.

    • parent: null | string

      If the node is to be inserted, it will become a child of this node, otherwise it is ignored

    • updater: Updater<undefined | T, T>

      The callback that will take in the previous value and return the new value.

    Returns void

Hierarchy / Ancestors

  • Returns an object representing the ancestors nodes of the given node, with keys as node keys and values as node values, from closest to root.

    Parameters

    • key: string

      The key of the node for which to find the ancestors.

    Returns {
        [key: string]: T;
    }

    An array of values representing the ancestor nodes.

    • [key: string]: T
  • Returns an array of keys representing the ancestor nodes of the node with the given key, from closest to root.

    Parameters

    • key: string

      The key of the node for which to find the ancestors.

    Returns string[]

    An array of keys representing the ancestor nodes.

  • Returns an array of objects representing the ancestor keys and nodes of the node with the given key, from closest to root.

    Parameters

    • key: string

      The key of the node for which to find the ancestors.

    Returns {
        key: string;
        value: T;
    }[]

    An array of values representing the ancestor nodes.

  • Returns an array of tuples representing the ancestor keys and nodes of the node with the given key, from closest to root.

    Parameters

    • key: string

      The key of the node for which to find the ancestors.

    Returns [string, T][]

    An array of values representing the ancestor nodes.

  • Returns an array of values representing the ancestor nodes of the node with the given key, from closest to root.

    Parameters

    • key: string

      The key of the node for which to find the ancestors.

    Returns T[]

    An array of values representing the ancestor nodes.

  • Returns an array of values representing the ancestor nodes of the node with the given key, from closest to root.

    Parameters

    • key: string

      The key of the node for which to find the ancestors.

    Returns T[]

    An array of values representing the ancestor nodes.

    Alias

    ancestorValues

  • Maps a function to each ancestors of the target node, from closest to root.

    Type Parameters

    • R

      The type of the result.

    Parameters

    • mapper: KeyedMapper<T, string, R>

      The mapping function to be applied. It takes three arguments:

      • value (type T): The value associated with the current node being processed.
      • key (string): The key of the current node being processed.
      • i (number): The index of the current node in the ancestor line.
    • key: string

      the node from which to iterate the descendents from

    Returns R[]

    • An array containing the results of applying the mapper to all nodes.
  • Maps a function to each ancestors of the target node, from root to closest.

    Type Parameters

    • R

      The type of the result.

    Parameters

    • mapper: KeyedMapper<T, string, R>

      The mapping function to be applied. It takes three arguments:

      • value (type T): The value associated with the current node being processed.
      • key (string): The key of the current node being processed.
      • i (number): The index of the current node in the ancestor line.
    • key: string

      the node from which to iterate the descendents from

    Returns R[]

    • An array containing the results of applying the mapper to all nodes.
  • Applies a reducer function to each ancestors in the tree from the given node, from closest to root

    Type Parameters

    • R = void

    Parameters

    • reducer: KeyedReducer<T, string, R>

      The reducer function to be applied. It takes four arguments:

      • key (string): The key of the current node being processed.
      • value (type T): The value associated with the current node being processed.
      • i (number): The index of the current node in the ancestor list traversal.
      • accumulation (type R): The accumulated result from previous reductions.
    • start: R

      The initial value of the accumulator for the reduction.

    • key: string

      the node from which to traverse upward from

    Returns R

    The final accumulated result after applying the reducer to all nodes.

  • Applies a reducer function to each ancestors in the tree from the given node, from root to closest

    Type Parameters

    • R = void

    Parameters

    • reducer: KeyedReducer<T, string, R>

      The reducer function to be applied. It takes four arguments:

      • key (string): The key of the current node being processed.
      • value (type T): The value associated with the current node being processed.
      • i (number): The index of the current node in the ancestor list traversal.
      • accumulation (type R): The accumulated result from previous reductions.
    • start: R

      The initial value of the accumulator for the reduction.

    • key: string

      the node from which to traverse upward from

    Returns R

    The final accumulated result after applying the reducer to all nodes.

Hierarchy / Children

  • Returns an array of values representing the child nodes of the node with the given key.

    Parameters

    • key: string

      The key of the node for which to find the children.

    Returns T[]

    An array of values representing the child nodes.

    Alias

    childrenValues

  • Returns an object representing the children nodes of the given node, with keys as node keys and values as node values.

    Parameters

    • key: string

      The key of the node for which to find the children.

    Returns {
        [key: string]: T;
    }

    An array of values representing the child nodes.

    • [key: string]: T
  • Returns an array of keys representing the child nodes of the node with the given key.

    Parameters

    • key: string

      The key of the node for which to find the children.

    Returns string[]

    An array of keys representing the child nodes.

  • Returns an array of objects representing the children keys and nodes of the node with the given key.

    Parameters

    • key: string

      The key of the node for which to find the children.

    Returns {
        key: string;
        value: T;
    }[]

    An array of values representing the children nodes.

  • Returns an array of tuples representing the children keys of the given node

    Parameters

    • key: string

      The key of the node for which to find the children.

    Returns [string, T][]

    An array of values representing the children nodes.

  • Returns an array of values representing the child nodes of the node with the given key.

    Parameters

    • key: string

      The key of the node for which to find the children.

    Returns T[]

    An array of values representing the child nodes.

  • Maps a function to each child of the target node.

    Type Parameters

    • R

      The type of the result.

    Parameters

    • mapper: KeyedMapper<T, string, R>

      The mapping function to be applied. It takes three arguments:

      • value (type T): The value associated with the current node being processed.
      • key (string): The key of the current node being processed.
      • i (number): The index of the current node in the child.
    • key: string

      the node from which to get children from

    Returns R[]

    • An array containing the results of applying the mapper to all nodes.
  • Applies a reducer function to each child of the given node

    Type Parameters

    • R = void

    Parameters

    • reducer: KeyedReducer<T, string, R>

      The reducer function to be applied. It takes four arguments:

      • key (string): The key of the current node being processed.
      • value (type T): The value associated with the current node being processed.
      • i (number): The index of the current node in the child.
      • accumulation (type R): The accumulated result from previous reductions.
    • start: R

      The initial value of the accumulator for the reduction.

    • key: string

      the node from which to get children from

    Returns R

    The final accumulated result after applying the reducer to all nodes.

Hierarchy / Descendents

  • Returns an object representing the descendent nodes of the given node, with keys as node keys and values as node values in depth-first order.

    Parameters

    • key: string

      The key of the node for which to find the descendents.

    Returns {
        [key: string]: T;
    }

    An array of values representing the descendents nodes.

    • [key: string]: T
  • Returns an array of keys representing the descendant nodes of the node with the given key in depth-first order.

    Parameters

    • key: string

      The key of the node for which to find the descendants.

    Returns string[]

    An array of keys representing the descendant nodes.

  • Returns an array of objects representing the descendent keys and nodes of the node with the given key in depth-first order.

    Parameters

    • key: string

      The key of the node for which to find the descendents.

    Returns {
        key: string;
        value: T;
    }[]

    An array of values representing the descendent nodes.

  • Returns an array of tuples representing the descemdemt keys and nodes of the node with the given key in depth-first order.

    Parameters

    • key: string

      The key of the node for which to find the descendents.

    Returns [string, T][]

    An array of values representing the descendent nodes.

  • Returns an array of values representing the descendant nodes of the node with the given key in depth-first order.

    Parameters

    • key: string

      The key of the node for which to find the descendants.

    Returns T[]

    An array of values representing the descendant nodes.

  • Returns an array of values representing the descendant nodes of the node with the given key in depth-first order.

    Parameters

    • key: string

      The key of the node for which to find the descendants.

    Returns T[]

    An array of values representing the descendant nodes.

    Alias

    deepDescendentValues

  • Maps a function to each descendent of the target node in a depth-order traversal.

    Type Parameters

    • R

      The type of the result.

    Parameters

    • mapper: KeyedMapper<T, string, R>

      The mapping function to be applied. It takes three arguments:

      • value (type T): The value associated with the current node being processed.
      • key (string): The key of the current node being processed.
      • i (number): The index of the current node in the depth-order traversal.
    • key: string

      the node from which to iterate the descendents from

    Returns R[]

    • An array containing the results of applying the mapper to all nodes.
  • Maps a function to each descendent of the target node in a wide-order traversal.

    Type Parameters

    • R

      The type of the result.

    Parameters

    • mapper: KeyedMapper<T, string, R>

      The mapping function to be applied. It takes three arguments:

      • value (type T): The value associated with the current node being processed.
      • key (string): The key of the current node being processed.
      • i (number): The index of the current node in the wide-order traversal.
    • key: string

      the node from which to iterate the descendents from

    Returns R[]

    • An array containing the results of applying the mapper to all nodes.
  • Applies a reducer function to each descendent in the tree in a depth-first traversal.

    Type Parameters

    • R = void

    Parameters

    • reducer: KeyedReducer<T, string, R>

      The reducer function to be applied. It takes four arguments:

      • key (string): The key of the current node being processed.
      • value (type T): The value associated with the current node being processed.
      • i (number): The index of the current node in the depth-first traversal.
      • accumulation (type R): The accumulated result from previous reductions.
    • start: R

      The initial value of the accumulator for the reduction.

    • key: string

      the node from which to iterate the descendents from

    Returns R

    The final accumulated result after applying the reducer to all nodes.

  • Applies a reducer function to each descendent in the tree in a width-first traversal.

    Type Parameters

    • R = void

    Parameters

    • reducer: KeyedReducer<T, string, R>

      The reducer function to be applied. It takes four arguments:

      • key (string): The key of the current node being processed.
      • value (type T): The value associated with the current node being processed.
      • i (number): The index of the current node in the width-first traversal.
      • accumulation (type R): The accumulated result from previous reductions.
    • start: R

      The initial value of the accumulator for the reduction.

    • key: string

      the node from which to iterate the descendents from

    Returns R

    The final accumulated result after applying the reducer to all nodes.

  • Returns an object representing the descendent nodes of the given node, with keys as node keys and values as node values in width-first order.

    Parameters

    • key: string

      The key of the node for which to find the descendents.

    Returns {
        [key: string]: T;
    }

    An array of values representing the descendents nodes.

    • [key: string]: T
  • Returns an array of keys representing the descendant nodes of the node with the given key.

    Parameters

    • key: string

      The key of the node for which to find the descendants.

    Returns string[]

    An array of keys representing the descendant nodes.

  • Returns an array of objects representing the descendent keys and nodes of the node with the given key in width-first order.

    Parameters

    • key: string

      The key of the node for which to find the descendents.

    Returns {
        key: string;
        value: T;
    }[]

    An array of values representing the descendent nodes.

  • Returns an array of tuples representing the descemdemt keys and nodes of the node with the given key in width-first order.

    Parameters

    • key: string

      The key of the node for which to find the descendents.

    Returns [string, T][]

    An array of values representing the descendent nodes.

  • Returns an array of values representing the descendant nodes of the node with the given key.

    Parameters

    • key: string

      The key of the node for which to find the descendants.

    Returns T[]

    An array of values representing the descendant nodes.

  • Returns an array of values representing the descendant nodes of the node with the given key.

    Parameters

    • key: string

      The key of the node for which to find the descendants.

    Returns T[]

    An array of values representing the descendant nodes.

    Alias

    wideDescendentValues

Hierarchy / Leaves

  • Returns an object representing the leaf nodes of the tree, with keys as node keys and values as node values.

    Parameters

    • Optional origin: string | string[]

      where the traversal begins. If unspecified, will be all root nodes, thus traversal the whole forest.

    • Optional Rest ...moreOrigins: string[]

    Returns {
        [key: string]: T;
    }

    An object representing the leaf nodes.

    • [key: string]: T
  • Returns an array of keys representing the leaf nodes of the tree.

    Parameters

    • origin: string | string[] = ...
    • Rest ...moreOrigins: string[]

    Returns string[]

    An array of keys representing the leaf nodes.

  • Returns an array of objects object representing the leaf keys and value of the tree.

    Parameters

    • Optional origin: string | string[]

      where the traversal begins. If unspecified, will be all root nodes, thus traversal the whole forest.

    • Optional Rest ...moreOrigins: string[]

    Returns {
        key: string;
        value: T;
    }[]

    An object representing the leaf nodes.

  • Returns an array of key-value pairs representing the leaf nodes of the tree.

    Parameters

    • Optional origin: string | string[]

      where the traversal begins. If unspecified, will be all root nodes, thus traversal the whole forest.

    • Optional Rest ...moreOrigins: string[]

    Returns [string, T][]

    An array of key-value pairs representing the leaf nodes.

  • Returns an array of values representing the leaf nodes of the tree.

    Parameters

    • Optional origin: string | string[]

      where the traversal begins. If unspecified, will be all root nodes, thus traversal the whole forest.

    • Optional Rest ...moreOrigins: string[]

    Returns T[]

    An array of values representing the leaf nodes.

  • Returns an array of values representing the leaf nodes of the tree.

    Parameters

    • Optional origin: string | string[]

      where the traversal begins. If unspecified, will be all root nodes, thus traversal the whole forest.

    • Optional Rest ...moreOrigins: string[]

    Returns T[]

    An array of values representing the leaf nodes.

    Alias

    leafValues

  • Maps a function to each sibling of the target node.

    Type Parameters

    • R

      The type of the result.

    Parameters

    • mapper: KeyedMapper<T, string, R>

      The mapping function to be applied. It takes three arguments:

      • value (type T): The value associated with the current node being processed.
      • key (string): The key of the current node being processed.
      • i (number): The index of the current node in the sibling.
    • Optional origin: string | string[]

      where the traversal begins. If unspecified, will be all root nodes, thus traversal the whole forest.

    • Optional Rest ...moreOrigins: string[]

    Returns R[]

    • An array containing the results of applying the mapper to all nodes.
  • Applies a reducer function to each sibling of the given node

    Type Parameters

    • R = void

    Parameters

    • reducer: KeyedReducer<T, string, R>

      The reducer function to be applied. It takes four arguments:

      • key (string): The key of the current node being processed.
      • value (type T): The value associated with the current node being processed.
      • i (number): The index of the current node in the sibling.
      • accumulation (type R): The accumulated result from previous reductions.
    • start: R

      The initial value of the accumulator for the reduction.

    • Optional origin: string | string[]

      where the traversal begins. If unspecified, will be all root nodes, thus traversal the whole forest.

    • Optional Rest ...moreOrigins: string[]

    Returns R

    The final accumulated result after applying the reducer to all nodes.

Hierarchy / Parent

  • Returns the value of the parent node of the node with the given key.

    Parameters

    • key: string

      The key of the node for which to find the parent.

    Returns undefined | T

    The value of the parent node, or undefined if the node has no parent or the key does not exist.

    Alias

    parentValue

  • Returns the key of the parent node of the node with the given key.

    Parameters

    • key: string

      The key of the node for which to find the parent.

    Returns undefined | null | string

    The key of the parent node as a string, or null if the node has no parent, or undefined if the node was not in the key

  • Returns an objects representing the pareent key and node of the given node.

    Parameters

    • key: string

      The key of the node for which to find the parent.

    Returns {
        key: undefined | null | string;
        value: undefined | T;
    }

    An object representing the parent node.

    • key: undefined | null | string
    • value: undefined | T
  • Returns a tuples representing this nodes parent key and value.

    Parameters

    • key: string

      The key of the node for which to find the parent.

    Returns [undefined | null | string, undefined | T]

    A tuple consistent of the parent key and value, if applicable.

  • Returns the value of the parent node of the node with the given key.

    Parameters

    • key: string

      The key of the node for which to find the parent.

    Returns undefined | T

    The value of the parent node, or undefined if the node has no parent or the key does not exist.

Hierarchy / Root

  • Maps a function to each root of the tree.

    Type Parameters

    • R

      The type of the result.

    Parameters

    • mapper: KeyedMapper<T, string, R>

      The mapping function to be applied. It takes three arguments:

      • value (type T): The value associated with the current node being processed.
      • key (string): The key of the current node being processed.
      • i (number): The index of the current node in the root list.

    Returns R[]

    • An array containing the results of applying the mapper to all root nodes.
  • Applies a reducer function to each root of the tree

    Type Parameters

    • R = void

    Parameters

    • reducer: KeyedReducer<T, string, R>

      The reducer function to be applied. It takes four arguments:

      • key (string): The key of the current node being processed.
      • value (type T): The value associated with the current node being processed.
      • i (number): The index of the current node in the root list.
      • accumulation (type R): The accumulated result from previous reductions.
    • start: R

      The initial value of the accumulator for the reduction.

    Returns R

    The final accumulated result after applying the reducer to all root nodes.

  • Returns an object representing the root nodes of the tree, with keys as node keys and values as node values.

    Returns {
        [key: string]: T;
    }

    An object representing the root nodes.

    • [key: string]: T
  • Get the root key of the subtree that this key is in.

    Parameters

    • key: string

      The key to check.

    Returns undefined | string

    The root key in question.

  • Returns an array of keys representing the root nodes of the tree.

    Returns string[]

    An array of keys representing the root nodes.

  • Returns an array of objects representing the root keys and nodes of the tree.

    Returns {
        key: string;
        value: T;
    }[]

    An array of values representing the sibling nodes.

  • Returns an array of key-value pairs representing the root nodes of the tree.

    Returns [string, T][]

    An array of key-value pairs representing the root nodes.

  • Returns an array of values representing the root nodes of the tree.

    Returns T[]

    An array of values representing the root nodes.

  • Returns an array of values representing the root nodes of the tree.

    Returns T[]

    An array of values representing the root nodes.

    Alias

    rootValues

Hierarchy / Siblings

  • gives the index of a given key amongst it's siblings using a predicate

    Parameters

    Returns number

  • Maps a function to each sibling of the target node.

    Type Parameters

    • R

      The type of the result.

    Parameters

    • mapper: KeyedMapper<T, string, R>

      The mapping function to be applied. It takes three arguments:

      • value (type T): The value associated with the current node being processed.
      • key (string): The key of the current node being processed.
      • i (number): The index of the current node in the sibling.
    • key: string

      the node from which to get siblings from

    Returns R[]

    • An array containing the results of applying the mapper to all nodes.
  • Applies a reducer function to each sibling of the given node

    Type Parameters

    • R = void

    Parameters

    • reducer: KeyedReducer<T, string, R>

      The reducer function to be applied. It takes four arguments:

      • key (string): The key of the current node being processed.
      • value (type T): The value associated with the current node being processed.
      • i (number): The index of the current node in the sibling.
      • accumulation (type R): The accumulated result from previous reductions.
    • start: R

      The initial value of the accumulator for the reduction.

    • key: string

      the node from which to get siblings from

    Returns R

    The final accumulated result after applying the reducer to all nodes.

  • Returns an object representing the sibling nodes of the given node, with keys as node keys and values as node values.

    Parameters

    • key: string

      The key of the node for which to find the sibling.

    Returns {
        [key: string]: T;
    }

    An array of values representing the sibling nodes.

    • [key: string]: T
  • gives the index of a given key amongst it's siblings.

    Parameters

    • key: string

    Returns number

  • Returns an array of keys representing the sibling nodes of the node with the given key.

    Parameters

    • key: string

      The key of the node for which to find the siblings.

    Returns string[]

    An array of keys representing the sibling nodes.

  • Returns an array of objects representing the sibling keys and nodes of the node with the given key.

    Parameters

    • key: string

      The key of the node for which to find the sibling.

    Returns {
        key: string;
        value: T;
    }[]

    An array of values representing the sibling nodes.

  • Returns an array of tuples representing the sibling keys and nodes of the node with the given key.

    Parameters

    • key: string

      The key of the node for which to find the siblings.

    Returns [string, T][]

    An array of values representing the sibling nodes.

  • Returns an array of values representing the sibling nodes of the node with the given key.

    Parameters

    • key: string

      The key of the node for which to find the siblings.

    Returns T[]

    An array of values representing the sibling nodes.

  • Returns an array of values representing the sibling nodes of the node with the given key.

    Parameters

    • key: string

      The key of the node for which to find the siblings.

    Returns T[]

    An array of values representing the sibling nodes.

    Alias

    siblingValues

Properties

_comparator: Comparator<[string, T]>
_keys: string[]
_store: {
    [key: string]: TreeEntry<T>;
}

Type declaration

Traversal / Deep

  • Returns an array of keys representing all nodes in the tree in a depth-first traversal.

    Parameters

    • Optional origin: string | string[] = ...

      where the traversal begins. If unspecified, will be all root nodes, thus traversal the whole forest.

    • Optional Rest ...moreOrigins: string[]

    Returns string[]

    An array of keys representing all nodes in the tree in a depth-first traversal.

  • Returns an array of key-value pairs representing the nodes of the tree in a depth-first traversal.

    Parameters

    • Optional origin: string | string[]

      where the traversal begins. If unspecified, will be all root nodes, thus traversal the whole forest.

    • Optional Rest ...moreOrigins: string[]

    Returns {
        key: string;
        value: T;
    }[]

    An array of objects representing the key-value pairs of the nodes in depth-first. Each object in the array has two properties: key (string) representing the key of the node and value (type T) representing the value associated with the node.

  • Returns an array of key-value tuples representing all nodes in the tree in a depth-first traversal.

    Parameters

    • Optional origin: string | string[]

      where the traversal begins. If unspecified, will be all root nodes, thus traversal the whole forest.

    • Optional Rest ...moreOrigins: string[]

    Returns [string, T][]

    An array of key-value tuples representing all nodes in the tree in a depth-first traversal.

  • Returns an array of keys representing all nodes in the tree in a depth-first traversal.

    Parameters

    • Optional origin: string | string[]

      where the traversal begins. If unspecified, will be all root nodes, thus traversal the whole forest.

    • Optional Rest ...moreOrigins: string[]

    Returns string[]

    An array of keys representing all nodes in the tree in a depth-first traversal.

  • Returns an array of key-value pairs representing all nodes in the tree in a depth-first traversal.

    Parameters

    • Optional origin: string | string[]

      where the traversal begins. If unspecified, will be all root nodes, thus traversal the whole forest.

    • Optional Rest ...moreOrigins: string[]

    Returns {
        key: string;
        value: T;
    }[]

    An array of key-value pairs representing all nodes in the tree in a depth-first traversal.

  • Returns an array of key-value tuples representing all nodes in the tree in a depth-first traversal.

    Parameters

    • Optional origin: string | string[]

      where the traversal begins. If unspecified, will be all root nodes, thus traversal the whole forest.

    • Optional Rest ...moreOrigins: string[]

    Returns [string, T][]

    An array of key-value tuples representing all nodes in the tree in a depth-first traversal.

  • Returns an array of values associated with all nodes in the tree in a depth-first traversal.

    Parameters

    • Optional origin: string | string[]

      where the traversal begins. If unspecified, will be all root nodes, thus traversal the whole forest.

    • Optional Rest ...moreOrigins: string[]

    Returns T[]

    An array of values associated with all nodes in the tree in a depth-first traversal.

  • Returns an array of values associated with all nodes in the tree in a depth-first traversal.

    Parameters

    • Optional origin: string | string[]

      where the traversal begins. If unspecified, will be all root nodes, thus traversal the whole forest.

    • Optional Rest ...moreOrigins: string[]

    Returns T[]

    An array of values associated with all nodes in the tree in a depth-first traversal.

  • Maps a function to each node in the tree in a deep-order traversal.

    Type Parameters

    • R

      The type of the result.

    Parameters

    • mapper: KeyedMapper<T, string, R>

      The mapping function to be applied. It takes three arguments:

      • value (type T): The value associated with the current node being processed.
      • key (string): The key of the current node being processed.
      • i (number): The index of the current node in the deep-order traversal.
    • Optional origin: string | string[]

      where the traversal begins. If unspecified, will be all root nodes, thus traversal the whole forest.

    • Optional Rest ...moreOrigins: string[]

    Returns R[]

    • An array containing the results of applying the mapper to all nodes.
  • Maps a function to each node in the tree in a deep-order traversal, starting at leaves and going upwards towards roots.

    Type Parameters

    • R

      The type of the result.

    Parameters

    • mapper: KeyedMapper<T, string, R>

      The mapping function to be applied. It takes three arguments:

      • value (type T): The value associated with the current node being processed.
      • key (string): The key of the current node being processed.
      • i (number): The index of the current node in the deep-order traversal.
    • Optional origin: string | string[]

      where the traversal begins. If unspecified, will be all root nodes, thus traversal the whole forest.

    • Optional Rest ...moreOrigins: string[]

    Returns R[]

    • An array containing the results of applying the mapper to all nodes.
  • Applies a reducer function to each node in the tree in a depth-first traversal.

    Type Parameters

    • R = void

    Parameters

    • reducer: KeyedReducer<T, string, R>

      The reducer function to be applied. It takes four arguments:

      • key (string): The key of the current node being processed.
      • value (type T): The value associated with the current node being processed.
      • i (number): The index of the current node in the depth-first traversal.
      • accumulation (type R): The accumulated result from previous reductions.
    • start: R

      The initial value of the accumulator for the reduction.

    • Optional origin: string | string[]

      where the traversal begins. If unspecified, will be all root nodes, thus traversal the whole forest.

    • Optional Rest ...moreOrigins: string[]

    Returns R

    The final accumulated result after applying the reducer to all nodes.

  • Applies a reducer function to each node in the tree in a depth-first traversal.

    Type Parameters

    • R = void

    Parameters

    • reducer: KeyedReducer<T, string, R>

      The reducer function to be applied. It takes four arguments:

      • key (string): The key of the current node being processed.
      • value (type T): The value associated with the current node being processed.
      • i (number): The index of the current node in the depth-first traversal.
      • accumulation (type R): The accumulated result from previous reductions.
    • start: R

      The initial value of the accumulator for the reduction.

    • Optional origin: string | string[]

      where the traversal begins. If unspecified, will be all root nodes, thus traversal the whole forest.

    • Optional Rest ...moreOrigins: string[]

    Returns R

    The final accumulated result after applying the reducer to all nodes.

Traversal / Flat Path

  • Finds the keys representing the path from one node to another in the ordered flattened form of the tree.

    Parameters

    • from: string

      the key of the starting node

    • to: string

      the key of the ending node

    Returns string[]

    An array of keys representing the path.

  • returns the value of the next node relative to the given key in the flattened tree.

    Parameters

    • key: string

    Returns undefined | T

  • returns the key of the next node relative to the given key in the flattened tree.

    Parameters

    • key: string

    Returns undefined | string

  • returns the key of the next node that satisifes the selector relative to the given key in the flattened tree.

    Parameters

    Returns undefined | string

  • returns the value of the next node that satisifes the selector relative to the given key in the flattened tree.

    Parameters

    Returns undefined | T

  • returns the value of the previous node relative to the given key in the flattened tree.

    Parameters

    • key: string

    Returns undefined | T

  • returns the key of the previous node relative to the given key in the flattened tree.

    Parameters

    • key: string

    Returns undefined | string

  • returns the value of the previous node that satisifes the selector relative to the given key in the flattened tree.

    Parameters

    • key: string
    • selector: ((value, key) => boolean)
        • (value, key): boolean
        • Parameters

          • value: T
          • key: string

          Returns boolean

    Returns undefined | string

  • returns the value of the previous node that satisifes the selector relative to the given key in the flattened tree.

    Parameters

    • key: string
    • selector: ((value, key) => boolean)
        • (value, key): boolean
        • Parameters

          • value: T
          • key: string

          Returns boolean

    Returns undefined | T

Traversal / Path

  • Maps a function to each node in the a path starting at 'from' node and ending at 'to' node.

    Type Parameters

    • R = void

      The type of the result.

    Parameters

    • from: string

      The key of the starting node.

    • to: string

      The key of the ending node.

    • mapper: KeyedMapper<T, string, R>

      The mapping function to be applied. It takes three arguments:

      • value (type T): The value associated with the current node being processed.
      • key (string): The key of the current node being processed.
      • i (number): The index of the current node in the wide-order traversal.

    Returns R[]

    • An array containing the results of applying the mapper to all nodes.
  • Finds the keys representing the path from one node to another in the tree, if it exists. If no such path is viable, the array will be empty.

    Parameters

    • from: string

      The key of the starting node.

    • to: string

      The key of the ending node.

    Returns string[]

    An array of keys representing the path from the starting node to the ending node, if it exists. If no such path is viable, the array will be empty.

  • Returns an array of key-value representing the nodes along the path from one node to another in the tree, if it exists.

    Parameters

    • from: string

      The key of the starting node.

    • to: string

      The key of the ending node.

    Returns {
        key: string;
        value: T;
    }[]

    An array of objects representing the key-value pairs of the nodes in depth-first. Each object in the array has two properties: key (string) representing the key of the node and value (type T) representing the value associated with the node.

  • Finds the key-value tuples representing the nodes along the path from one node to another in the tree, if it exists.

    Parameters

    • from: string

      The key of the starting node.

    • to: string

      The key of the ending node.

    Returns [string, T][]

    An array of key-value tuples representing the nodes along the path from the starting node to the ending node, if it exists.

  • Finds the values associated with the nodes along the path from one node to another in the tree, if it exists.

    Parameters

    • from: string

      The key of the starting node.

    • to: string

      The key of the ending node.

    Returns T[]

    An array of values associated with the nodes along the path from the starting node to the ending node, if it exists.

  • Applies a reducer function to each node along the path from one node to another in the tree, if it exists.

    Type Parameters

    • R = void

    Parameters

    • from: string

      The key of the starting node.

    • to: string

      The key of the ending node.

    • reducer: KeyedReducer<T, string, R>

      The reducer function to be applied. It takes four arguments:

      • key (string): The key of the current node being processed.
      • value (type T): The value associated with the current node being processed.
      • i (number): The index of the current node along the path.
      • accumulation (type R): The accumulated result from previous reductions.
    • start: R

      The initial value of the accumulator for the reduction.

    Returns R

    The final accumulated result after applying the reducer to all nodes along the path.

Traversal / Wide

  • Maps a function to each node in the tree in a wide-order traversal, starting at leaves and going upwards towards roots.

    Type Parameters

    • R

      The type of the result.

    Parameters

    • mapper: KeyedMapper<T, string, R>

      The mapping function to be applied. It takes three arguments:

      • value (type T): The value associated with the current node being processed.
      • key (string): The key of the current node being processed.
      • i (number): The index of the current node in the wide-order traversal.
    • Optional origin: string | string[]

      where the traversal begins. If unspecified, will be all root nodes, thus traversal the whole forest.

    • Optional Rest ...moreOrigins: string[]

    Returns R[]

    • An array containing the results of applying the mapper to all nodes.
  • Maps a function to each node in the tree in a wide-order traversal.

    Type Parameters

    • R

      The type of the result.

    Parameters

    • mapper: KeyedMapper<T, string, R>

      The mapping function to be applied. It takes three arguments:

      • value (type T): The value associated with the current node being processed.
      • key (string): The key of the current node being processed.
      • i (number): The index of the current node in the wide-order traversal.
    • Optional origin: string | string[]

      where the traversal begins. If unspecified, will be all root nodes, thus traversal the whole forest.

    • Optional Rest ...moreOrigins: string[]

    Returns R[]

    • An array containing the results of applying the mapper to all nodes.
  • Applies a reducer function to each node in the tree in a width-first traversal.

    Type Parameters

    • R = void

    Parameters

    • reducer: KeyedReducer<T, string, R>

      The reducer function to be applied. It takes four arguments:

      • key (string): The key of the current node being processed.
      • value (type T): The value associated with the current node being processed.
      • i (number): The index of the current node in the width-first traversal.
      • accumulation (type R): The accumulated result from previous reductions.
    • start: R

      The initial value of the accumulator for the reduction.

    • Optional origin: string | string[]

      where the traversal begins. If unspecified, will be all root nodes, thus traversal the whole forest.

    • Optional Rest ...moreOrigins: string[]

    Returns R

    The final accumulated result after applying the reducer to all nodes.

  • Applies a reducer function to each node in the tree in a width-first traversal.

    Type Parameters

    • R = void

    Parameters

    • reducer: KeyedReducer<T, string, R>

      The reducer function to be applied. It takes four arguments:

      • key (string): The key of the current node being processed.
      • value (type T): The value associated with the current node being processed.
      • i (number): The index of the current node in the width-first traversal.
      • accumulation (type R): The accumulated result from previous reductions.
    • start: R

      The initial value of the accumulator for the reduction.

    • Optional origin: string | string[]

      where the traversal begins. If unspecified, will be all root nodes, thus traversal the whole forest.

    • Optional Rest ...moreOrigins: string[]

    Returns R

    The final accumulated result after applying the reducer to all nodes.

  • Returns an array of keys representing the nodes of the tree in a width-first traversal.

    Parameters

    • Optional origin: string | string[] = ...

      where the traversal begins. If unspecified, will be all root nodes, thus traversal the whole forest.

    • Optional Rest ...moreOrigins: string[]

    Returns string[]

    An array of keys representing the nodes in width-first.

  • Returns an array of key-value pairs representing the nodes of the tree in a width-first traversal.

    Parameters

    • Optional origin: string | string[]

      where the traversal begins. If unspecified, will be all root nodes, thus traversal the whole forest.

    • Optional Rest ...moreOrigins: string[]

    Returns {
        key: string;
        value: T;
    }[]

    An array of objects representing the key-value pairs of the nodes in width-first. Each object in the array has two properties: key (string) representing the key of the node and value (type T) representing the value associated with the node.

  • Returns an array of key-value tuples representing the nodes of the tree in a width-first traversal.

    Parameters

    • Optional origin: string | string[]

      where the traversal begins. If unspecified, will be all root nodes, thus traversal the whole forest.

    • Optional Rest ...moreOrigins: string[]

    Returns [string, T][]

    An array of key-value tuples representing the nodes in width-first.

  • Returns an array of keys representing the nodes of the tree in a width-first traversal starting from leaf nodes.

    Parameters

    • Optional origin: string | string[]

      where the traversal begins. If unspecified, will be all root nodes, thus traversal the whole forest.

    • Optional Rest ...moreOrigins: string[]

    Returns string[]

    An array of keys representing the nodes in width-first starting from leaf nodes.

  • Returns an array of key-value pairs representing the nodes of the tree in a width-first traversal starting from leaf nodes.

    Parameters

    • Optional origin: string | string[]

      where the traversal begins. If unspecified, will be all root nodes, thus traversal the whole forest.

    • Optional Rest ...moreOrigins: string[]

    Returns {
        key: string;
        value: T;
    }[]

    An array of objects representing the key-value pairs of the nodes in width-first. Each object in the array has two properties: key (string) representing the key of the node and value (type T) representing the value associated with the node.

  • Returns an array of key-value pairs representing the nodes of the tree in a width-first traversal starting from leaf nodes.

    Parameters

    • Optional origin: string | string[]

      where the traversal begins. If unspecified, will be all root nodes, thus traversal the whole forest.

    • Optional Rest ...moreOrigins: string[]

    Returns [string, T][]

    An array of key-value pairs representing the nodes in width-first starting from leaf nodes.

  • Returns an array of values representing the nodes of the tree in a width-first traversal starting from leaf nodes.

    Parameters

    • Optional origin: string | string[]

      where the traversal begins. If unspecified, will be all root nodes, thus traversal the whole forest.

    • Optional Rest ...moreOrigins: string[]

    Returns T[]

    An array of values representing the nodes in width-first starting from leaf nodes.

  • Returns an array of values representing the nodes of the tree in a width-first traversal.

    Parameters

    • Optional origin: string | string[]

      where the traversal begins. If unspecified, will be all root nodes, thus traversal the whole forest.

    • Optional Rest ...moreOrigins: string[]

    Returns T[]

    An array of values representing the nodes in width-first.

Utility

  • set the default comparator of the SortedTree to a new comparator.

    Parameters

    • comparator: Comparator<[string, T]>

      the comparator to replace the default comprator with

    Returns void

  • Parameters

    • __namedParameters: [string, unknown]
    • __namedParameters: [string, unknown]

    Returns number