File: test_components.ml

package info (click to toggle)
ocamlgraph 2.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,624 kB
  • sloc: ml: 19,995; xml: 151; makefile: 14; sh: 1
file content (41 lines) | stat: -rw-r--r-- 1,786 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
(**************************************************************************)
(*                                                                        *)
(*  Ocamlgraph: a generic graph library for OCaml                         *)
(*  Copyright (C) 2004-2007                                               *)
(*  Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles        *)
(*                                                                        *)
(*  This software is free software; you can redistribute it and/or        *)
(*  modify it under the terms of the GNU Library General Public           *)
(*  License version 2, with the special exception on linking              *)
(*  described in file LICENSE.                                            *)
(*                                                                        *)
(*  This software is distributed in the hope that it will be useful,      *)
(*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *)
(*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                  *)
(*                                                                        *)
(**************************************************************************)

open Format
open Graph

module C = Components.Undirected(Pack.Graph)

open Pack.Graph

(*         0 -- 2 -- 7   1   3 -- 4   5
                             \  /
                               6

component:      0        1     2      3
*)

let () =
  let g = create () in
  let v = Array.init 8 V.create in
  Array.iter (add_vertex g) v;
  let add i j = add_edge g v.(i) v.(j) in
  add 0 2; add 7 2; add 3 4; add 4 6; add 3 6;
  let n, f = C.components g in
  printf "%d components@." n;
  iter_vertex (fun v -> printf "%d -> %d@." (V.label v) (f v)) g