Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix removal of complex subtrees #72

Merged
merged 1 commit into from
May 17, 2021

Conversation

jistr
Copy link
Contributor

@jistr jistr commented May 16, 2021

Previous code had incorrect preorder traversal in
NodeId::remove_subtree. Upon return upwards in the tree, if a cursor's
parent didn't have a sibling, the algorithm would terminate without
looking at more distant ancestors which still might have some siblings
that needed removing.

In the following example arena, when removing node 1_2, node 1_2_2
should be marked as removed but it wasn't:

arena
`-- 1
    |-- 1_1
    |-- 1_2
    |   |-- 1_2_1
    |   |   `-- 1_2_1_1
    |   |       `-- 1_2_1_1_1
    |   `-- 1_2_2
    `-- 1_3

This issue with returning upwards in ancestors chain is now fixed. A
new test case is added with the above example scenario.

Resolves: #71

Previous code had incorrect preorder traversal in
NodeId::remove_subtree. Upon return upwards in the tree, if a cursor's
parent didn't have a sibling, the algorithm would terminate without
looking at more distant ancestors which still might have some siblings
that needed removing.

In the following example arena, when removing node 1_2, node 1_2_2
should be marked as removed but it wasn't:

    arena
    `-- 1
        |-- 1_1
        |-- 1_2
        |   |-- 1_2_1
        |   |   `-- 1_2_1_1
        |   |       `-- 1_2_1_1_1
        |   `-- 1_2_2
        `-- 1_3

This issue with returning upwards in ancestors chain is now fixed. A
new test case is added with the above example scenario.

Resolves: saschagrunert#71
@saschagrunert saschagrunert merged commit 806014f into saschagrunert:master May 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NodeId::remove_subtree does not remove the whole subtree sometimes
2 participants