Module

Data.Graph

A data structure and functions for graphs

#Graph

newtype Graph k v

A graph with vertices of type v.

Edges refer to vertices using keys of type k.

Instances

#unfoldGraph

unfoldGraph :: forall f k v out. Ord k => Functor f => Foldable f => Foldable out => f k -> (k -> v) -> (k -> out k) -> Graph k v

Unfold a Graph from a collection of keys and functions which label keys and specify out-edges.

#fromMap

fromMap :: forall k v. Map k (Tuple v (List k)) -> Graph k v

Create a Graph from a Map which maps vertices to their labels and outgoing edges.

#vertices

vertices :: forall k v. Graph k v -> List v

List all vertices in a graph.

#lookup

lookup :: forall k v. Ord k => k -> Graph k v -> Maybe v

Lookup a vertex by its key.

#outEdges

outEdges :: forall k v. Ord k => k -> Graph k v -> Maybe (List k)

Get the keys which are directly accessible from the given key.

#topologicalSort

topologicalSort :: forall k v. Ord k => Graph k v -> List k

Topologically sort the vertices of a graph.

If the graph contains cycles, then the behavior is undefined.

Modules