intervaltree icon indicating copy to clipboard operation
intervaltree copied to clipboard

Fast way to build large tree?

Open 25thbamofthetower opened this issue 4 years ago • 2 comments

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,
    ),
)

25thbamofthetower avatar Sep 03 '20 17:09 25thbamofthetower

Is the speed better if you do this?

tree = IntervalTree(Interval(obj.lo_location, obj.hi_location, obj) for obj in obj_list)

chaimleib avatar Nov 20 '20 18:11 chaimleib

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:

  1. Dict-like insertion -> The slowest
t = IntervalTree()
for obj in obj_list:
    t[obj.begin : obj.end] = obj
  1. Using from_tuples classmethod -> Much better
  2. Using the approach you suggested in the previous comment to the issue -> Slightly better than 2

didimelli avatar Feb 08 '21 11:02 didimelli