File: test_fixpoint.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 (47 lines) | stat: -rw-r--r-- 1,141 bytes parent folder | download | duplicates (3)
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
42
43
44
45
46
47

(* Test file for Fixpoint *)

let id x = x
module IntOrdered = struct
  type t = int
  let compare: int -> int -> int = compare
  let hash: int -> int = id
  let equal: int -> int -> bool = (=)
end
module IntSet = Set.Make(IntOrdered)
module G = Graph.Persistent.Digraph.Concrete(IntOrdered)
module Divisors = Graph.Classic.P(G)
module Analysis = struct
  type data = IntSet.t
  type edge = G.edge
  type vertex = G.vertex
  type g = G.t
  let direction = Graph.Fixpoint.Backward
  let join = IntSet.union
  let equal = IntSet.equal
  let analyze (_: edge): data -> data = id
end
module Fixpoint = Graph.Fixpoint.Make(G)(Analysis)

let pp_int_set pp set =
  let first = ref true in
  Format.fprintf pp "@[<hov>";
  IntSet.iter (fun x ->
      if !first then
	first := false
      else 
	Format.fprintf pp ",@ ";
      Format.pp_print_int pp x)
    set;
  Format.fprintf pp "@]"

let () =
  let n = 15 in
  let labels = Fixpoint.analyze IntSet.singleton (Divisors.divisors n) in
  Format.open_vbox 0;
  for i = 2 to n do
    Format.printf "Labels for %d: %a@," i pp_int_set (labels i)
  done;
  Format.close_box ();
  Format.print_flush ()