Topological sorting algorithms implemented in Kotlin.
This library contains the following top-level functions:
-
fun <T> toposortKahn(graph: Map<T, List<T>>)Returns topologically sorted elements of a graph using Kahn’s algorithm. Note that
graphcontains the adjacency list for each vertex. One can also interpretgraphas a Hasse diagram of partial order. -
fun <T> toposortLayers(deps: Map<T, List<T>>)Performs a topological sort by returning elements by layers. Note that
depsrepresents the dependencies of each element. The order of produced elements is "reversed" with respect totoposortKahnfunction. One can also interpretdepsas a Hasse diagram with reversed edges — the returned layers correspond to anti-chains in partial order.