Next: Enumerated/finite types and sets, Up: Libraries
Scheme48 provides a facility for generalized boxed bitwise-integer
masks. Masks represent sets of elements. An element is any arbitrary
object that represents an index into a bit mask; mask types are
parameterized by an isomorphism between elements and their integer
indices. Usual abstract set operations are available on masks. The
mask facility is divided into two parts: the mask-types
structure, which provides the operations on the generalized mask type
descriptors; and the masks
structure, for the operations on
masks themselves.
Make-mask-type
constructs a mask type with the given name. Elements of this mask type must satisfy the predicate elt?. Integer->elt is a unary procedure that maps bit mask indices to possible set elements; elt->integer maps possible set elements to bit mask indices. Size is the number of possible elements of masks of the new type, i.e. the number of bits needed to represent the internal bit mask.Mask?
is the disjoint type predicate for mask objects.
Mask-type
returns mask's type.Mask-has-type?
returns#t
if mask's type is the mask type type or#f
if not.
The mask-types
structure, not the masks
structure,
exports mask?
and mask-has-type?
: it is expected that
programmers who implement mask types will define type predicates for
masks of their type based on mask?
and mask-has-type?
,
along with constructors &c. for their masks.
Integer->mask
returns a mask of type type that contains all the possible elements e of the type type such that the bit at e's index is set.List->mask
returns a mask whose type is type containing all of the elements in the list elts.
Mask->integer
returns the integer bit set that mask uses to represent the element set.Mask->list
returns a list of all the elements that mask contains.
Mask-member?
returns true if elt is a member of the mask mask, or#f
if not.Mask-set
returns a mask with all the elements in mask as well as each elt ....Mask-clear
returns a mask with all the elements in mask but with none of elt ....
Set operations on masks.
Mask-union
returns a mask containing every element that is a member of any one of its arguments.Mask-intersection
returns a mask containing every element that is a member of every one of its arguments.Mask-subtract
returns a mask of every element that is in maska but not also in maskb.Mask-negate
returns a mask whose members are every possible element of mask's type that is not in mask.