1. James Taylor
  2. bx-python
  3. Issues
Issue #4 invalid

Not stable result of quicksect.IntervalNode

Nini Zhou
created an issue

In file test_intervalnode.py:

from bx.intervals.operations.quicksect import IntervalNode

tree = IntervalNode(0, 10, other=1)

tree.insert(5, 15, other=2)

tree.insert(5, 15, other=3)

tree.insert(15, 25, other=4)

tree.insert(25, 35, other=5)

result = []

tree.intersect(0, 30, lambda x: result.append(x.other))

for node in result:

print node

[zhouyu@localhost Tests]$ python test_intervalnode.py

1

[zhouyu@localhost Tests]$ python test_intervalnode.py

1

4

5

[zhouyu@localhost Tests]$ python test_intervalnode.py

1

2

3

4

5

[zhouyu@localhost Tests]$ python test_intervalnode.py

1

2

3

4

[zhouyu@localhost Tests]$ python test_intervalnode.py

1

4

Results are from running to running. bx-python svn version is 462. What is the possible reason for that? Thanks a lot!

Comments (1)

  1. James Taylor repo owner

    This is because of rotation, a node may need to change the root of the tree, returning a new root. If you keep using the old node as if it were the root, strange things happen (its subtrees may have changed, and the part of the tree above the node will be lost). Make sure to always use the new root returned from insert, or use the new IntervalTree wrapper that handles this for you. I have updated the documentation to try and make usage more clear.

  2. Log in to comment