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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 251 - (download) (annotate)
Mon Apr 19 02:55:26 1999 UTC (20 years, 10 months ago) by monnier
File size: 1362 byte(s)
First try at a merge of 110.16
(* copyright 1998 YALE FLINT PROJECT *)

signature INTSETF =
sig
    type intset
    val empty : intset
    val singleton: int -> intset
    val make: int list -> intset

    val size: intset -> int
    val isEmpty: intset -> bool

    val add: int * intset -> intset
    val rmv: int * intset -> intset
    val member : intset -> int -> bool

    val union : intset * intset -> intset
    val diff : intset * intset -> intset
    val inter : intset * intset -> intset

    val members: intset -> int list
    val fold: (int * 'a -> 'a) -> 'a -> intset -> 'a
end

structure IntSetF :> INTSETF =
struct
local
    structure M = IntmapF
(*      fun bug msg = ErrorMsg.impossible ("IntSetF: "^msg) *)
(*      fun assert p = if p then () else bug ("assertion failed") *)
in
    type intset = unit M.intmap

    val empty = M.empty
    fun size s = M.cardinality s
    fun add (i,s) = M.add(s, i, ())
    fun rmv (i,s) = M.delete(i, s)
    fun member s i = (M.lookup s i; true) handle M.IntmapF => false

    fun union (s1,s2) = M.overlay(s1, s2)
    fun diff (s1,s2) = M.difference(s1, s2)
    fun inter (s1,s2) = diff(s1, diff(s1, s2))

    fun members s = map #1 (M.members s)
    fun fold f b s = M.fold (fn (x,(),r) => f(x, r)) b s

    fun singleton i = add(i, empty)
    fun make is = foldl add empty is
    fun isEmpty s = size s = 0

end
end

(*
 * $Log$
 *)

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