Skip to content
FutureBlitz

    Install

    Import std.algo.topological

    FindCycle

    std.algo.topological

    function

    Public Function FindCycle<N: Hashable>(nodes: N[], successors: Func(N): N[]): N[]?

    A cycle among the nodes and what their successors reach, its nodes in the order they lead to each other, each once, or Null when there's none. It's the first that depth-first search meets, going from the nodes given in their order: a node that's its own successor is a cycle of one.

    Examples

    Local leads = {"a": ["b"], "b": ["c"], "c": ["a"]}
    Expect(FindCycle(["a"], Function(node: String) => leads[node]) == ["a", "b", "c"])
    Expect(TopologicalSort(["a"], Function(node: String) => leads[node]) == Null)

    std/algo/topological.fb, line 102

    Report an issue with this page or with FutureBlitz on GitHub.