TopologicalSort

Topological sorting is used to define the order of execution of dependent specifications when they form an acyclic graph

class Object
trait Matchable
class Any

Value members

Concrete methods

def sort[T](elements: Seq[T], dependsOn: (T, T) => Boolean): Option[Vector[T]]

sort elements topologically so that element at position i doesn't depend on element at position j if i < j dependsOn(e1, e2) returns true if e1 depends on e2 returns None if there is a cycle

sort elements topologically so that element at position i doesn't depend on element at position j if i < j dependsOn(e1, e2) returns true if e1 depends on e2 returns None if there is a cycle

Here's the algorithm from Wikipedia

L ← Empty list that will contain the sorted nodes while there are unmarked nodes do select an unmarked node n visit(n) function visit(node n) if n has a temporary mark then stop (not a DAG) if n is not marked (i.e. has not been visited yet) then mark n temporarily for each node m with an edge from n to m do visit(m) mark n permanently add n to head of L