Is it lack of time, some technical problem or is there a reason why it should not exist?
Companion object TreeMapA mutable sorted map implemented using a mutable red-black tree as underlying data structure.
Companion object TreeMapAn immutable SortedMap whose values are stored in a red-black tree. This class is optimal when range queries will be performed, or when traversal in order of an ordering is desired.
2. Default Sorting in TreeMap. By default, TreeMap sorts all its entries according to their natural ordering. For an integer, this would mean ascending order and for strings, alphabetical order.
A TreeMap is a Map that maintains its entries in ascending order, sorted according to the keys' natural ordering, or according to a Comparator provided at the time of the TreeMap constructor argument. The TreeMap class is efficient for traversing the keys in a sorted order.
It's just a missing case that will presumably eventually be filled in. There is no reason not to do it, and in certain cases it would be considerably faster than the immutable tree (since modifications require log(n) object creations with an immutable tree and only 1 with a mutable tree).
Edit: and in fact it was filled in in 2.12.
Mutable TreeMap.
(There is a corresponding Set
also.)
Meanwhile you can use the Java TreeMap, which is exactly what you need.
val m = new java.util.TreeMap[String, Int]() m.put("aa", 2) m.put("cc", 3)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With