https://kotlinlang.org logo
#codereview
Title
# codereview
m

Marc Knaup

01/30/2019, 9:12 AM
What's better (faster? more memory efficient?) when creating mutable maps where the insertion order doesn't matter? Use
mutableMapOf()
and
toMutableMap()
which use
LinkedHashMap
or instead
hashMapOf()
and
HashMap(other)
?
g

gildor

01/30/2019, 9:14 AM
hashMap
m

Marc Knaup

01/30/2019, 9:15 AM
👍 thanks I guess maintaining the order adds quite noticeable overhead?
g

gildor

01/30/2019, 9:17 AM
Not sure about real performance difference. you may try to find benchmarks. Also it depends on your use case
👌 1
LinkedHashMap consumes more memory because Entry has also
before
and
after
nodes
u

ursus

01/30/2019, 5:36 PM
TreeMap maintains order
m

Marc Knaup

01/30/2019, 5:37 PM
No, it's sorts entries :)
u

ursus

01/30/2019, 5:41 PM
well yea, because its a sorted tree inside
thats why its log n
oh you asked order doesnt matter, sorry
m

Marc Knaup

01/30/2019, 5:42 PM
But thanks for the intent :)
2 Views