This site is a static rendering of the Trac instance that was used by R7RS-WG1 for its work on R7RS-small (PDF), which was ratified in 2013. For more information, see Home. For a version of this page that may be more recent, see IntegerSetsCowan in WG2's repo for R7RS-large.

# Integer­Sets­Cowan

2014-08-15 02:47:57
source

## Integer set procedures

The elements of an integer set are non-negative exact integers less than the set's limit, which is specified instead of a comparator when it is created. The procedures for creating and manipulating integer sets are the same as those for SRFI 113 sets, except that `set` is replaced by `integer-set` in their names, that `set-comparator` is replaced by `integer-set-limit`, and that in `integer-set`, `integer-set-unfold`, `integer-set-map`, and `integer-set-copy` the comparator argument is replaced by a limit argument, a non-negative integer.

Wherever a newly allocated integer set is returned by any other procedure, it has the same limit as the source sets. It is an error for a single procedure to be invoked on integer sets with different limits.

Although sets subsume integer sets, providing them separately allows for increased implementation efficiency. There are two Chicken eggs that provide integer sets: `iset`, which is conceptually similar to the integer sets described here; and `cis`, which uses lists of integer intervals.

`(integer-set-limit `integer-set`)`

Returns the limit of integer-set. This procedure corresponds to `set-comparator`.

`(universal-integer-set `limit`)`

Returns a newly allocated integer set. The possible elements of the set are the exact integers from 0 to limit - 1, where limit is an exact non-negative integer. The set contains all possible elements.

`(range->integer-set `limit low high`)`

Returns a newly allocated integer set. The possible elements of the set are the exact integers from 0 to limit - 1, where limit is an exact non-negative integer. The set contains the elements from low (inclusive) to high (exclusive).

`(integer-set-adjoin-range `integer-set low high`)`

Returns a newly allocated integer set with the same limit as integer-set and that contains all its values, and in addition each integer from low (inclusive) to high (exclusive) unless it is already equal to an existing member.

`(integer-set-adjoin-range! `integer-set low high`)`

A linear update procedure that returns an integer set with the same limit as integer-set and that contains all its values, and in addition each integer from low (inclusive) to high (exclusive) unless it is already equal to an existing member.

`(integer-set-complement `integer-set`)`

Returns a newly allocated integer set that is the complement of integer-set.

`(integer-set-complement! `integer-set`)`

A linear update procedure that returns a set that is the complement of integer-set.

`(integer-set-min `integer-set`)`

`(integer-set-max `integer-set`)`

Returns the smallest or largest integer in integer-set, or `#f` if there is none.

`(integer-set-delete-min! `integer-set`)`

`(integer-set-delete-max! `integer-set`)`

Linear update procedures that return two values: the smallest or largest integer in integer-set or `#f` if there is none, and a set which contains all the elements of set except the integer being returned.