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

com.autonomousapps.graph.Topological.kt Maven / Gradle / Ivy

There is a newer version: 2.0.2
Show newest version
package com.autonomousapps.graph

/**
 * Finds the topological order of DAG `graph`. We know it has one, because it is a DAG.
 *
 * @param graph the DAG.
 */
internal class Topological(
  private val graph: DependencyGraph
) {

  private val order: Iterable

  init {
    val dfs = DepthFirstOrder(graph)
    order = dfs.reversePost()
  }

  /**
   * Returns a topological order for the digraph.
   *
   * @return a topological order of the nodes (as an iterable).
   */
  fun order(): Iterable = order
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy