com.jtransc.util.topologicalSort.kt Maven / Gradle / Ivy
package com.jtransc.util
import com.jtransc.error.noImpl
import java.util.*
// https://en.wikipedia.org/wiki/Topological_sorting
fun List.topologicalSort(getDependencies: (item:T) -> List):List {
// Kahn's algorithm
//val nodes = this
//val edges = nodes.map { it to getDependencies(it) }.toMap()
//val L = arrayListOf()
//val S = LinkedList(edges.filter { it.value.isEmpty() }.map { it.key })
//while (S.isNotEmpty()) {
// val n = S.removeFirst()
// L += n
// val ledges = edges[n]
// for (e in ledges)
// //ledges.
//}
noImpl("Not implemented topologicalSort!")
}