mask.texi 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. @node Boxed bitwise-integer masks
  2. @section Boxed bitwise-integer masks
  3. @stindex mask-types
  4. @stindex masks
  5. Scheme48 provides a facility for generalized boxed bitwise-integer
  6. masks. Masks represent sets of elements. An element is any arbitrary
  7. object that represents an index into a bit mask; mask types are
  8. parameterized by an isomorphism between elements and their integer
  9. indices. Usual abstract set operations are available on masks. The
  10. mask facility is divided into two parts: the @code{mask-types}
  11. structure, which provides the operations on the generalized mask type
  12. descriptors; and the @code{masks} structure, for the operations on
  13. masks themselves.
  14. @subsection Mask types
  15. @deffn procedure make-mask-type name elt? index->elt elt->index size @returns{} mask-type
  16. @deffnx procedure mask-type? object @returns{} boolean
  17. @deffnx procedure mask? object @returns{} boolean
  18. @code{Make-mask-type} constructs a mask type with the given name.
  19. Elements of this mask type must satisfy the predicate @var{elt?}.
  20. @var{Integer->elt} is a unary procedure that maps bit mask indices to
  21. possible set elements; @var{elt->integer} maps possible set elements to
  22. bit mask indices. @var{Size} is the number of possible elements of
  23. masks of the new type, @ie{} the number of bits needed to represent the
  24. internal bit mask. @code{Mask?} is the disjoint type predicate for
  25. mask objects.
  26. @end deffn
  27. @deffn procedure mask-type mask @returns{} mask-type
  28. @deffnx procedure mask-has-type? mask type @returns{} boolean
  29. @code{Mask-type} returns @var{mask}'s type. @code{Mask-has-type?}
  30. returns @code{#t} if @var{mask}'s type is the mask type @var{type} or
  31. @code{#f} if not.
  32. @end deffn
  33. The @code{mask-types} structure, not the @code{masks} structure,
  34. exports @code{mask?} and @code{mask-has-type?}: it is expected that
  35. programmers who implement mask types will define type predicates for
  36. masks of their type based on @code{mask?} and @code{mask-has-type?},
  37. along with constructors @etc{} for their masks.
  38. @deffn procedure integer->mask type integer @returns{} mask
  39. @deffnx procedure list->mask type elts @returns{} mask
  40. @code{Integer->mask} returns a mask of type @var{type} that contains
  41. all the possible elements @var{e} of the type @var{type} such that
  42. the bit at @var{e}'s index is set. @code{List->mask} returns a mask
  43. whose type is @var{type} containing all of the elements in the list
  44. @var{elts}.
  45. @end deffn
  46. @subsection Masks
  47. @deffn procedure mask->integer mask @returns{} integer
  48. @deffnx procedure mask->list mask @returns{} element-list
  49. @code{Mask->integer} returns the integer bit set that @var{mask} uses
  50. to represent the element set. @code{Mask->list} returns a list of all
  51. the elements that @var{mask} contains.
  52. @end deffn
  53. @deffn procedure mask-member? mask elt @returns{} boolean
  54. @deffnx procedure mask-set mask elt @dots{} @returns{} mask
  55. @deffnx procedure mask-clear mask elt @dots{} @returns{} mask
  56. @code{Mask-member?} returns true if @var{elt} is a member of the mask
  57. @var{mask}, or @code{#f} if not. @code{Mask-set} returns a mask with
  58. all the elements in @var{mask} as well as each @var{elt} @dots{}.
  59. @code{Mask-clear} returns a mask with all the elements in @var{mask}
  60. but with none of @var{elt} @dots{}.
  61. @end deffn
  62. @deffn procedure mask-union mask@sub{1} mask@sub{2} @dots{} @returns{} mask
  63. @deffnx procedure mask-intersection mask@sub{1} mask@sub{2} @dots{} @returns{} mask
  64. @deffnx procedure mask-subtract mask@suba{a} mask@suba{b} @returns{} mask
  65. @deffnx procedure mask-negate mask @returns{} mask
  66. Set operations on masks. @code{Mask-union} returns a mask containing
  67. every element that is a member of any one of its arguments.
  68. @code{Mask-intersection} returns a mask containing every element that
  69. is a member of every one of its arguments. @code{Mask-subtract}
  70. returns a mask of every element that is in @var{mask@suba{a}} but not
  71. also in @var{mask@suba{b}}. @code{Mask-negate} returns a mask whose
  72. members are every possible element of @var{mask}'s type that is not in
  73. @var{mask}.
  74. @end deffn