16 lines
580 B
OCaml
16 lines
580 B
OCaml
(* Yes, we have to repeat open Graph. *)
|
||
open Graph
|
||
|
||
(* assert false is of type ∀α.α, so the type-checker is happy. *)
|
||
|
||
(* returns a new graph having the same nodes than gr, but no arc. *)
|
||
let clone_nodes gr = n_fold gr new_node empty_graph
|
||
(*adds an arc or its value if there is an existing one*)
|
||
let add_arc g id1 id2 n =
|
||
match find_arc g id1 id2 with
|
||
| None -> new_arc g id1 id2 n
|
||
| Some a -> new_arc g id1 id2 (n + a)
|
||
|
||
(* maps all arcs of gr by function f *)
|
||
let gmap gr f = e_fold gr (fun acc id1 id2 x -> new_arc acc id1 id2 (f x)) (clone_nodes gr)
|
||
|