JSPM

interval-tree2

1.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 109
  • Score
    100M100P100Q91130F
  • License MIT

interval tree in javascript

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

Circle CI

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-tree2

usage

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 tree

add 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 given

search 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');