Package Exports
- interval-tree2
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (interval-tree2) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
interval-tree2
interval tree in JavaScript (source is written in CoffeeScript)
improves previous interval-tree
more maintenanceability with CoffeeScript OOP.
more robustness with mocha, CircleCI
API Documentation
latest API documentation Page (YUIDoc)
installation
$ npm install interval-tree2usage
require
var IntervalTree = require('interval-tree2');when using in web, use dist/interval-tree.js in this module.
<script src="dist/interval-tree.js"></scirpt>create
var itree = new IntervalTree(300); // 300 : the center of the treeadd interval data
itree.add(22, 56, 'foo'); // 'foo' is the id of the interval data
itree.add(44, 199, 'bar'); // 'bar' is the id of the interval data
itree.add(1, 38); // id is automatically set when not givensearch by point: get overlapped intervals from one point
var intervals = itree.search(103);or
var intervals = itree.pointSearch(103);intervals.forEach(function(interval) {
console.log(interval.start); // overlapped interval start position
console.log(interval.end); // overlapped interval end position
console.log(interval.id); // id of the overlapped interval
});
search by range: get overlapped intervals from a range
var intervals2 = itree.search(103, 400);or
var intervals2 = itree.rangeSearch(103, 400);intervals2.forEach(function(interval) {
console.log(interval.start); // overlapped interval start position
console.log(interval.end); // overlapped interval end position
console.log(interval.id); // id of the overlapped interval
});
remove an interval by id
itree.remove('foo');