Structural Sharing Between Immutable Values
Structural sharing lets new and old immutable values reference unchanged parts while allocating only what differs.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 2
- Reading time
- 1 min
In this article2 chapters
Trace a linked list
Begin with a list containing A, B, C. A new value can add X at the front and point from X to the unchanged earlier list. Both versions share A through C without needing those nodes to change. See linked node storage.
Check what still depends on immutability
If a shared node can change its successor, both versions can observe the edit. Use a representation that maintains the promised invariant. Persistent data structures extend this technique to more operations.[1]