intervaltree
intervaltree copied to clipboard
Fast way to build large tree?
Hi,
I'm trying to build a tree that can be 6000+ nodes big, and it seems to take roughly 4 minutes. I was wondering if there's a fast way to do it?
tree = IntervalTree()
for obj in obj_list:
tree.add(
Interval(
begin=obj.lo_location,
end=obj.hi_location,
data=obj,
),
)
Is the speed better if you do this?
tree = IntervalTree(Interval(obj.lo_location, obj.hi_location, obj) for obj in obj_list)
Hello,
I am building trees that are not as big as @25thbamofthetower's (mine are around 100 items long), and I have tested 3 ways to build the tree:
- Dict-like insertion -> The slowest
t = IntervalTree()
for obj in obj_list:
t[obj.begin : obj.end] = obj
- Using
from_tuples
classmethod -> Much better - Using the approach you suggested in the previous comment to the issue -> Slightly better than 2