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/intset.sml
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 419 - (view) (download)

1 : monnier 245 (* Copyright 1989 by AT&T Bell Laboratories *)
2 : monnier 411 (* replaced with int-binary-set.sml
3 :     new == fn () => empty
4 :     add s x == add(s,x)
5 :     rmv s x == delete(s,x)
6 :     mem s x == member(s,x)
7 :     *)
8 : monnier 245 structure Intset : sig type intset
9 :     val new : unit -> intset
10 :     val add : intset -> int -> unit
11 :     val rmv : intset -> int -> unit
12 :     val mem : intset -> int -> bool
13 :     end =
14 :    
15 :     struct
16 :     open Array List
17 :     infix 9 sub
18 :    
19 :     val p = 211
20 :     type intset = int list array
21 :     fun new () = array(p,nil : int list)
22 :     fun add a i = let val index = i mod p in update(a,index,i::(a sub index)) end
23 :     fun mem a i = exists (fn j => j=i) (a sub (i mod p))
24 :     fun rmv a i = let fun f (j::r) = if i=j then f r else j :: f r
25 :     | f nil = nil
26 :     val index = i mod p
27 :     in update(a,index, f(a sub index))
28 :     end
29 :     (*
30 :     type intset = unit Intmap.intmap
31 :     exception NO
32 :     fun new () = Intmap.new(32, NO)
33 :     fun add a i = Intmap.add a (i,())
34 :     fun mem a i = (Intmap.map a i; true) handle NO => false
35 :     fun rmv a i = Intmap.rem a i
36 :     *)
37 :     end
38 :    
39 :    
40 : monnier 411

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