4 ms·
As far as I understand, refs are not intended for implementing data structures. Instead, they should be used to provide concurrent access to immutable data stru
by sesm 13y ago
As far as I understand, refs are not intended for implementing data structures. Instead, they should be used to provide concurrent access to immutable data structures. So the "Clojure way" solution would be to efficiently implement an immutable B-tree and then expose a ref to it.
- pron 13y agoAn atom would do that much more efficiently that a ref. Refs are there for more complex types of mutation (like mutating more than one persistent DS transactionally). Also, B-trees are a mutable data structure. "Immutable" B-trees aren't B-trees. Clojure's own persistent DS tries are quite efficient, but not nearly as scalable as a concurrent B-Tree, which easily supports lots of concurrent writes. AFAIK, there are no persistent data-structures that efficiently scale writes.