Welcome! Please see the About page for a little more info on how this works.

+1 vote
in Collections by

It seems to me that the reason https://ask.clojure.org/index.php/12073/update-vals-not-preserving-sorted-maps is a question at all, is that PersistentTreeMap doesn't implement IEditableCollection.

So to satisfy my own curiosity, why is this?

1 Answer

0 votes
by
selected by
 
Best answer

PTM (sorted maps) are implemented with red-black trees. Transients (IEditableCollection) needs some way to O(1) switch from persistent to transient and vice-versa, and a faster than O(n log n) way (amortized) to collect values during transient batch updates.

This pre-dates my involvement on the Clojure team, but I presume that the PTM red-black tree implementation can't provide those performance guarantees. Or perhaps it it possible but was just too difficult to be worth doing. I assume it's the former (due to rebalancing), but can't say for certain.

...