@@ -84,7 +84,7 @@ import 'package:quiver/collection.dart';
8484/// final interval = ivt.Interval(1, 2);
8585///
8686@immutable
87- class Interval extends Comparable <Interval > {
87+ class Interval implements Comparable <Interval > {
8888 /// Creates an interval between [start] and [end] points.
8989 Interval (dynamic start, dynamic end)
9090 : _start = _min (start, end),
@@ -101,10 +101,6 @@ class Interval extends Comparable<Interval> {
101101 /// Returns the end point of this interval.
102102 dynamic get end => _end;
103103
104- /// Returns the length of this interval.
105- @deprecated
106- dynamic get length => _end - _start;
107-
108104 /// Returns `true` if this interval contains the [other] interval.
109105 bool contains (Interval other) => other.start >= start && other.end <= end;
110106
@@ -247,7 +243,9 @@ class Interval extends Comparable<Interval> {
247243 String toString () => '[$start , $end ]' ;
248244
249245 static int _cmp (dynamic a, dynamic b) => Comparable .compare (a, b);
246+
250247 static dynamic _min (dynamic a, dynamic b) => _cmp (a, b) < 0 ? a : b;
248+
251249 static dynamic _max (dynamic a, dynamic b) => _cmp (a, b) > 0 ? a : b;
252250
253251 final dynamic _start;
@@ -327,13 +325,15 @@ class IntervalTree with IterableMixin<Interval> {
327325 factory IntervalTree .of (Iterable <Interval ?> intervals) =>
328326 IntervalTree ()..addAll (intervals);
329327
328+ final _tree = AvlTreeSet <Interval >(comparator: Comparable .compare);
329+
330330 /// Adds an [interval] into this tree.
331- void add (dynamic ? interval) {
332- Interval ? iv = _asInterval (interval);
331+ void add (dynamic interval) {
332+ var iv = _asInterval (interval);
333333 if (iv == null ) return ;
334334
335335 bool joined = false ;
336- BidirectionalIterator < Interval ?> it = _tree.fromIterator (iv);
336+ var it = _tree.fromIterator (iv);
337337 while (it.movePrevious ()) {
338338 final union = _tryJoin (it.current, iv);
339339 if (union == null ) break ;
@@ -365,7 +365,7 @@ class IntervalTree with IterableMixin<Interval> {
365365 void remove (dynamic interval) {
366366 final iv = _asInterval (interval);
367367
368- BidirectionalIterator < Interval > it = _tree.fromIterator (iv! );
368+ var it = _tree.fromIterator (iv! );
369369 while (it.movePrevious ()) {
370370 final current = it.current;
371371 if (! _trySplit (it.current, iv)) break ;
@@ -405,7 +405,7 @@ class IntervalTree with IterableMixin<Interval> {
405405 final result = IntervalTree ();
406406 if (isEmpty || other.isEmpty) result;
407407 for (final iv in other) {
408- BidirectionalIterator < Interval > it = _tree.fromIterator (iv);
408+ var it = _tree.fromIterator (iv);
409409 while (it.movePrevious () && iv.intersects (it.current)) {
410410 result.add (iv.intersection (it.current));
411411 }
@@ -418,15 +418,15 @@ class IntervalTree with IterableMixin<Interval> {
418418 }
419419
420420 @override
421- bool contains (dynamic interval ) {
422- final iv = _asInterval (interval );
423- BidirectionalIterator < Interval ?> it = _tree.fromIterator (iv! );
424- while (it.movePrevious () && iv.intersects (it.current! )) {
425- if (it.current! .contains (iv)) return true ;
421+ bool contains (Object ? element ) {
422+ final iv = _asInterval (element );
423+ var it = _tree.fromIterator (iv! );
424+ while (it.movePrevious () && iv.intersects (it.current)) {
425+ if (it.current.contains (iv)) return true ;
426426 }
427427 it = _tree.fromIterator (iv, inclusive: false );
428- while (it.moveNext () && it.current! .intersects (iv)) {
429- if (it.current! .contains (iv)) return true ;
428+ while (it.moveNext () && it.current.intersects (iv)) {
429+ if (it.current.contains (iv)) return true ;
430430 }
431431 return false ;
432432 }
@@ -457,13 +457,13 @@ class IntervalTree with IterableMixin<Interval> {
457457
458458 /// Returns a bidirectional iterator that allows iterating the intervals.
459459 @override
460- BidirectionalIterator <Interval > get iterator => _tree.iterator;
460+ TreeIterator <Interval > get iterator => _tree.iterator;
461461
462462 /// Returns a string representation of the tree.
463463 @override
464- String toString () => 'IntervalTree' + super .toString ();
464+ String toString () => 'IntervalTree${ super .toString ()}' ;
465465
466- Interval ? _asInterval (dynamic ? interval) {
466+ Interval ? _asInterval (dynamic interval) {
467467 if (interval is Iterable ) {
468468 if (interval.length != 2 || interval.first is Iterable ) {
469469 throw ArgumentError ('$interval is not an interval' );
@@ -490,7 +490,4 @@ class IntervalTree with IterableMixin<Interval> {
490490 _tree.addAll ([...? a.difference (b)]);
491491 return true ;
492492 }
493-
494- final AvlTreeSet <Interval > _tree =
495- AvlTreeSet <Interval >(comparator: Comparable .compare);
496493}
0 commit comments