All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.jetbrains.datalore.plot.builder.data.GroupUtil.kt Maven / Gradle / Ivy

There is a newer version: 4.5.3-alpha1
Show newest version
/*
 * Copyright (c) 2019. JetBrains s.r.o.
 * Use of this source code is governed by the MIT license that can be found in the LICENSE file.
 */

package jetbrains.datalore.plot.builder.data

object GroupUtil {
    internal val SINGLE_GROUP = { _: Int -> 0 }

    fun wrap(l: List): (Int) -> Int {
        return { index ->
            if (index > 0 && index < l.size)
                l[index]!!.toInt()
            else
                0
        }
    }

    fun wrap(groupByPointIndex: Map): (Int) -> Int {
        return { groupByPointIndex[it]!! }
    }

    fun indicesByGroup(dataLength: Int, groups: (Int) -> Int): Map> {
        val indicesByGroup = LinkedHashMap>()
        for (i in 0 until dataLength) {
            val group = groups(i)
            if (!indicesByGroup.containsKey(group)) {
                indicesByGroup[group] = ArrayList()
            }
            indicesByGroup[group]!!.add(i)
        }

        return indicesByGroup
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy