impure-containers-0.4.3: Mutable containers in haskell

Safe HaskellNone
LanguageHaskell2010

Data.Graph.Mutable

Contents

Synopsis

Graph Operations

Operations that mutate a MGraph. Vertices and edges can both be added, and edges can be deleted, but vertices cannot be deleted. Providing such an operation would undermine the safety that this library provides.

insertVertex :: (PrimMonad m, Hashable v, Eq v) => MGraph (PrimState m) g e v -> v -> m (Vertex g) Source #

This does two things:

  • Check to see if a vertex with the provided value already exists
  • Create a new vertex if it does not exist

In either case, the vertex id is returned, regardless or whether it was preexisting or newly created.

insertEdge :: PrimMonad m => MGraph (PrimState m) g e v -> Vertex g -> Vertex g -> e -> m () Source #

This replaces the edge if it already exists. If you pass the same vertex as the source and the destination, this function has no effect.

insertEdgeWith :: PrimMonad m => MGraph (PrimState m) g e v -> (e -> e -> e) -> Vertex g -> Vertex g -> e -> m () Source #

Insert edge with a function, combining the existing edge value and the old one.

Vertices Operations

Operations that mutate a MVertices or a MUVertices. These functions have nothing to do with MGraph and are not usually needed by end users of this library. They are useful for users writing algorithms that need to mark vertices in a graph as it is traversed.

All of these operations are wrappers around operations from Data.Vector.Mutable and Data.Vector.Unbox.Mutable. As long as you do not import Data.Graph.Types.Internal, this library guarentees that these operations will not fail at runtime.

verticesUReplicate :: (PrimMonad m, Unbox v) => Size g -> v -> m (MUVertices (PrimState m) g v) Source #

verticesWrite :: PrimMonad m => MVertices (PrimState m) g v -> Vertex g -> v -> m () Source #

verticesUWrite :: (PrimMonad m, Unbox v) => MUVertices (PrimState m) g v -> Vertex g -> v -> m () Source #

verticesURead :: (PrimMonad m, Unbox v) => MUVertices (PrimState m) g v -> Vertex g -> m v Source #