Import Upstream version 20180207
[hcoop/debian/mlton.git] / lib / mlton / set / test.sml
CommitLineData
7f918cf1
CE
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
8structure S = UnorderedUniverse(Integer)
9
10
11structure S = SetEqual(structure Element = Integer)
12
13open S
14
15val s = listTo[1, 2, 3, 4]
16
17val ss = subsets s 3
18
19structure D = DisjointMax(structure Label = struct open Int open IU end) ;
20
21open D ;
22
23val ss = LU.mapFromTo 0 10 singleton ;
24
25val s = LU.nth ss ;
26
27 LU.map ss eval ;
28
29fun u i n = update (s i) n ;
30fun l i j = link (s i) (s j) ;
31fun 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
44open DisjointCollection ;
45
46val (c, ss) = new (LU.fromTo 0 10) ;
47
48fun s i = LU.nth ss i ;
49fun r() = randomSet c ;
50fun u i j = union c (s i) (s j) ;
51fun n() = numSets c ;
52fun v i = value c (s i) ;
53
54r() ;
55
56n() ;
57
58value c (r()) ;
59
60LU.map (LU.fromTo 0 10) v ;
61
62u 1 2 ;
63
64u 2 3 ;
65
66u 3 4 ;
67
68u 1 3 ;
69
70u 2 4 ;
71
72open DisjointSet ;
73
74val elts = LU.mapFromTo 0 9 singleton ;
75
76val n = ListUtil.nth elts ;
77fun e i j = areEquivalent (n i) (n j) ;
78fun 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
88u 1 2 ;
89e 1 2 ;
90e 1 3 ;
91
92u 3 4 ;
93
94u 5 6 ;
95
96u 1 4 ;
97
98e 2 3 ;
99
100u 5 1 ;
101
102e 6 4 ;
103
104u 7 8 ;
105u 9 0 ;
106
107u 8 9 ;
108
109u 1 7 ;
110
111elts ;