5 ms·
How is the cost of copying close to zero or not apparent?
by inconclusive 10y ago
How is the cost of copying close to zero or not apparent?
- macmac 10y agoBecause persistent data structures that use structural sharing.
- rads 10y agoThe data structures in Clojure are built on shallow 32-way trees. When you "change" a map or a vector, the algorithm only copies from the root node down to the parent of the leaf you're changing. That's log32(N) copied nodes in a tree of N nodes total.
- DannyB2 10y agoGood answers by others. The cost it not quite zero, but very close. The benefits this buys are huge. The obvious case is recursive search algorithms.