IntervalTree

IntervalTree

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

Constructor

new IntervalTree()

Construct new empty instance of IntervalTree
Source:

Members

items

Returns array of items ( pairs) in the ascended keys order
Source:

keys

Returns array of sorted keys in the ascending order
Source:

size

Returns number of items stored in the interval tree
Source:

values

Return array of values in the ascending keys order
Source:

Methods

exist(key, value) → {boolean}

Returns true if item {key,value} exist in the tree
Source:
Parameters:
Name Type Description
key interval correspondent to keys stored in the tree
value value object to be checked
Returns:
Type:
boolean
- true if item {key, value} exist in the tree, false otherwise

forEach(visitor(key,value))

Tree visitor. For each node implement a callback function.
Method calls a callback function with two parameters (key, value)
Source:
Parameters:
Name Type Description
visitor(key,value) function to be called for each tree item

insert(key, value) → {Node}

Insert new item into interval tree
Source:
Parameters:
Name Type Description
key interval object or array of two numbers [low, high]
value value representing any object (optional)
Returns:
Type:
Node
- returns reference to inserted node as an object {key:interval, value: value}

isEmpty() → {boolean}

Returns true if tree is empty
Source:
Returns:
Type:
boolean

map(callback(value,)

Value Mapper. Walk through every node and map node value to another value
Source:
Parameters:
Name Type Description
callback(value, key) - function to be called for each tree item

remove(key, value) → {boolean}

Remove entry {key, value} from the tree
Source:
Parameters:
Name Type Description
key interval correspondent to keys stored in the tree
value - value object
Returns:
Type:
boolean
- true if item {key, value} deleted, false if not found
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
Source:
Parameters:
Name Type Description
interval search interval, or array [low, high]
Returns:
Type:
Array