Skip to content
New issue

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

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

Already on GitHub? # to your account

quadtree: fix cleanup of nodes during removal #94

Merged
merged 3 commits into from
Apr 6, 2022
Merged

Conversation

paulmach
Copy link
Owner

@paulmach paulmach commented Apr 3, 2022

This PR fixes issues brought up by @Hades32 in #90

Parts of the tree were getting pruned during removal, the cause is something like:

  1. remove a value that was stored in a leaf node. This would make the node's value nil, but not remove the node.
  2. adding some values would/could create children of this nil-value node. So you had have a nil-value node in the middle of the tree.
  3. when removing a value in a parent of the original node the removeNode code would recurse down, find this nil-value node and remove it, along with everything under it.

The main bug is that when adding nodes in 2, existing nil-value nodes were not reused. Also I'm unsure about the the previous removeNode code working properly.

The code assumes nil-value nodes are only in leafs. So on add we reuse nil-value nodes instead of jumping over them (reuse leaf nil-value nodes). On remove, we "pull-up" values to fill in the nil-value node caused by the removal that is in the middle of the tree.

@paulmach paulmach mentioned this pull request Apr 3, 2022
@paulmach paulmach merged commit a67580d into master Apr 6, 2022
@paulmach paulmach deleted the quadtree-remove branch April 6, 2022 23:18
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants