The mzlib/integer-set library provides functions for
working with finite sets of integers. This module is designed for
sets that are compactly represented as groups of intervals, even when
their cardinality is large. For example, the set of integers from
-1000000 to 1000000 except for 0, can be represented as
{[-1000000, -1], [1, 1000000]}. This data structure would not be
a good choice for the set of all odd integers between 0 and
1000000, which would be {[1, 1], [3, 3], ... [999999,
999999]}.
In addition to the integer set abstract type, a
well-formed set is a list of pairs of exact integers, where
each pair represents a closed range of integers, and the entire set is
the union of the ranges. The ranges must be disjoint and increasing.
Further, adjacent ranges must have at least one integer between them.
For example: '((-1 . 2) (4 . 10)) is a well-formed-set as is
'((1 . 1) (3 . 3)), but '((1 . 5) (6 . 7)),
'((1 . 5) (-3 . -1)), '((5 . 1)), and '((1 . 5) (3 . 6)) are not.
Creates an integer set from a well-formed set.
Produces a well-formed set from an integer set.
Mutates an integer set.
Returns #t if v is an integer set, #f
otherwise.
Returns #t if v is a well-formed set, #f
otherwise.
Produces, respectively, an empty integer set, an integer set
containing only
elem, or an integer set containing the
integers from
start to
end inclusive, where
(<= start end).
Returns the intersection of the given sets.
Returns the difference of the given sets (i.e., elements in x
that are not in y).
Returns the union of the given sets.
Produces three values: the first is the intersection of x and
y, the second is the difference x remove y,
and the third is the difference y remove x.
Returns the a set containing the elements between start to
end inclusive that are not in s, where
(<= start-k end-k).}
Returns an integer set containing every member of x
and y that is not in both sets.
Returns #t if k is in s, #f
otherwise.
Returns a member of integer-set, or #f if
integer-set is empty.
Applies
proc to each member of
s in ascending order,
where the first argument to
proc is the set member, and the
second argument is the fold result starting with
base-v. For
example,
(foldr cons null s) returns a list of all the
integers in
s, sorted in increasing order.
Returns the coarsest refinement of the sets in s such that
the sets in the result list are pairwise disjoint. For example,
partitioning the sets that represent '((1 . 2) (5 . 10)) and
'((2 . 2) (6 . 6) (12 . 12)) produces the a list containing
the sets for '((1 . 1) (5 . 5) (7 . 10)) '((2 . 2) (6 . 6)), and '((12 . 12)).
Returns the number of integers in the given integer set.
Returns true if every integer in x is also in
y, otherwise #f.