123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139(*
* Copyright (c) 2013-2022 Thomas Gazagnaire <thomas@gazagnaire.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)moduletypeS=sigincludeGraph.Sig.I(** Directed graph *)includeGraph.Oper.Swithtypeg:=t(** Basic operations. *)(** Topological traversal *)moduleTopological:sigvalfold:(vertex->'a->'a)->t->'a->'aendvalvertex:t->vertexlist(** Get all the vertices. *)valedges:t->(vertex*vertex)list(** Get all the relations. *)valclosure:?depth:int->pred:(vertex->vertexlistLwt.t)->min:vertexlist->max:vertexlist->unit->tLwt.t(** [closure depth pred min max ()] creates the transitive closure graph of
[max] using the predecessor relation [pred]. The graph is bounded by the
[min] nodes and by [depth].
{b Note:} Both [min] and [max] are subsets of [n]. *)valiter:?cache_size:int->?depth:int->pred:(vertex->vertexlistLwt.t)->min:vertexlist->max:vertexlist->node:(vertex->unitLwt.t)->?edge:(vertex->vertex->unitLwt.t)->skip:(vertex->boolLwt.t)->rev:bool->unit->unitLwt.t(** [iter depth min max node edge skip rev ()] iterates in topological order
over the closure graph starting with the [max] nodes and bounded by the
[min] nodes and by [depth].
It applies three functions while traversing the graph: [node] on the
nodes; [edge n predecessor_of_n] on the directed edges and [skip n] to not
include a node [n], its predecessors and the outgoing edges of [n].
If [rev] is true (the default) then the graph is traversed in the reverse
order: [node n] is applied only after it was applied on all its
predecessors; [edge n p] is applied after [node n]. Note that [edge n p]
is applied even if [p] is skipped.
[cache_size] is the size of the LRU cache used to store nodes already
seen. If [None] (by default) every traversed nodes is stored (and thus no
entries are never removed from the LRU). *)valbreadth_first_traversal:?cache_size:int->pred:(vertex->vertexlistLwt.t)->max:vertexlist->node:(vertex->unitLwt.t)->unit->unitLwt.t(** [breadth_first_traversal ?cache_size pred max node ()] traverses the
closure graph in breadth-first order starting with the [max] nodes. It
applies [node] on the nodes of the graph while traversing it. *)valoutput:Format.formatter->(vertex*Graph.Graphviz.DotAttributes.vertexlist)list->(vertex*Graph.Graphviz.DotAttributes.edgelist*vertex)list->string->unit(** [output ppf vertex edges name] create aand dumps the graph contents on
[ppf]. The graph is defined by its [vertex] and [edges]. [name] is the
name of the output graph.*)valmin:t->vertexlist(** Compute the minimum vertex. *)valmax:t->vertexlist(** Compute the maximun vertex. *)typedump=vertexlist*(vertex*vertex)list(** Expose the graph internals. *)valexport:t->dump(** Expose the graph as a pair of vertices and edges. *)valimport:dump->t(** Import a graph. *)moduleDump:Type.Swithtypet=dump(** The base functions over graph internals. *)endmoduletypeHASH=sigincludeType.Svalshort_hash:t->intendmoduletypeSigs=sigmoduletypeS=SmoduletypeHASH=HASH(** Build a graph. *)moduleMake(Contents_key:Type.S)(Node_key:Type.S)(Commit_key:Type.S)(Branch:Type.S):SwithtypeV.t=[`ContentsofContents_key.t|`NodeofNode_key.t|`CommitofCommit_key.t|`BranchofBranch.t]end