README.md
1# intervaltree
2
3## Overview
4
5An interval tree can be used to efficiently find a set of numeric intervals overlapping or containing another interval.
6
7This library provides a basic implementation of an interval tree using C++ templates, allowing the insertion of arbitrary types into the tree.
8
9## Usage
10
11Add `#include "IntervalTree.h"` to the source files in which you will use the interval tree.
12
13To make an IntervalTree to contain objects of class T, use:
14
15```c++
16vector<Interval<T> > intervals;
17T a, b, c;
18intervals.push_back(Interval<T>(2, 10, a));
19intervals.push_back(Interval<T>(3, 4, b));
20intervals.push_back(Interval<T>(20, 100, c));
21IntervalTree<T> tree;
22tree = IntervalTree<T>(intervals);
23```
24
25Now, it's possible to query the tree and obtain a set of intervals which are contained within the start and stop coordinates.
26
27```c++
28vector<Interval<T> > results;
29tree.findContained(start, stop, results);
30cout << "found " << results.size() << " overlapping intervals" << endl;
31```
32
33The function IntervalTree::findOverlapping provides a method to find all those intervals which are contained or partially overlap the interval (start, stop).
34
35### Author: Erik Garrison <erik.garrison@gmail.com>
36
37### License: MIT
38