Safe Haskell | None |
---|---|
Language | Haskell2010 |
This is a simple module to handle a common pattern: constructing graphs where vertex labels map uniquely to vertices.
The primary functions in this module are vertexForLabel
and
vertexForLabelRef
, which take a vertex label and return the Vertex
for
that label (allocating a new Vertex
) if necessary. The first of those
functions explicitly threads the mapping as inputs and outputs. The second
manages a mutable ref side-by-side with the underlying graph.
After the graph is fully constructed, this mapping is often still useful.
Synopsis
- data VertexMap nl
- emptyVertexMap :: VertexMap nl
- vertexForLabel :: (MLabeledVertex g, Ord (MVertexLabel g), PrimMonad m, MonadRef m) => g m -> VertexMap (MVertexLabel g) -> MVertexLabel g -> m (Vertex, VertexMap (MVertexLabel g))
- lookupVertexForLabel :: Ord nl => nl -> VertexMap nl -> Maybe Vertex
- vertexMapFromGraph :: (HasVertexLabel g, Ord (VertexLabel g)) => g -> VertexMap (VertexLabel g)
- data VertexMapRef nl m
- newVertexMapRef :: (PrimMonad m, MonadRef m) => m (VertexMapRef nl m)
- vertexForLabelRef :: (MLabeledVertex g, Ord (MVertexLabel g), PrimMonad m, MonadRef m) => g m -> VertexMapRef (MVertexLabel g) m -> MVertexLabel g -> m Vertex
- vertexMapFromRef :: (PrimMonad m, MonadRef m) => VertexMapRef nl m -> m (VertexMap nl)
Pure interface
A simple mapping from labels to their Vertex
emptyVertexMap :: VertexMap nl Source #
vertexForLabel :: (MLabeledVertex g, Ord (MVertexLabel g), PrimMonad m, MonadRef m) => g m -> VertexMap (MVertexLabel g) -> MVertexLabel g -> m (Vertex, VertexMap (MVertexLabel g)) Source #
vertexMapFromGraph :: (HasVertexLabel g, Ord (VertexLabel g)) => g -> VertexMap (VertexLabel g) Source #
Ref interface
data VertexMapRef nl m Source #
A VertexMap
wrapped up in a mutable ref for possibly
easier access in vertexMapFromRef
.
newVertexMapRef :: (PrimMonad m, MonadRef m) => m (VertexMapRef nl m) Source #
Allocate a new VertexMap
buried in a mutable ref.
vertexForLabelRef :: (MLabeledVertex g, Ord (MVertexLabel g), PrimMonad m, MonadRef m) => g m -> VertexMapRef (MVertexLabel g) m -> MVertexLabel g -> m Vertex Source #
Just like vertexForLabel
, but holding the mapping in a ref instead
of threading it. Usage is simpler:
v <- vertexForLabelRef g m lbl
vertexMapFromRef :: (PrimMonad m, MonadRef m) => VertexMapRef nl m -> m (VertexMap nl) Source #
Extract the pure VertexMap
from the mutable ref. This is useful
to retain the mapping after the graph is fully constructed.