9 Bit Vectors
(require data/bit-vector) | package: base |
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.
procedure
(make-bit-vector size [fill]) → bit-vector?
size : exact-integer? fill : boolean? = #f
Examples: | ||||
|
procedure
(bit-vector elem ...) → bit-vector?
elem : boolean?
Example: | ||
|
procedure
(bit-vector? v) → boolean?
v : any/c
procedure
(bit-vector-ref bv index [default]) → any/c
bv : bit-vector? index : exact-nonnegative-integer? default : any/c = (error ....)
Examples: | ||||
|
procedure
(bit-vector-set! bv index value) → void?
bv : bit-vector?
index :
(and/c exact-nonnegative-integer? (</c (+ 1 (bit-vector-length vv)))) value : boolean?
Examples: | ||||||||||
|
procedure
bv : bit-vector?
procedure
bv : bit-vector?
Example: | ||
|
procedure
(bit-vector-copy bv [start end]) → bit-vector?
bv : bit-vector? start : exact-nonnegative-integer? = 0 end : exact-nonnegative-integer? = (vector-length v)
procedure
(in-bit-vector bv) → sequence?
bv : bit-vector?
Examples: | |||||
|
syntax
(for/bit-vector maybe-length (for-clause ...) body-or-break ... body)
maybe-length =
| #:length length-expr | #:length length-expr #:fill fill-expr
length-expr : exact-nonnegative-integer?
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).
Examples: | ||||||||||||||||
|
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.
syntax
(for*/bit-vector maybe-length (for-clause ...) body-or-break ... body)
procedure
(bit-vector->list bv) → (listof boolean?)
bv : bit-vector?
procedure
(list->bit-vector bits) → bit-vector?
bits : (listof boolean?)
procedure
(bit-vector->string bv) → (and/c string? #rx"^[01]*$")
bv : bit-vector?
procedure
s : (and/c string? #rx"^[01]*$")
Examples: | ||||
|