brainrake / elm-arc-diagram / AcyclicDigraph

Type aliases

The following type aliases are used to make type annotations more meaningful.


type alias Node =
Basics.Int


type alias Edge =
( Node
, Node 
)


type alias Cycle =
List Node

AcyclicDigraph


type AcyclicDigraph

Represents a directed graph with no cycles.

fromEdges : Set Edge -> Result (List Cycle) AcyclicDigraph

From a directed graph represented as a set of edges, get an AcyclicDigraph if the graph has no cycles; otherwise, get a list of all its simple cycles.

toEdges : AcyclicDigraph -> Set Edge

From an AcyclicDigraph, get its representation as a set of edges.

Topological sorting

topologicalRank : AcyclicDigraph -> Dict Node Basics.Int

Get a dictionary mapping node to topological rank. Rank numbering starts at 1 for all source nodes.

topologicalSortBy : (Node -> comparable) -> Dict Node Basics.Int -> List Node

From topologically-ranked nodes, get a well-ordered list of nodes by providing a (Node -> comparable) function to sort same-ranked nodes by.