Backport from sid to buster
[hcoop/debian/mlton.git] / lib / mlton / set / test.sml
1 (* Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh
2 * Jagannathan, and Stephen Weeks.
3 *
4 * MLton is released under a BSD-style license.
5 * See the file MLton-LICENSE for details.
6 *)
7
8 structure S = UnorderedUniverse(Integer)
9
10
11 structure S = SetEqual(structure Element = Integer)
12
13 open S
14
15 val s = listTo[1, 2, 3, 4]
16
17 val ss = subsets s 3
18
19 structure D = DisjointMax(structure Label = struct open Int open IU end) ;
20
21 open D ;
22
23 val ss = LU.mapFromTo 0 10 singleton ;
24
25 val s = LU.nth ss ;
26
27 LU.map ss eval ;
28
29 fun u i n = update (s i) n ;
30 fun l i j = link (s i) (s j) ;
31 fun e i = eval (s i) ;
32
33 l 3 6 ;
34
35 l 3 7 ;
36
37 l 8 3 ;
38
39 l 8 10 ;
40
41 u 8 11 ;
42
43
44 open DisjointCollection ;
45
46 val (c, ss) = new (LU.fromTo 0 10) ;
47
48 fun s i = LU.nth ss i ;
49 fun r() = randomSet c ;
50 fun u i j = union c (s i) (s j) ;
51 fun n() = numSets c ;
52 fun v i = value c (s i) ;
53
54 r() ;
55
56 n() ;
57
58 value c (r()) ;
59
60 LU.map (LU.fromTo 0 10) v ;
61
62 u 1 2 ;
63
64 u 2 3 ;
65
66 u 3 4 ;
67
68 u 1 3 ;
69
70 u 2 4 ;
71
72 open DisjointSet ;
73
74 val elts = LU.mapFromTo 0 9 singleton ;
75
76 val n = ListUtil.nth elts ;
77 fun e i j = areEquivalent (n i) (n j) ;
78 fun u i j = union (n i) (n j) ;
79
80 u 1 3 ; u 2 3 ; e 1 2 ;
81
82 u 1 3 ; e 1 3 ;
83
84 u 2 3 ; e 1 3 ;
85
86 u 2 4 ; u 1 4 ; u 1 3 ; e 1 2 ;
87
88 u 1 2 ;
89 e 1 2 ;
90 e 1 3 ;
91
92 u 3 4 ;
93
94 u 5 6 ;
95
96 u 1 4 ;
97
98 e 2 3 ;
99
100 u 5 1 ;
101
102 e 6 4 ;
103
104 u 7 8 ;
105 u 9 0 ;
106
107 u 8 9 ;
108
109 u 1 7 ;
110
111 elts ;