I understand how trees are usually used to change persistent data structures (create a new node and replace all its ancestors).
But what if I have a tree of 10,000 nodes and I need to change 1000 of them? I do not want to go through and create 1000 new roots, I need only one new root, which arises due to a change in everything at once.
For example: For example, take a constant binary tree. In the case of a single node update, it searches until it finds a node, creates a new one with the changes and old children, and creates new ancestors to the root.
In the case of a bulk upgrade, we can: Instead of just updating a single node, you will update 1000 nodes on it in a single pass.
In the root directory of the node, the current list is a complete list. Then you split this list between those that correspond to the left node and those that correspond to the right. If none of them matches one of the children, do not go down to him. Then you go to the left of the node (assuming there are matches), split its search list between its children and continue. When you have one node and a match, you update it and come back, replacing and updating the ancestors and other branches as needed.
This will only lead to one new root, even if it has changed any number of nodes.
source share