# Data.Graph

- Package
- purescript-colehaus-graphs
- Repository
- colehaus/purescript-graphs

A data structure and functions for graphs

### #insertEdge Source

`insertEdge :: forall v k. Ord k => k -> k -> Graph k v -> Maybe (Graph k v)`

Insert an edge from the start key to the end key.

Does nothing if the edge is already present.
Returns `Nothing`

iff either key is absent from the graph.

### #deleteEdge Source

`deleteEdge :: forall v k. Ord k => k -> k -> Graph k v -> Graph k v`

Remove edge from the start key to the end key.

Does nothing if the edge isn't present.

### #insertVertex Source

`insertVertex :: forall v k. Ord k => k -> v -> Graph k v -> Graph k v`

Insert a vertex into the graph.

If the key already exists, replaces the existing value and preserves existing edges.

### #deleteVertex Source

`deleteVertex :: forall v k. Ord k => k -> Graph k v -> Graph k v`

Remove the given vertex from the graph.

Does nothing if the key isn't present.

### #descendants Source

`descendants :: forall v k. Ord k => k -> Graph k v -> Set k`

Returns all descendants of given key.

Returns bottom if `k`

is in cycle.
Returns `mempty`

if the queried key is absent from the graph.

### #isDescendantOf Source

`isDescendantOf :: forall v k. Ord k => Graph k v -> k -> k -> Boolean`

Returns `false`

if either key is absent from the graph.

### #isParentOf Source

`isParentOf :: forall v k. Ord k => Graph k v -> k -> k -> Boolean`

Returns `false`

if either key is absent from the graph.

### #isAncestorOf Source

`isAncestorOf :: forall v k. Ord k => Graph k v -> k -> k -> Boolean`

Returns `false`

if either key is absent from the graph.

### #topologicalSort Source

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

Topologically sort the vertices of a graph.

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

### #areAdjacent Source

`areAdjacent :: forall v k. Ord k => Graph k v -> k -> k -> Boolean`

Check if the keys are adjacent.

Returns `false`

if either key is absent from the graph.

### #areConnected Source

`areConnected :: forall v k. Ord k => Graph k v -> k -> k -> Boolean`

Checks if there's a directed path between the start and end key.

### #isValidPath Source

`isValidPath :: forall v k. Ord k => Graph k v -> NonEmptyList k -> Boolean`

### #shortestPath Source

`shortestPath :: forall v k. Ord k => k -> k -> Graph k v -> Maybe (NonEmptyList k)`

Returns shortest path between start and end key if it exists.

Returns `Nothing`

if there's no path between the keys or
if the keys aren't present in the graph.
Cyclic graphs may return bottom.

- Modules
- Data.
Graph