Data.Graph.Inductive.NodeMap

fgl-5.8.3.0: Martin Erwig's Functional Graph Library

Safe Haskell | Safe-Inferred
Language | Haskell98

Data.Graph.Inductive.NodeMap

Contents

- Functional Construction
  - Map Construction
  - Graph Construction
- Monadic Construction
  - Map Construction
  - Graph Construction
  - Map inspection

Description

Utility methods to automatically generate and keep track of a mapping between node labels and `Node`s.

Synopsis

- data NodeMap a
- new :: NodeMap a
- fromGraph :: (Ord a, Graph g) => g a b -> NodeMap a
- mkNode :: Ord a => NodeMap a -> a -> (LNode a, NodeMap a)
- mkNode_ :: Ord a => NodeMap a -> a -> LNode a
- mkNodes :: Ord a => NodeMap a -> [a] -> ([LNode a], NodeMap a)
- mkLookupNode :: Ord a => NodeMap a -> a -> (Bool, LNode a, NodeMap a)
- mkNodes_ :: Ord a => NodeMap a -> [a] -> [LNode a]
- mkEdge :: Ord a => NodeMap a -> (a, a, b) -> Maybe (LEdge b)
- mkEdges :: Ord a => NodeMap a -> [(a, a, b)] -> Maybe [LEdge b]
- insMapNode :: (Ord a, DynGraph g) => NodeMap a -> a -> g a b -> (g a b, NodeMap a, LNode a)
- insMapLookupNode :: (Ord a, DynGraph g) => NodeMap a -> a -> g a b -> (Bool, g a b, NodeMap a, LNode a)
- insMapNode_ :: (Ord a, DynGraph g) => NodeMap a -> a -> g a b -> g a b
- insMapEdge :: (Ord a, DynGraph g) => NodeMap a -> (a, a, b) -> g a b -> g a b
- delMapNode :: (Ord a, DynGraph g) => NodeMap a -> a -> g a b -> g a b
- delMapEdge :: (Ord a, DynGraph g) => NodeMap a -> (a, a) -> g a b -> g a b
- insMapNodes :: (Ord a, DynGraph g) => NodeMap a -> [a] -> g a b -> (g a b, NodeMap a, [LNode a])
- insMapNodes_ :: (Ord a, DynGraph g) => NodeMap a -> [a] -> g a b -> g a b
- insMapEdges :: (Ord a, DynGraph g) => NodeMap a -> [(a, a, b)] -> g a b -> g a b
- delMapNodes :: (Ord a, DynGraph g) => NodeMap a -> [a] -> g a b -> g a b
- delMapEdges :: (Ord a, DynGraph g) => NodeMap a -> [(a, a)] -> g a b -> g a b
- mkMapGraph :: (Ord a, DynGraph g) => [a] -> [(a, a, b)] -> (g a b, NodeMap a)
- type NodeMapM a b (g :: Type -> Type -> Type) r = State (NodeMap a, g a b) r
- run :: (DynGraph g, Ord a) => g a b -> NodeMapM a b g r -> (r, (NodeMap a, g a b))
- run_ :: (DynGraph g, Ord a) => g a b -> NodeMapM a b g r -> g a b
- mkNodeM :: Ord a => a -> NodeMapM a b g (LNode a)
- mkNodesM :: Ord a => [a] -> NodeMapM a b g [LNode a]
- mkEdgeM :: Ord a => (a, a, b) -> NodeMapM a b g (Maybe (LEdge b))
- mkEdgesM :: Ord a => [(a, a, b)] -> NodeMapM a b g (Maybe [LEdge b])
- insMapNodeM :: (Ord a, DynGraph g) => a -> NodeMapM a b g (LNode a)
- insMapEdgeM :: (Ord a, DynGraph g) => (a, a, b) -> NodeMapM a b g ()
- delMapNodeM :: (Ord a, DynGraph g) => a -> NodeMapM a b g ()
- delMapEdgeM :: (Ord a, DynGraph g) => (a, a) -> NodeMapM a b g ()
- insMapNodesM :: (Ord a, DynGraph g) => [a] -> NodeMapM a b g [LNode a]
- insMapEdgesM :: (Ord a, DynGraph g) => [(a, a, b)] -> NodeMapM a b g ()
- delMapNodesM :: (Ord a, DynGraph g) => [a] -> NodeMapM a b g ()
- delMapEdgesM :: (Ord a, DynGraph g) => [(a, a)] -> NodeMapM a b g ()
- memberNode :: Ord a => a -> NodeMap a -> Bool
- lookupNode :: Ord a => a -> NodeMap a -> Maybe Node

# Functional Construction

data NodeMap a #

#### Instances

Instances details

NFData a => NFData (NodeMap a) # |
Instance details Defined in Data.Graph.Inductive.NodeMap Methods rnf :: NodeMap a -> () #
(Ord a, Read a) => Read (NodeMap a) # |
Instance details Defined in Data.Graph.Inductive.NodeMap Methods readsPrec :: Int -> ReadS (NodeMap a) # readList :: ReadS [NodeMap a] # readPrec :: ReadPrec (NodeMap a) # readListPrec :: ReadPrec [NodeMap a] #
Show a => Show (NodeMap a) # |
Instance details Defined in Data.Graph.Inductive.NodeMap Methods showsPrec :: Int -> NodeMap a -> ShowS # show :: NodeMap a -> String # showList :: [NodeMap a] -> ShowS #
Eq a => Eq (NodeMap a) # |
Instance details Defined in Data.Graph.Inductive.NodeMap Methods (==) :: NodeMap a -> NodeMap a -> Bool # (/=) :: NodeMap a -> NodeMap a -> Bool #

## Map Construction

new :: NodeMap a #

Create a new, empty mapping.

fromGraph :: (Ord a, Graph g) => g a b -> NodeMap a #

Generate a mapping containing the nodes in the given graph.

mkNode :: Ord a => NodeMap a -> a -> (LNode a, NodeMap a) #

Generate a labelled node from the given label. Will return the same node for the same label.

mkNode_ :: Ord a => NodeMap a -> a -> LNode a #

Generate a labelled node and throw away the modified `NodeMap`.

mkNodes :: Ord a => NodeMap a -> [a] -> ([LNode a], NodeMap a) #

Construct a list of nodes.

mkLookupNode :: Ord a => NodeMap a -> a -> (Bool, LNode a, NodeMap a) #

Act as `mkNode`, but return also a boolean set as `True` if the node was already in the map.

mkNodes_ :: Ord a => NodeMap a -> [a] -> [LNode a] #

Construct a list of nodes and throw away the modified `NodeMap`.

mkEdge :: Ord a => NodeMap a -> (a, a, b) -> Maybe (LEdge b) #

Generate a `LEdge` from the node labels.

mkEdges :: Ord a => NodeMap a -> [(a, a, b)] -> Maybe [LEdge b] #

Generates a list of `LEdge`s.

## Graph Construction

These functions mirror the construction and destruction functions in `Graph`, but use the given `NodeMap` to look up the appropriate `Node`s. Note that the `insMapNode` family of functions will create new nodes as needed, but the other functions will not.

insMapNode :: (Ord a, DynGraph g) => NodeMap a -> a -> g a b -> (g a b, NodeMap a, LNode a) #

insMapLookupNode :: (Ord a, DynGraph g) => NodeMap a -> a -> g a b -> (Bool, g a b, NodeMap a, LNode a) #

Act as `insMapNode`, but return also a boolean set as `True` if the node was already in the map.

insMapNode_ :: (Ord a, DynGraph g) => NodeMap a -> a -> g a b -> g a b #

insMapEdge :: (Ord a, DynGraph g) => NodeMap a -> (a, a, b) -> g a b -> g a b #

Partial function: raises exception if passed nodes that are not in the graph.

delMapNode :: (Ord a, DynGraph g) => NodeMap a -> a -> g a b -> g a b #

delMapEdge :: (Ord a, DynGraph g) => NodeMap a -> (a, a) -> g a b -> g a b #

Partial function: raises exception if passed nodes that are not in the graph.

insMapNodes :: (Ord a, DynGraph g) => NodeMap a -> [a] -> g a b -> (g a b, NodeMap a, [LNode a]) #

insMapNodes_ :: (Ord a, DynGraph g) => NodeMap a -> [a] -> g a b -> g a b #

insMapEdges :: (Ord a, DynGraph g) => NodeMap a -> [(a, a, b)] -> g a b -> g a b #

Partial function: raises exception if passed nodes that are not in the graph.

delMapNodes :: (Ord a, DynGraph g) => NodeMap a -> [a] -> g a b -> g a b #

delMapEdges :: (Ord a, DynGraph g) => NodeMap a -> [(a, a)] -> g a b -> g a b #

Partial function: raises exception if passed nodes that are not in the graph.

mkMapGraph :: (Ord a, DynGraph g) => [a] -> [(a, a, b)] -> (g a b, NodeMap a) #

Partial function: raises exception if passed a node that is not in the graph.

# Monadic Construction

type NodeMapM a b (g :: Type -> Type -> Type) r = State (NodeMap a, g a b) r #

Graph construction monad; handles passing both the `NodeMap` and the `Graph`.

The following mirror the functional construction functions, but handle passing `NodeMap`s and `Graph`s behind the scenes.

## Map Construction

run :: (DynGraph g, Ord a) => g a b -> NodeMapM a b g r -> (r, (NodeMap a, g a b)) #

Run a construction; return the value of the computation, the modified `NodeMap`, and the modified `Graph`.

run_ :: (DynGraph g, Ord a) => g a b -> NodeMapM a b g r -> g a b #

Run a construction and only return the `Graph`.

mkNodeM :: Ord a => a -> NodeMapM a b g (LNode a) #

Monadic node construction.

mkNodesM :: Ord a => [a] -> NodeMapM a b g [LNode a] #

mkEdgeM :: Ord a => (a, a, b) -> NodeMapM a b g (Maybe (LEdge b)) #

mkEdgesM :: Ord a => [(a, a, b)] -> NodeMapM a b g (Maybe [LEdge b]) #

## Graph Construction

insMapNodeM :: (Ord a, DynGraph g) => a -> NodeMapM a b g (LNode a) #

insMapEdgeM :: (Ord a, DynGraph g) => (a, a, b) -> NodeMapM a b g () #

delMapNodeM :: (Ord a, DynGraph g) => a -> NodeMapM a b g () #

delMapEdgeM :: (Ord a, DynGraph g) => (a, a) -> NodeMapM a b g () #

insMapNodesM :: (Ord a, DynGraph g) => [a] -> NodeMapM a b g [LNode a] #

insMapEdgesM :: (Ord a, DynGraph g) => [(a, a, b)] -> NodeMapM a b g () #

delMapNodesM :: (Ord a, DynGraph g) => [a] -> NodeMapM a b g () #

delMapEdgesM :: (Ord a, DynGraph g) => [(a, a)] -> NodeMapM a b g () #

## Map inspection

memberNode :: Ord a => a -> NodeMap a -> Bool #

Is the node in the map ?

lookupNode :: Ord a => a -> NodeMap a -> Maybe Node #

Lookup for the node in the map.