Closed ccneko closed 2 years ago
I'm using the tree.merge_overlaps()
function at the end for now. Is it a preferrable way?
Modifying the data
field is disallowed by default so that users don't get tripped up when they sort Intervals and the (default) sorting order changes.
If you still want to modify the data field, you can set it to a single-element list, so [0]
instead of 0
, and then you can change the list member freely:
t = IntervalTree()
t.addi(1, 2, [0])
print(t)
# IntervalTree([Interval(1, 2, [0])])
data = list(t)[0].data
data[0] = data[0] + 1
print(t)
# IntervalTree([Interval(1, 2, [1])])
Thank you so much for your helpful prompt reply! This is a good idea.
May I ask if there is a way io update interval data?
For example, if I want to add 1 to a numeric data of an Interval in an IntervalTree
The result is creating a new Interval object at the same location, instead of updating the existing one:
Thankyou so much for your help in advance