Persistent Data Structures and Path Copying
Keep old versions of a tree by copying only the nodes whose contents or child pointers change.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 2
- Reading time
- 1 min
In this article2 chapters
A root names one immutable version
Start with a balanced search tree whose nodes never change after construction. To insert an item, create nodes along the search path and reuse every unaffected subtree. If the original root represented keys \(2,4,6\), inserting \(7\) into a new version can leave the node for \(2\) shared by both roots. Following pointers from the old root still yields exactly the old contents. Rebalancing also constructs new nodes for each changed fragment.
Space grows with the changed frontier
A root-to-leaf update in a balanced tree creates \(O(\log n)\) nodes. The number of simultaneously retained versions determines when shared nodes can be reclaimed. Reference counting or tracing can identify nodes unreachable from retained roots. Balanced search trees explain the local transformations that path copying must preserve. Snapshot isolation uses a related idea of historical visibility, with additional transaction rules to decide which versions a reader may observe.[1]