Safe Haskell | Safe-Inferred |
---|

Implementation of a graph with each node identified by a unique key. It is a provisional module and it might be replaced by the standard graph from containers package in the future.

- data Graph k v = Graph {}
- mkGraph :: Ord k => [(k, v, [k])] -> Graph k v
- node :: (Show k, Ord k) => Graph k v -> k -> v
- edges :: (Show k, Ord k) => Graph k v -> k -> [k]
- roots :: Ord k => Graph k v -> [k]
- toTree :: (Show k, Ord k) => Graph k v -> k -> Tree v
- toKeyTree :: (Show k, Ord k) => Graph k v -> k -> Tree k
- toForestWith :: (Show k, Ord k, Ord a) => (Tree v -> a) -> Graph k v -> Forest v
- toForest :: (Show k, Ord k) => Graph k v -> Forest v

# Documentation

mkGraph :: Ord k => [(k, v, [k])] -> Graph k vSource

Make a graph from a list of (key, value, [children keys]) tuples.

edges :: (Show k, Ord k) => Graph k v -> k -> [k]Source

Get keys of adjacent nodes for the given node key.

toTree :: (Show k, Ord k) => Graph k v -> k -> Tree vSource

Make a tree rooted in the node with respect to the graph.

toKeyTree :: (Show k, Ord k) => Graph k v -> k -> Tree kSource

Make a key tree rooted in the node with respect to the graph.

toForestWith :: (Show k, Ord k, Ord a) => (Tree v -> a) -> Graph k v -> Forest vSource

Transform graph into a forest given the priority function. That is, trees with higher priorities will be taken first, while those with lower priorities might be trimmed down (since we don't want to have nodes with multiple parents in the resulting forest).