Signatures for graph implementations.
Signature for edges.
Edges are ORDERED_TYPE.
Edges are directed.
Edges are labeled.
Common signature for all graphs.
Abstract type of graphs
Vertices have type V.t
and are labeled with type V.label
(note that an implementation may identify the vertex with its
label)
Is this an implementation of directed graphs?
Degree of a vertex
You should better use iterators on successors/predecessors (see Section "Vertex iterators").
Labeled edges going from/to a vertex
Each iterator iterator f v g
iters f
to the successors/predecessors
of v
in the graph g
and raises Invalid_argument
if v
is not in
g
. It is the same for functions fold_*
which use an additional
accumulator.
Time complexity for ocamlgraph implementations: operations on successors are in O(1) amortized for imperative graphs and in O(ln(|V|)) for persistent graphs while operations on predecessors are in O(max(|V|,|E|)) for imperative graphs and in O(max(|V|,|E|)*ln|V|) for persistent graphs.
iter/fold on all successors/predecessors of a vertex.
iter/fold on all edges going from/to a vertex.
Signature for persistent (i.e. immutable) graph.
remove g v
removes the vertex v
from the graph g
(and all the edges going from v
in g
).
Just return g
if v
is not in g
.
Time complexity for ocamlgraph implementations: O(|V|*ln(|V|)) for unlabeled graphs and O(|V|*max(ln(|V|),D)) for labeled graphs. D is the maximal degree of the graph.
Signature for imperative (i.e. mutable) graphs.
create ()
returns an empty graph. Optionally, a size can be
given, which should be on the order of the expected number of
vertices that will be in the graph (for hash tables-based
implementations). The graph grows as needed, so size
is
just an initial guess.
remove g v
removes the vertex v
from the graph g
(and all the edges going from v
in g
).
Do nothing if v
is not in g
.
Time complexity for ocamlgraph implementations: O(|V|*ln(D)) for unlabeled graphs and O(|V|*D) for labeled graphs. D is the maximal degree of the graph.
Signature equivalent to Set.OrderedType
with a default value.