What is the complexity of the groupingBy{ it }.eachCount() operation?
What is the time-complexity of the groupingBy{ it }.eachCount() operation?
fun main() {
val a = listOf(1, 1, 3, 3, 3, 5, 8, 8)
val counter = a.groupingBy { it }.eachCount()
println(counter)
}
Here is the source code for both functions:
public actual fun Grouping.eachCount(): Map =
foldTo(destination = mutableMapOf(),
initialValueSelector = { _, _ -> kotlin.jvm.internal.Ref.IntRef() },
operation = { _, acc, _ -> acc.apply { element += 1 } })...