Why is there no mutable TreeMap in Scala?

后端 未结 5 1004
-上瘾入骨i
-上瘾入骨i 2020-12-29 19:17

Is it lack of time, some technical problem or is there a reason why it should not exist?

5条回答
  •  再見小時候
    2020-12-29 19:41

    I assume that the reason is that having a mutable variant doesn't bring a big benefit. There are some cases mentioned in the other answers when a mutable map could be a bit more efficient, for example when replacing an already existing value: A mutable variant would save creation of new nodes, but the complexity would be still O(log n).

    If you want to keep a shared reference to the map, you can use ImmutableMapAdaptor which wraps any immutable map into a mutable structure.

提交回复
热议问题