Guy Bieber
10/06/2020, 10:25 PMgildor
10/06/2020, 11:46 PMa little surprised that mutableMapOf promises to maintain key orderThere is no such promise
but considering the contract ofIt's not a part of contract, it's an implementation detail, but it intentional, to avoid many bugs caused by usage map and expect that it keeps ordermutableMapOf
jim
10/06/2020, 11:49 PMThere is no such promise@gildor Did you read the contract for
mutableMapOf
? Can you elaborate? Because I'm not sure how else to interpret the docs.Guy Bieber
10/06/2020, 11:56 PMmDataModel.tabMap.forEach() {
After:
mDataModel.tabMap.toSortedMap().forEach()
gildor
10/07/2020, 12:27 AMChuck Jazdzewski [G]
10/07/2020, 3:55 PMLinkedHashMap
returned by mutableMapOf()
does, whose iteration order is insertion order, but uses a doubly-linked list to maintain this order.
The map returned by mutableStateMapOf()
is more similar to HashMap
which does not guarantee a stable order. It is implemented by using PersistentMap
from kotlinx.collections.immutable
which also does not guarantee a stable order.Guy Bieber
10/08/2020, 6:15 PMChuck Jazdzewski [G]
10/09/2020, 3:32 PM