chaimleib / intervaltree

A mutable, self-balancing interval tree. Queries may be by point, by range overlap, or by range containment.
Apache License 2.0
638 stars 108 forks source link

intersection? #58

Open chananshgong opened 7 years ago

chananshgong commented 7 years ago
t1 = IntervalTree([Interval(0, 10))
t2 = IntervalTree([Interval(5, 15)])
t1&t2
Out[]: IntervalTree()

would not you expect to get IntervalTree(Interval(5,10)) ?

0:10 ----------
5:15      ------------
*         -----
escalonn commented 7 years ago

That's a different interpretation of intersection. The set operations implemented in this library on interval trees treat them simply as sets of interval objects, and those interval objects either compare equal or do not compare equal.

So if there are three unequal intervals, a, b, and c (no matter what their bounds are or if they overlap), then IntervalTree([b, c]) & IntervalTree([b, a]) == IntervalTree([b])

chaimleib commented 7 years ago

Part of the reason I didn't implement range intersection is that it was ambiguous what should happen if intervals within one or both of the input trees overlapped each other:

Rather than impose my idea of what to do in these cases, I decided to leave this up to users to implement.