9 Bit Vectors
A bit vector is a mutable sequence whose elements
are booleans. A bit vector also acts as a dictionary (dict?
from racket/dict), where the keys are zero-based
indexes and the values are the elements of the bit-vector. A bit-vector
has a fixed size.
Two bit-vectors are equal? if they contain the same number of
elements and if they contain equal elements at each index.
Creates a new bit-vector of size size. All elements
are initialized to fill.
Creates a new bit-vector containing each elem in order.
Returns #t if v is a bit-vector, #f otherwise.
Returns the element at index index
, if index
than (bit-vector-length bv)
. Otherwise, default
invoked if it is a procedure, returned otherwise.
Sets the value at index index to be value.
Returns the number of items in the bit-vector bv.
Returns the number of set bits in the bit-vector bv.
Creates a fresh bit-vector with the
same elements as bv from start (inclusive)
to end (exclusive).
Returns a sequence whose elements are the elements of the bit-vector
. Mutation of bv
while the sequence is running
changes the elements produced by the sequence. To obtain a sequence
from a snapshot of bv
, use (in-bit-vector (bit-vector-copy bv))
|maybe-length|| ||=|| |
| || ||||| ||#:length length-expr|
| || ||||| ||#:length length-expr #:fill fill-expr|
Iterates like for/vector
, but results are accumulated into
a bit-vector instead of a vector.
If the optional #:length clause is specified, the result of
length-expr determines the length of the result bit-vector.
In that case, the iteration can be performed more efficiently, and it
terminates when the bit-vector is full or the requested number of
iterations have been performed, whichever comes first. If
length-expr specifies a length longer than the number of
iterations, then the remaining slots of the vector are initialized to
the value of fill-expr, which defaults to #f (i.e.,
the default argument of make-bit-vector).
'(#t #f #t)
'(#t #f #t #f)
'(#t #f #t #t)
The for/bit-vector form may allocate a bit-vector and mutate it
after each iteration of body, which means that capturing a
continuation during body and applying it multiple times may
mutate a shared bit-vector.
Converts between bit-vectors and their representations as lists and