Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/comp-lib/intsetf.sml
ViewVC logotype

Annotation of /sml/trunk/src/comp-lib/intsetf.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 122 - (view) (download)

1 : monnier 122 (* copyright 1998 YALE FLINT PROJECT *)
2 :    
3 :     signature INTSETF =
4 :     sig
5 :     type intset
6 :     val empty : intset
7 :     val singleton: int -> intset
8 :     val make: int list -> intset
9 :    
10 :     val size: intset -> int
11 :     val isEmpty: intset -> bool
12 :    
13 :     val add: int * intset -> intset
14 :     val rmv: int * intset -> intset
15 :     val member : intset -> int -> bool
16 :    
17 :     val union : intset * intset -> intset
18 :     val diff : intset * intset -> intset
19 :     val inter : intset * intset -> intset
20 :    
21 :     val members: intset -> int list
22 :     val fold: (int * 'a -> 'a) -> 'a -> intset -> 'a
23 :     end
24 :    
25 :     structure IntSetF :> INTSETF =
26 :     struct
27 :     local
28 :     structure M = IntmapF
29 :     (* fun bug msg = ErrorMsg.impossible ("IntSetF: "^msg) *)
30 :     (* fun assert p = if p then () else bug ("assertion failed") *)
31 :     in
32 :     type intset = unit M.intmap
33 :    
34 :     val empty = M.empty
35 :     fun size s = M.cardinality s
36 :     fun add (i,s) = M.add(s, i, ())
37 :     fun rmv (i,s) = M.delete(i, s)
38 :     fun member s i = (M.lookup s i; true) handle M.IntmapF => false
39 :    
40 :     fun union (s1,s2) = M.overlay(s1, s2)
41 :     fun diff (s1,s2) = M.difference(s1, s2)
42 :     fun inter (s1,s2) = diff(s1, diff(s1, s2))
43 :    
44 :     fun members s = map #1 (M.members s)
45 :     fun fold f b s = M.fold (fn (x,(),r) => f(x, r)) b s
46 :    
47 :     fun singleton i = add(i, empty)
48 :     fun make is = foldl add empty is
49 :     fun isEmpty s = size s = 0
50 :    
51 :     end
52 :     end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0