Legend:
Library
Module
Module type
Parameter
Class
Class type
Simple Graph Interface
A collections of algorithms on (mostly read-only) graph structures. The user provides her own graph structure as a ('v, 'e) CCGraph.t, where 'v is the type of vertices and 'e the type of edges (for instance, 'e = ('v * 'v) is perfectly fine in many cases).
Such a ('v, 'e) CCGraph.t structure is a record containing three functions: two relate edges to their origin and destination, and one maps vertices to their outgoing edges. This abstract notion of graph makes it possible to run the algorithms on any user-specific type that happens to have a graph structure.
Many graph algorithms here take a sequence of vertices as input. If the user only has a single vertex (e.g., for a topological sort from a given vertex), she can use Seq.return x to build a sequence of one element.
val topo_sort :
?eq:('v->'v-> bool)->?rev:bool ->?tbl:'vset->graph:('v, 'e)t->'vsequence->'v list
topo_sort ~graph seq returns a list of vertices l where each element of l is reachable from seq. The list is sorted in a way such that if v -> v' in the graph, then v comes before v' in the list (i.e. has a smaller index). Basically v -> v' means that v is smaller than v' see wikipedia
parametereq
equality predicate on vertices (default (=))
parameterrev
if true, the dependency relation is inverted (v -> v' means v' occurs before v)
Strongly connected components reachable from the given vertices. Each component is a list of vertices that are all mutually reachable in the graph. The components are explored in a topological order (if C1 and C2 are components, and C1 points to C2, then C2 will be yielded before C1). Uses Tarjan's algorithm
let open CCGraph in
let open Dot in
with_out "/tmp/truc.dot"
(fun out ->
pp ~attrs_v:(fun i -> [`Label (string_of_int i)]) ~graph:divisors_graph out 42
)
type('v, 'e) mut_graph =
< graph : ('v, 'e)t
; add_edge : 'e-> unit
; remove : 'v-> unit >
val mk_mut_tbl :
?eq:('v->'v-> bool)->?hash:('v-> int)->int ->('v, 'v * 'a * 'v)mut_graph
Make a new mutable graph from a Hashtbl. Edges are labelled with type 'a
Immutable Graph
A classic implementation of a graph structure on totally ordered vertices, with unlabelled edges. The graph allows to add and remove edges and vertices, and to iterate on edges and vertices.