interval_tree library Null safety

The library provides a non-overlapping interval tree implementation with support for calculating unions, intersections, and differences between individual intervals and entire trees.

Usage

Import the library:

import 'package:interval_tree/interval_tree.dart';

Construct a tree:

final IntervalTree tree = IntervalTree.from([[1, 3], [5, 8], [10, 15]]);

Add an interval:

tree.add([2, 6]);
print(tree); // IntervalTree([1, 8], [10, 15])

Remove an interval:

tree.remove([12, 16]);
print(tree); // IntervalTree([1, 8], [10, 12])

Calculate union/intersection/difference:

final IntervalTree other = IntervalTree.from([[0, 2], [5, 7] ]);

print(tree.union(other)); // IntervalTree([0, 8], [10, 12])
print(tree.intersection(other)); // IntervalTree([1, 2], [5, 7])
print(tree.difference(other)); // IntervalTree([2, 5], [7, 8], [10, 12])

Classes

Interval
An interval between two points, start and end.
IntervalTree
A non-overlapping collection of intervals organized into a tree.