So, the `LinkedHashMap` is a nice type in that its...
# announcements
g
So, the
LinkedHashMap
is a nice type in that its got the time complexities of a hash map and it preserves insertion order... but its implementation really is pretty gnarly. Does anybody have numbers on how its implementation impacts performance? Is there a more performant (and/or simpler and/or compact) implementation of an insertion-order-preserving-Map if I'm willing to give up some of the more esoteric intricacies of
LinkedHashMap
(eg: degradation to a b-tree if
hashCode == 0
, dynamic-checking for
Comparable
implementations, etc)? Immutability (even via copy-on-write) is also fine. I have maps that have an upper-bound size of 200, and I'm looking to get to lookups on the order of millions per second.
j
There is also PersistentMap available https://github.com/Kotlin/kotlinx.collections.immutable but no idea how it compares in performance. Great for use if you want to have immutable collections that share internals and program in a more functional style.
e
Persistent data strucutures are all slower and more complicated. Here I have a hashmap that is significantly faster, simpler and also preserves insertion order (we use it in K/N): https://github.com/elizarov/pure-kotlin-impl
2
m
if you’re targeting the JVM you could use http://fastutil.di.unimi.it/