data-named-0.1.0: Data types for named entities

Safe HaskellSafe-Inferred

Data.Named.Graph

Description

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.

Synopsis

Documentation

data Graph k v Source

A graph.

Constructors

Graph 

Fields

nodeMap :: Map k v
 
edgeMap :: Map k [k]
 

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

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

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

Get node with the given key.

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

Get keys of adjacent nodes for the given node key.

roots :: Ord k => Graph k v -> [k]Source

Return all graph roots (i.e. nodes with no parents).

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).

toForest :: (Show k, Ord k) => Graph k v -> Forest vSource

Transform graph into a forest. It removes duplicate nodes from trees chosing trees in an arbitrary order.