The IntervalSetFn
functor provides sets over a discrete ordered domain,
where the sets are represented by intervals. It is meant for representing
dense sets (e.g., unicode character classes).
Synopsis
signature INTERVAL_SET
functor IntervalSetFn (D : INTERVAL_DOMAIN) : INTERVAL_SET
Functor Argument Description
D : INTERVAL_DOMAIN
-
The argument defines the type of points in the domain and their order structure.
Interface
structure D : INTERVAL_DOMAIN
type item = D.point
type interval = (item * item)
type set
val empty : set
val universe : set
val singleton : item -> set
val interval : item * item -> set
val isEmpty : set -> bool
val isUniverse : set -> bool
val member : set * item -> bool
val items : set -> item list
val intervals : set -> interval list
val add : set * item -> set
val add' : item * set -> set
val addInt : set * interval -> set
val addInt' : interval * set -> set
val complement : set -> set
val union : (set * set) -> set
val intersect : (set * set) -> set
val difference : (set * set) -> set
val app : (item -> unit) -> set -> unit
val foldl : (item * 'a -> 'a) -> 'a -> set -> 'a
val foldr : (item * 'a -> 'a) -> 'a -> set -> 'a
val filter : (item -> bool) -> set -> set
val exists : (item -> bool) -> set -> bool
val all : (item -> bool) -> set -> bool
val appInt : (interval -> unit) -> set -> unit
val foldlInt : (interval * 'a -> 'a) -> 'a -> set -> 'a
val foldrInt : (interval * 'a -> 'a) -> 'a -> set -> 'a
val filterInt : (interval -> bool) -> set -> set
val existsInt : (interval -> bool) -> set -> bool
val allInt : (interval -> bool) -> set -> bool
val compare : set * set -> order
val isSubset : set * set -> bool
Interface Description
structure D : INTERVAL_DOMAIN
-
The argument structure.
type item = D.point
-
The type of items in the set.
type interval = (item * item)
-
A collection of items defined by an interval.
type set
-
The type of a set of items.
val empty : set
-
The empty set.
val universe : set
-
The set of all elements in the domain, which is specified as the interval
(D.minPt, D.maxPt)
. val singleton : item -> set
-
singleton item
returns the singleton set containingitem
. val fromList : item list -> set
-
fromList items
returns the set containing the list of items. val interval : item * item -> set
-
singleton (pt1, pt2)
returns a set containing the items between the itemspt1
andpt2
(as ordered byD.compare
). This expression raises theDomain
exception ifD.compare(pt1, pt2) = GREATER
. val isEmpty : set -> bool
-
isEmpty set
returnstrue
if, and only if,set
is empty. val isUniverse : set -> bool
-
isUniverse set
returnstrue
if, and only if,set
contains all of the elements of the domain. val member : set * item -> bool
-
isEmpty (set, item)
returnstrue
if, and only if,item
is contained inset
.
val toList : set -> item list
-
toList set
returns a list of the items inset
. The items will be sorted in increasing order. val intervals : set -> interval list
-
intervals set
returns a list of disjoint intervals that represents the set. The intervals will be sorted in increasing order. val add : set * item -> set
-
add (set, item)
addsitem
toset
and returns the resulting set. val add' : item * set -> set
-
add' (item, set)
addsitem
toset
and returns the resulting set.(* add an interval to the set *)
val addInt : set * interval -> set
-
addInt (set, (pt1, pt2))
adds the items between the itemspt1
andpt2
(as ordered byD.compare
) toset
. This expression raises theDomain
exception ifD.compare(pt1, pt2) = GREATER
. val addInt' : interval * set -> set
-
addInt' ((pt1, pt2), set)
adds the items between the itemspt1
andpt2
(as ordered byD.compare
) toset
. This expression raises theDomain
exception ifD.compare(pt1, pt2) = GREATER
. val complement : set -> set
-
complement set
returns the complement ofset
(i.e., the set of items from the universe that are not inset
). val union : (set * set) -> set
-
union (set1, set2)
returns the union ofset1
andset2
; (i.e., the set of items that are inset1
or inset2
). val intersect : (set * set) -> set
-
intersect (set1, set2)
returns the intersection ofset1
andset2
; (i.e., the set of items that are in bothset1
and`set2`). val difference : (set * set) -> set
-
difference (set1, set2)
returns the set difference ofset1
andset2
; (i.e., the set of items that are inset1
, but not inset2
). val app : (item -> unit) -> set -> unit
-
app f set
applies the functionf
to the items inset
. This expression is equivalent toList.app f (toList set)
val foldl : (item * 'a -> 'a) -> 'a -> set -> 'a
-
foldl f init set
folds the functionf
over the items inset
in increasing order usinginit
as the initial value. This expression is equivalent toList.foldl f init (toList set)
val foldr : (item * 'a -> 'a) -> 'a -> set -> 'a
-
foldr f init set
folds the functionf
over the items inset
in decreasing order usinginit
as the initial value. This expression is equivalent toList.foldr f init (toList set)
val filter : (item -> bool) -> set -> set
-
filter pred set
filters out any items of set for which the predicatepred
returns false. val exists : (item -> bool) -> set -> bool
-
exists pred set
returnstrue
if, and only if, there is an item in the set for whichpred
returnstrue
. This function short-circuits evaluation once an item is encountered for whichpred
returnstrue
. val all : (item -> bool) -> set -> bool
-
all pred set
returnstrue
if, and only if,pred
returnstrue
for all items in the set. This function short-circuits evaluation once an item is encountered for whichpred
returnsfalse
. val appInt : (interval -> unit) -> set -> unit
-
appInt f set
applies the functionf
to the intervals inset
. This expression is equivalent toList.app f (intervals set)
val foldlInt : (interval * 'a -> 'a) -> 'a -> set -> 'a
-
foldlInt f init set
folds the functionf
over the intervals inset
in increasing order usinginit
as the initial value. This expression is equivalent toList.foldl f init (intervals set)
val foldrInt : (interval * 'a -> 'a) -> 'a -> set -> 'a
-
foldrInt f init set
folds the functionf
over the intervals inset
in decreasing order usinginit
as the initial value. This expression is equivalent toList.foldr f init (intervals set)
val filterInt : (interval -> bool) -> set -> set
-
filterInt pred set
filters out any intervals of set for which the predicatepred
returns false. val existsInt : (interval -> bool) -> set -> bool
-
existsInt pred set
returnstrue
if, and only if, there is an interval in the set for whichpred
returnstrue
. This function short-circuits evaluation once an interval is encountered for whichpred
returnstrue
. val allInt : (interval -> bool) -> set -> bool
-
allInt pred set
returnstrue
if, and only if,pred
returnstrue
for all of the intervals in the set. This function short-circuits evaluation once an interval is encountered for whichpred
returnsfalse
. val compare : set * set -> order
-
compare (set1, set2)
returns the lexical order of the two sets. val isSubset : set * 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
).
Deprecated functions
The following functions are part of the interface, but have been deprecated.
val items : set -> item list`
-
Use
toList
instead.