Module Graph.Abstract
Abstract Imperative Unlabeled Graphs.
Parameters
Signature
An imperative graph with marks is an imperative graph.
include Sig.I
An imperative graph is a graph.
include Sig.G
module V : Sig.VERTEXVertices have type
V.tand are labeled with typeV.label(note that an implementation may identify the vertex with its label)
type vertex= V.t
module E : Sig.EDGE with type vertex = vertexEdges have type
E.tand are labeled with typeE.label.src(resp.dst) returns the origin (resp. the destination) of a given edge.
type edge= E.t
Size functions
Membership functions
val mem_vertex : t -> vertex -> boolval mem_edge : t -> vertex -> vertex -> boolval mem_edge_e : t -> edge -> boolval find_edge : t -> vertex -> vertex -> edgefind_edge g v1 v2returns the edge fromv1tov2if it exists. Unspecified behaviour ifghas several edges fromv1tov2.- raises Not_found
if no such edge exists.
Successors and predecessors
You should better use iterators on successors/predecessors (see Section "Vertex iterators").
val succ : t -> vertex -> vertex listsucc g vreturns the successors ofving.- raises Invalid_argument
if
vis not ing.
val pred : t -> vertex -> vertex listpred g vreturns the predecessors ofving.- raises Invalid_argument
if
vis not ing.
Graph iterators
val iter_edges : (vertex -> vertex -> unit) -> t -> unitIter on all edges of a graph. Edge label is ignored.
Vertex iterators
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.
<b>Time complexity for ocamlgraph implementations:</b> 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.
val create : ?size:int -> unit -> tcreate ()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, sosizeis just an initial guess.
val clear : t -> unitRemove all vertices and edges from the given graph.
- since
- ocamlgraph 1.4
val copy : t -> tcopy greturns a copy ofg. Vertices and edges (and eventually marks, see moduleMark) are duplicated.
val add_vertex : t -> vertex -> unitadd_vertex g vadds the vertexvto the graphg. Do nothing ifvis already ing.
val remove_vertex : t -> vertex -> unitremove g vremoves the vertexvfrom the graphg(and all the edges going fromving). Do nothing ifvis not ing.<b>Time complexity for ocamlgraph implementations:</b> O(|V|*ln(D)) for unlabeled graphs and O(|V|*D) for labeled graphs. D is the maximal degree of the graph.
val add_edge : t -> vertex -> vertex -> unitadd_edge g v1 v2adds an edge from the vertexv1to the vertexv2in the graphg. Add alsov1(resp.v2) ingifv1(resp.v2) is not ing. Do nothing if this edge is already ing.
val add_edge_e : t -> edge -> unitadd_edge_e g eadds the edgeein the graphg. Add alsoE.src e(resp.E.dst e) ingifE.src e(resp.E.dst e) is not ing. Do nothing ifeis already ing.