Open kdorsel opened 4 years ago
After some looking around I found I'm able to get using the built in filter. For my use case, I'd sacrifice memory for quick lookup of Interval length. I will play around with this some more.
def findInterval(tree, minLength=None, maxLength=None):
if minLength and maxLength:
l = lambda x: minLength <= x.length() <= maxLength
elif minLength:
l = lambda x: minLength <= x.length()
elif maxLength:
l = lambda x: x.length() <= maxLength
else:
raise('')
return list(filter(l, tree))
Every data structure has pros and cons; there is no single data structure that can answer all possible queries in optimum time. Unfortunately, intervaltree cannot answer your length filter query in faster than linear time. You might want to use a sorted list to get answers in log(n)
time. Or if linear time is ok for you, a comprehension like this can help save memory:
[i for i in t if minLength <= i.length() <= maxLength]
Is there a way to find all intervals that are at least
x
in length. For examplet.findIntervals(minLength=None, maxLength=None)