|
|
1.1 ! root 1: (* Copyright 1989 by AT&T Bell Laboratories *) ! 2: structure Intset : sig type intset ! 3: val new : unit -> intset ! 4: val add : intset -> int -> unit ! 5: val rem : intset -> int -> unit ! 6: val mem : intset -> int -> bool ! 7: end = ! 8: ! 9: struct ! 10: val p = 211 ! 11: type intset = int list array ! 12: fun new () = array(p,nil : int list) ! 13: fun add a i = let val index = i mod p in update(a,index,i::(a sub index)) end ! 14: fun mem a i = exists (fn j => j=i) (a sub (i mod p)) ! 15: fun rem a i = let fun f (j::r) = if i=j then f r else j :: f r ! 16: | f nil = nil ! 17: val index = i mod p ! 18: in update(a,index, f(a sub index)) ! 19: end ! 20: (* ! 21: type intset = unit Intmap.intmap ! 22: exception NO ! 23: fun new () = Intmap.new(32, NO) ! 24: fun add a i = Intmap.add a (i,()) ! 25: fun mem a i = (Intmap.map a i; true) handle NO => false ! 26: fun rem a i = Intmap.rem a i ! 27: *) ! 28: end ! 29:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.