A data structure and functions for graphs

#Graph Source

newtype Graph k v

A graph with vertices of type v.

Edges refer to vertices using keys of type k.


#unfoldGraph Source

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 Source

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 Source

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

List all vertices in a graph.

#lookup Source

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

Lookup a vertex by its key.

#outEdges Source

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 Source

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.