Skip to content

ruaneg/interval-tree

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

interval-tree

interval tree in JavaScript

this repository is no more maintenanced. use interval-tree2

Installation

git clone git://github.com/shinout/interval-tree.git

OR

npm install interval-tree

Usage

var IntervalTree = require('interval-tree');

// add interval data

var itree = new IntervalTree(300); // 300 : the center of the tree

itree.add([22, 56,  'foo']);
itree.add([44, 199, 'bar']);

// search 1: get overlapped regions from one point
var results = itree.search(103);

results.forEach(function(result) {
  console.log(result.data); // overlapped range data
  console.log(result.id);   // id of the overlapped range
});

// search 2: get overlapped regions from a range
var results2 = itree.search(103, 400);

results2.forEach(function(result) {
  console.log(result.data);  // overlapped range data
  console.log(result.id);    // id of the overlapped range
  console.log(result.rate1); // overlapped rate to the given range
  console.log(result.rate2); // overlapped rate to the range of this result
});

About

interval tree in javascript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%