Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any reference for Kotlin standard Collection library time complexity?

For example, Scala has the official Collections Performance Characteristics page that shows the time complexity of methods like apply()(get in Java), insert(), and append() in collections like List, Array, and ArrayBuffer.

However, I cannot find such kind of information in Kotlin.

The Kotlin stdlib API page also does not have such information. Even worse, I don't get the information about the underlying implementation of List (created by listOf() or so), for example unless I dig into the source code.

So does List in Kotlin take O(n) time accessing an element, and take O(1) time appending an element?

Where can I find this information?

like image 202
Naetmul Avatar asked Jun 23 '17 08:06

Naetmul


1 Answers

Kotlin stdlib does not contain its own collections, on JVM listOf is just a binding to Java's Collections.emptyList(), Collections.singletonList(), and ArrayList. ArrayList has O(1) positional access complexity.

like image 124
Miha_x64 Avatar answered Nov 15 '22 10:11

Miha_x64