From 76c59abf84269e73b2ee11e746387ed7e35f1b1a Mon Sep 17 00:00:00 2001 From: Leandro-rdz Date: Mon, 2 Dec 2024 11:06:56 +0100 Subject: [PATCH] feat : wrtie the function in tools --- src/tools.ml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/tools.ml b/src/tools.ml index e064a78..b40c1b4 100644 --- a/src/tools.ml +++ b/src/tools.ml @@ -1,7 +1,13 @@ - (* Yes, we have to repeat open Graph. *) open Graph -(* assert false is of type ∀α.α, so the type-checker is happy. *) -let clone_nodes _gr = assert false -let gmap _gr _f = assert false -(* Replace _gr and _f by gr and f when you start writing the real function. *) \ No newline at end of file +(* returns a new graph having the same nodes than gr, but no arc *) +let clone_nodes gr = n_fold gr new_node empty_graph + +(* maps all arcs of gr by function f *) +let gmap gr f = e_fold gr (fun gr arc -> new_arc gr {arc with lbl = f arc.lbl}) (clone_nodes gr) + +(* adds n to the value of the arc between id1 and id2. If the arc does not exist, it is created *) +let add_arc g id1 id2 n= + match find_arc g id1 id2 with + | Some _ -> g + | None -> let arc = {src = id1; tgt = id2; lbl = n} in new_arc g arc \ No newline at end of file