The HashConsSet
structure implements finite sets of hash-consed objects.
Synopsis
signature HASH_CONS_SET
structure HashConsSet : HASH_CONS_SET
Interface
type 'a obj = 'a HashCons.obj
type 'a set
val empty : 'a set
val singleton : 'a obj -> 'a set
val fromList : 'a obj list -> 'a set
val add : 'a set * 'a obj -> 'a set
val add' : ('a obj * 'a set) -> 'a set
val addList : 'a set * 'a obj list -> 'a set
val subtract : 'a set * 'a obj -> 'a set
val subtract' : ('a obj * 'a set) -> 'a set
val subtractList : 'a set * 'a obj list -> 'a set
val delete : 'a set * 'a obj -> 'a set
val member : 'a set * 'a obj -> bool
val isEmpty : 'a set -> bool
val equal : ('a set * 'a set) -> bool
val compare : ('a set * 'a set) -> order
val isSubset : ('a set * 'a set) -> bool
val disjoint : 'a set * 'a set -> bool
val numItems : 'a set -> int
val toList : 'a set -> 'a obj list
val listItems : 'a set -> 'a obj list
val union : 'a set * 'a set -> 'a set
val intersection : 'a set * 'a set -> 'a set
val difference : 'a set * 'a set -> 'a set
val map : ('a obj -> 'b obj) -> 'a set -> 'b set
val mapPartial : ('a obj -> 'b obj option) -> 'a set -> 'b set
val app : ('a obj -> unit) -> 'a set -> unit
val foldl : ('a obj * 'b -> 'b) -> 'b -> 'a set -> 'b
val foldr : ('a obj * 'b -> 'b) -> 'b -> 'a set -> 'b
val partition : ('a obj -> bool) -> 'a set -> ('a set * 'a set)
val filter : ('a obj -> bool) -> 'a set -> 'a set
val all : ('a obj -> bool) -> 'a set -> bool
val exists : ('a obj -> bool) -> 'a set -> bool
val find : ('a obj -> bool) -> 'a set -> 'a obj option
Description
type 'a obj = 'a HashCons.obj
-
The elements in the set are hash-cons objects.
type 'a set
-
A finite set of
'a obj
values. val empty : 'a set
-
The empty set.
val singleton : 'a obj -> 'a set
-
singleton obj
creates a singleton set containingobj
. val fromList : 'a obj list -> 'a set
-
fromList objs
creates a set from the list of objects. val add : 'a set * 'a obj -> 'a set
-
add (set, obj)
adds the object to the set. val add' : ('a obj * 'a set) -> 'a set
-
add' (obj, set)
adds the object to the set. val addList : 'a set * 'a obj list -> 'a set
-
addList (set, objs)
adds the list of objects to the set. val subtract : 'a set * 'a obj -> 'a set
-
subtract (set, obj)
removes the objectobj
fromset
. Acts as the identity ifobj
is not in the set. val subtract' : ('a obj * 'a set) -> 'a set
-
subtract (obj, set)
removes the objectobj
fromset
. Acts as the identity ifobj
is not in the set. val delete : 'a set * 'a obj -> 'a set
-
delete (set, obj)
removes the objectobj
fromset
. Unlikesubtract
, this function raises theNotFound
exception ifobj
is not in the set. val member : 'a set * 'a obj -> bool
-
member (obj, set)
returnstrue
if, and only if,obj
is an element ofset
. val isEmpty : 'a set -> bool
-
isEmpty set
returns true if, and only if,set
is empty. val equal : ('a set * 'a set) -> bool
-
equal (set1, set2)
returns true if, and only if, the two sets are equal (i.e., they contain the same elements). val compare : ('a set * 'a set) -> order
-
compare (set1, set2)
returns the lexical order of the two sets. val isSubset : ('a set * 'a set) -> bool
-
isSubset (set1, set2)
returns true if, and only if,set1
is a subset ofset2
(i.e., any element ofset1
is an element ofset2
). val disjoint : 'a set * 'a set -> bool
-
equal (set1, set2)
returns true if, and only if, the two sets are disjoint (i.e., their intersection is empty). val numItems : 'a set -> int
-
numItems set
returns the number of items in theset
.
val toList : 'a set -> 'a obj list
-
toList set
returns a list of the objects inset
. val union : 'a set * 'a set -> 'a set
-
union (set1, set2)
returns the union of the two sets. val intersection : 'a set * 'a set -> 'a set
-
intersection (set1, set2)
returns the intersection of the two sets. val difference : 'a set * 'a set -> 'a set
-
difference (set1, set2)
returns the difference of the two sets; i.e., the set of objects that are inset1
, but not inset2
. val map : ('a obj -> 'b obj) -> 'a set -> 'b set
-
map f set
constructs a new set from the result of applying the functionf
to the elements ofset
. This expression is equivalent tofromList (List.map f (toList set))
val mapPartial : ('a obj -> 'b obj option) -> 'a set -> 'b set
-
mapPartial f set
constructs a new set from the result of applying the functionf
to the elements ofset
. This expression is equivalent tofromList (List.mapPartial f (toList set))
val app : ('a obj -> unit) -> 'a set -> unit
-
app f set
applies the functionf
to the objects inset
. This expression is equivalent toList.app f (toList set)
val fold : ('a obj * 'b -> 'b) -> 'b -> 'a set -> 'b
-
fold f init set
folds the functionf
over the objects inset
usinginit
as the initial value. This expression is equivalent toList.foldl f init (toList set)
Although the order in which the elements are processed is unspecified.
val partition : ('a obj -> bool) -> 'a set -> ('a set * 'a set)
-
partition pred set
returns a pair of disjoint sets(tSet, fSet)
, where the predicatepred
returns true for every element oftSet
,false
for every element offSet
, andset
is the union oftSet
andfSet
. val filter : ('a obj -> bool) -> 'a set -> 'a set
-
filter pred set
filters out any elements of set for which the predicatepred
returns false. This expression is equivalent to#1 (partition pred set)
val all : ('a obj -> bool) -> 'a set -> bool
-
all pred set
returnstrue
if, and only if,pred obj
returns true for all elementsobj
inset
. val exists : ('a obj -> bool) -> 'a set -> bool
-
exists pred set
returnstrue
if, and only if, there exists an elementobj
inset
such thatpred obj
returnstrue
. val find : ('a obj -> bool) -> 'a set -> 'a obj option
-
find pred set
returnsSOME obj
if there exists an objectobj
in the set for whichpred obj
returnstrue
; otherwiseNONE
is returned.