The unpac monorepo manager self-hosting as a monorepo using unpac
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

new functions Classic.{cycle,grid}

+64 -4
+1
CHANGES.md
··· 1 1 2 + - [Classic]: new functions [cycle] and [grid] 2 3 - [Eulerian]: Eulerian paths (new module) 3 4 currently limited to undirected graphs 4 5 - [Components]: strong articulation points (see functors [Connectivity]
+27
src/classic.ml
··· 19 19 20 20 module type S = sig 21 21 type graph 22 + type vertex 22 23 val divisors : int -> graph 23 24 val de_bruijn : int -> graph 24 25 val vertex_only : int -> graph 25 26 val full : ?self:bool -> int -> graph 27 + val cycle : int -> graph * vertex array 28 + val grid : n:int -> m:int -> graph * vertex array array 26 29 end 27 30 28 31 module Generic(B : Builder.INT) = struct 29 32 30 33 type graph = B.G.t 34 + 35 + type vertex = B.G.V.t 31 36 32 37 let divisors n = 33 38 if n < 2 then invalid_arg "divisors"; ··· 77 82 (fun g j -> if self || i <> j then B.add_edge g v.(i) v.(j) else g) 78 83 g) 79 84 (fold_for 1 n (fun g i -> B.add_vertex g v.(i)) (B.empty ())) 85 + 86 + let cycle n = 87 + if n < 0 then invalid_arg "cycle"; 88 + let v = Array.init n (fun i -> B.G.V.create i) in 89 + let g = Array.fold_left B.add_vertex (B.empty ()) v in 90 + let rec loop g i = 91 + if i = n then g 92 + else let g = B.add_edge g v.(i) v.((i+1) mod n) in loop g (i+1) in 93 + loop g 0, v 94 + 95 + let grid ~n ~m = 96 + if n < 0 || m < 0 then invalid_arg "grid"; 97 + let create i j = B.G.V.create (m * i + j) in 98 + let v = Array.init n (fun i -> Array.init m (fun j -> create i j)) in 99 + let g = Array.fold_left (Array.fold_left B.add_vertex) (B.empty ()) v in 100 + let rec loop g i j = 101 + if i = n then g 102 + else if j = m then loop g (i+1) 0 103 + else let g = if j < m-1 then B.add_edge g v.(i).(j) v.(i).(j+1) else g in 104 + let g = if i < n-1 then B.add_edge g v.(i).(j) v.(i+1).(j) else g in 105 + loop g i (j+1) in 106 + loop g 0 0, v 80 107 81 108 end 82 109
+18 -4
src/classic.mli
··· 15 15 (* *) 16 16 (**************************************************************************) 17 17 18 - (* $Id: classic.mli,v 1.12 2005-02-25 13:54:33 signoles Exp $ *) 19 - 20 18 (** Some classic graphs *) 21 19 22 20 module type S = sig 23 21 24 22 type graph 23 + 24 + type vertex 25 25 26 26 val divisors : int -> graph 27 27 (** [divisors n] builds the graph of divisors. ··· 45 45 The optional argument [self] indicates if loop edges should be added 46 46 (default value is [true]). *) 47 47 48 + val cycle : int -> graph * vertex array 49 + (** [cycle n] builds a graph that is a cycle with [n] vertices. 50 + Vertices are labelled with [0,1,...,n-1] and there is an edge from 51 + vertex [i] to vertex [(i+1) mod n]. 52 + Vertices are also returned in an array for convenience. *) 53 + 54 + val grid : n:int -> m:int -> graph * vertex array array 55 + (** [grid n m] builds a grid graph with [n*m] vertices, with edges 56 + from vertex [(i,j)] to vertices [(i+1,j)] and [(i,j+1)] (and no 57 + wrapping around). Vertex [(i,j)] is labelled with [i*m+j]. 58 + Vertices are also returned in a [n*m] matrix for convenience. *) 59 + 48 60 end 49 61 50 - module P (G : Sig.P with type V.label = int) : S with type graph = G.t 62 + module P (G : Sig.P with type V.label = int) : 63 + S with type graph = G.t and type vertex = G.V.t 51 64 (** Classic Persistent Graphs *) 52 65 53 - module I (G : Sig.I with type V.label = int) : S with type graph = G.t 66 + module I (G : Sig.I with type V.label = int) : 67 + S with type graph = G.t and type vertex = G.V.t 54 68 (** Classic Imperative Graphs *)
+12
src/sig_pack.mli
··· 344 344 (** [full n] builds a graph with [n] vertices and all possible edges. 345 345 The optional argument [self] indicates if loop edges should be added 346 346 (default value is [true]). *) 347 + 348 + val cycle : int -> t * V.t array 349 + (** [cycle n] builds a graph that is a cycle with [n] vertices. 350 + Vertices are labelled with 0,1,...,n-1 and there is an edge from 351 + vertex [i] to vertex [(i+1) mod n]. 352 + Vertices are also returned in an array for convenience. *) 353 + 354 + val grid : n:int -> m:int -> t * V.t array array 355 + (** [grid n m] builds a grid graph with [n*m] vertices, with edges 356 + from vertex [(i,j)] to vertices [(i+1,j)] and [(i,j+1)] (and no 357 + wrapping around). Vertex [(i,j)] is labelled with [i*m+j]. 358 + Vertices are also returned in a [n*m] matrix for convenience. *) 347 359 end 348 360 349 361 (** Random graphs *)
+6
tests/test_eulerian.ml
··· 88 88 assert c; 89 89 assert (List.length p = (n+1)*(2*n+1)) 90 90 done 91 + 92 + (* let () = 93 + * let g, _ = Classic.grid ~n:2 ~m:3 in 94 + * assert (exists_path g); 95 + * assert (not (exists_cycle g)) *) 96 +