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

clear()

Clear tree
Source:

exist(key, value) → {boolean}

Returns true if item {key,value} exist in the tree
Source:
Parameters:
Name Type Description
key Interval interval correspondent to keys stored in the tree
value any 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 interval object or array of two numbers [low, high]
value any value representing any object (optional)
Returns:
Type:
Node
returns reference to inserted node as an object {key:interval, value: value}

intersect_any(interval) → {boolean}

Returns true if intersection between given and any interval stored in the tree found
Source:
Parameters:
Name Type Description
interval Interval search interval or tuple [low, high]
Returns:
Type:
boolean

isEmpty() → {boolean}

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

(generator) iterate(interval, outputMapperFn(value,key)) → {Iterator}

Source:
Parameters:
Name Type Description
interval Interval optional if the iterator is intended to start from the beginning
outputMapperFn(value,key) optional function that maps (value, key) to custom output
Returns:
Type:
Iterator

map(callback(value,key))

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 interval correspondent to keys stored in the tree
value any 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 Interval search interval, or tuple [low, high]
outputMapperFn(value,key) optional function that maps (value, key) to custom output
Returns:
Type:
Array