Implementation of interval binary search tree Interval tree stores items which are couples of {key:interval, value: value} Interval is an object with high and low properties or simply pair [low,high] of numeric values

Type Parameters

  • V = unknown

Constructors

Properties

nil_node: Node<V>
root: null | Node<V>

Accessors

  • get items(): { key: any; value: V }[]

    Returns array of items (<key,value> pairs) in the ascended keys order

    Returns { key: any; value: V }[]

Methods

  • Returns true if item {key,value} exist in the tree

    Parameters

    • key: IntervalInput

      interval correspondent to keys stored in the tree

    • value: V = ...

      value object to be checked

    Returns boolean

    true if item {key, value} exist in the tree, false otherwise

  • Tree visitor. For each node implement a callback function. Method calls a callback function with two parameters (key, value)

    Parameters

    • visitor: (key: IntervalBase, value: V) => void

      function to be called for each tree item

    Returns void

  • Insert new item into interval tree

    Parameters

    • key: IntervalInput

      interval object or array of two numbers [low, high]

    • value: V = ...

      value representing any object (optional)

    Returns undefined | Node<V>

    returns reference to inserted node

  • Returns array of entry values which keys intersect with given interval If no values stored in the tree, returns array of keys which intersect given interval

    Parameters

    Returns V[]

  • Returns array of entry values which keys intersect with given interval If no values stored in the tree, returns array of keys which intersect given interval

    Type Parameters

    • T

    Parameters

    • interval: IntervalInput

      search interval, or tuple [low, high]

    • outputMapperFn: (value: V, key: IntervalBase) => T

      optional function that maps (value, key) to custom output

    Returns T[]

  • Test red-black tree property: every path from root to leaf has same black height

    Parameters

    • node: Node<V>

      starting node

    Returns number

    black height

    Error if property is violated

  • Test red-black tree property: all red nodes have exactly two black child nodes

    Returns boolean

    true if property holds

  • Check if any interval intersects with given interval

    Parameters

    • node: null | Node<V>

      starting node

    • search_node: Node<V>

      search interval as node

    Returns boolean

    true if intersection found

  • Search for node with given key and value

    Parameters

    • node: null | Node<V>

      starting node

    • search_node: Node<V>

      node to search for

    Returns undefined | Node<V>

    found node or undefined

  • Search all intervals intersecting given interval

    Parameters

    • node: null | Node<V>

      starting node

    • search_node: Node<V>

      search interval as node

    • res: Node<V>[]

      result array to collect found nodes

    Returns void

  • Find nearest forward node from given interval

    Parameters

    • node: null | Node<V>

      starting node

    • search_node: Node<V>

      search interval as node

    Returns null | Node<V>

    nearest forward node or null

  • Performs in-order traversal of the tree Applies action callback to each node in ascending order of keys

    Parameters

    • node: null | Node<V>

      starting node for traversal (typically root)

    • action: (node: Node<V>) => void

      callback function to be executed for each node

    Returns void