David Glasser
09/16/2019, 5:14 PMmap
return Lists whose get
method is O(1)? If so, is that documented?Shawn
09/16/2019, 5:15 PMmap
is defined as an extension method to a number of collection typesmap
you’re referring to is likely inline fun <T, R> Iterable<T>.map()
David Glasser
09/16/2019, 5:16 PMCasey Brooks
09/16/2019, 5:16 PMArrayList
, which gets mapped to the underlying platform-specific equivalent. I don’t think it’s specifically documented, but it’s easy enough to see by looking at the sourceShawn
09/16/2019, 5:16 PMList
, but neither the Iterable nor List interfaces make any guarantee as to underlying access complexitiesDavid Glasser
09/16/2019, 5:16 PMShawn
09/16/2019, 5:17 PMList
will be returned by that map function, but pragmatically speaking on the JVM it’s going to be ArrayList
more likely than notCasey Brooks
09/16/2019, 5:18 PMmapTo(ArrayList())
instead.David Glasser
09/16/2019, 5:20 PMif (this is Random Access) this else ArrayList(this)
Shawn
09/16/2019, 5:24 PMRandom Access
interface or abstract type to match upon, butDavid Glasser
09/16/2019, 5:24 PMCasey Brooks
09/16/2019, 5:24 PMShawn
09/16/2019, 5:25 PMDavid Glasser
09/16/2019, 5:25 PMShawn
09/16/2019, 5:26 PMDavid Glasser
09/16/2019, 5:26 PMShawn
09/16/2019, 5:26 PMDavid Glasser
09/16/2019, 5:26 PMShawn
09/16/2019, 5:30 PMnew IndexOutOfBoundsException()
is a O(1)
operation 🤔