# LispKit Bitset

Library `(lispkit bitset)` implements bit sets of arbitrary size. Bit sets are mutable objects. The API of library `(lispkit bitset)` provides functionality to create, to inspect, to compose, and to mutate bit sets efficiently.

bitset-type-tag [object]

Symbol representing the `bitset` type. The `type-for` procedure of library `(lispkit type)` returns this symbol for all bitset objects.

(bitset? obj) [procedure]

Returns `#t` if obj is a bit set, `#f` otherwise.

(bitset i …) [procedure]

Returns a new bit set with bits i … set. Each i is a fixnum referring to one bit in the bit set by its ordinality.

(list->bitset list) [procedure]

Returns a new bit set with bits specified by list. Each element in list is a fixnum referring to one bit in the bit set by its ordinality.

(fixnum->bitset x) [procedure]

Returns a bit set with all bits set that are set in fixnum x.

(bitset-copy bs) [procedure]

Returns a copy of bit set bs.

(bitset-size bs) [procedure]

Returns the number of bits set in bit set bs.

(bitset-next bs) [procedure]
(bitset-next bs i)

Returns the next bit set in bs following bit i. If i is not provided, the first bit set in bs is returned.

(bitset-empty? bs) [procedure]

Returns `#t` if bit set bs is empty, `#f` otherwise.

(bitset-disjoint? bs1 bs2) [procedure]

Returns `#t` if bit sets bs1 and bs2 are disjoint, `#f` otherwise.

(bitset-subset? bs1 bs2) [procedure]

Returns `#t` if bit set bs2 is a subset of bit set bs2, `#f` otherwise.

(bitset-contains? bs i …) [procedure]

Returns `#t` if all bits i … are set in bit set bs, `#f` otherwise.

(bitset-adjoin! bs i …) [procedure]

Inserts the bits i … into bit set bs. `bitset-adjoin!` returns bs.

(bitset-adjoin-all! bs list) [procedure]

Inserts all the bits specified by list into bit set bs. Each element in list is a fixnum referring to one bit in the bit set by its ordinality. `bitset-adjoin-all!` returns bs.

(bitset-delete! bs i …) [procedure]

Removes the bits i … from bit set bs. `bitset-delete!` returns bs.

(bitset-delete-all! bs list) [procedure]

Removes all the bits specified by list from bit set bs. Each element in list is a fixnum referring to one bit in the bit set by its ordinality. `bitset-delete-all!` returns bs.

(bitset-union! bs bs1 …) [procedure]

Computes the union of bit sets bs, bs1 … and stores the result in bs. `bitset-union!` returns bs.

(bitset-intersection! bs bs1 …) [procedure]

Computes the intersection of bit sets bs, bs1 … and stores the result in bs. `bitset-intersection!` returns bs.

(bitset-difference! bs bs1 …) [procedure]

Computes the difference between bit sets bs and bs1 … and stores the result in bs. `bitset-difference!` returns bs.

(bitset-xor! bs bs1 …) [procedure]

Computes the exclusive disjunction of bit sets bs, bs1 … and stores the result in bs. `bitset-xor!` returns bs.

(bitset=? bs bs1 …) [procedure]

Returns `#t` if the bit sets bs, bs1 … are all equal, i.e. have the same bits set. Otherwise `#f` is returned.

(bitset<? bs bs1 …) [procedure]

Returns `#t` if bs is a proper subset of bs1, and bs1 is a proper subset of bs2, etc. Otherwise `#f` is returned.

(bitset>? bs bs1 …) [procedure]

Returns `#t` if bs is a proper superset of bs1, and bs1 is a proper superset of bs2, etc. Otherwise `#f` is returned.

(bitset<=? bs bs1 …) [procedure]

Returns `#t` if bs is a subset of bs1, and bs1 is a subset of bs2, etc. Otherwise `#f` is returned.

(bitset>=? bs bs1 …) [procedure]

Returns `#t` if bs is a superset of bs1, and bs1 is a superset of bs2, etc. Otherwise `#f` is returned.

(bitset->list bs) [procedure]

Returns a list of all bits set in bs.

(bitset->fixnum bs) [procedure]

Returns a fixnum with all bits set which are also set in bit set bs. If bs includes bits that cannot be represented by a fixnum, then `bitset->fixnum` returns `#f`.

(bitset-for-each proc bs) [procedure]

Invokes proc on each bit set in bs in increasing ordinal order.

(bitset-fold proc z bs) [procedure]

The current state is initialized to z, and proc is invoked on each bit of bs in increasing ordinal order and the current state, setting the current state to the result. The algorithm is repeated until all the bits of bs have been processed. Then the current state is returned.

(bitset-any? pred bs) [procedure]

Returns `#t` if any application of pred to the bits of bs returns true, and `#f` otherwise.

(bitset-every? pred bs) [procedure]

Returns `#t` if every application of pred to the bits of bs returns true, and `#f` otherwise.

(bitset-filter pred bs) [procedure]

Returns a new bit set containing the bits from bs that satisfy pred.

(bitset-filter! pred bs) [procedure]

Removes all bits from bs for which pred returns `#f`.