add method

void add(
  1. dynamic interval
)

Adds an interval into this tree.

Implementation

void add(dynamic interval) {
  var iv = _asInterval(interval);
  if (iv == null) return;

  bool joined = false;
  var it = _tree.fromIterator(iv);
  while (it.movePrevious()) {
    final union = _tryJoin(it.current, iv);
    if (union == null) break;
    it = _tree.fromIterator(iv = union, inclusive: false);
    joined = true;
  }

  it = _tree.fromIterator(iv!, inclusive: false);
  while (it.moveNext()) {
    final union = _tryJoin(it.current, iv);
    if (union == null) break;
    it = _tree.fromIterator(iv = union, inclusive: false);
    joined = true;
  }

  if (!joined) {
    _tree.add(iv!);
  }
}