From 52f2b6f24fdc76bb476729ca66ae08de68d5b82d Mon Sep 17 00:00:00 2001 From: kateonbxsh Date: Mon, 1 Dec 2025 10:21:26 +0100 Subject: [PATCH] feat: implement Tools module --- src/tools.ml | 18 ++++++++++++++++++ src/tools.mli | 6 ++++++ 2 files changed, 24 insertions(+) create mode 100644 src/tools.ml create mode 100644 src/tools.mli diff --git a/src/tools.ml b/src/tools.ml new file mode 100644 index 0000000..b78ea0c --- /dev/null +++ b/src/tools.ml @@ -0,0 +1,18 @@ +open Graph + +(* we fold the graph using new_node as the function, +and using empty_graph as the initial value*) +let clone_nodes (graph: 'a graph) = n_fold graph (fun x -> new_node x) empty_graph;; + +(* we clone the graph, then fold the old graph, mapping the arcs, +and using the new cloned graph as the initial value *) +let gmap graph f = + let new_graph = clone_nodes graph + in e_fold graph (fun old_graph old_arc -> new_arc old_graph (f old_arc)) new_graph;; + + + +(* new_arc already does the job (thanks prof for pointing it out)*) +let add_arc graph fromid toid value = + new_arc graph {src = fromid; tgt = toid; lbl = value } + diff --git a/src/tools.mli b/src/tools.mli new file mode 100644 index 0000000..79db193 --- /dev/null +++ b/src/tools.mli @@ -0,0 +1,6 @@ +open Graph + +val clone_nodes: 'a graph -> 'b graph +val gmap: 'a graph -> ('a -> 'b) -> 'b graph +val add_arc: int graph -> id -> id -> int -> int graph +