This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://en.wikipedia.org/wiki/Interval_tree | |
export default class IntervalTree { | |
// intervals is a two dimensional array of "from" and "to" values | |
// the values can be of any type. If they can directly be compared | |
// using greater/lesser than operators then a compare function does | |
// not need to be supplied | |
constructor(intervals) { | |
this.allIntervals = intervals.map(interval => new Interval(interval[0], interval[1])); | |
this.root = new IntervalTreeNode(this.allIntervals); |