(********************************************************************) (* OCaml code from the book ``Learn Programming with OCaml'' *) (* See https://usr.lmf.cnrs.fr/lpo/ *) (* *) (* Sylvain Conchon and Jean-Christophe Filliâtre *) (* Copyright 2025 Université Paris-Saclay and CNRS *) (* *) (* Openly licensed via CC BY SA 4.0 *) (* See https://creativecommons.org/licenses/by-sa/4.0/deed.en *) (********************************************************************) (* Program 68 on page 299 Graphs via adjacency matrices *) type vertex = int type t = bool array array let create n = Array.make_matrix n n false let nb_vertex = Array.length let mem_edge g v1 v2 = g.(v1).(v2) let add_edge g v1 v2 = g.(v1).(v2) <- true let remove_edge g v1 v2 = g.(v1).(v2) <- false let iter_succ f g v = Array.iteri (fun w b -> if b then f w) g.(v) let iter_edge f g = for v = 0 to nb_vertex g - 1 do iter_succ (f v) g v done
This document was generated using caml2html