Bit vectors are zero-origin, one-dimensional arrays of booleans. They
are displayed as a sequence of 0
s and 1
s prefixed by
#*
, e.g.,
(make-bitvector 8 #f) ⇒ #*00000000
Bit vectors are the special case of one dimensional bit arrays, and can thus be used with the array procedures, See Arrays.
Return #t
when obj is a bitvector, else
return #f
.
Create a new bitvector of length len and optionally initialize all elements to fill.
Create a new bitvector with the arguments as elements.
Return the length of the bitvector vec.
Return #t
if the bit at index idx of the bitvector
vec is set (for bitvector-bit-set?
) or clear (for
bitvector-bit-clear?
).
Set (for bitvector-set-bit!
) or clear (for
bitvector-clear-bit!
) the bit at index idx of the bitvector
vec.
Set, clear, or flip all bits of vec.
Return a new bitvector initialized with the elements of list.
Return a new list initialized with the elements of the bitvector vec.
Returns a freshly allocated bitvector containing the elements of bitvector in the range [start ... end). start defaults to 0 and end defaults to the length of bitvector.
Return a count of how many entries in bitvector are set.
(bitvector-count #*000111000) ⇒ 3
Return a count of how many entries in bitvector are set, with the bitvector bits selecting the entries to consider. bitvector must be at least as long as bits.
For example,
(bitvector-count-bits #*01110111 #*11001101) ⇒ 3
Return the index of the first occurrence of bool in
bitvector, starting from start. If there is no bool
entry between start and the end of bitvector, then return
#f
. For example,
(bitvector-position #*000101 #t 0) ⇒ 3 (bitvector-position #*0001111 #f 3) ⇒ #f
Set entries of bitvector to #t
, with bits selecting
the bits to set. The return value is unspecified. bitvector must
be at least as long as bits.
(define bv (bitvector-copy #*11000010)) (bitvector-set-bits! bv #*10010001) bv ⇒ #*11010011
Set entries of bitvector to #f
, with bits selecting
the bits to clear. The return value is unspecified. bitvector
must be at least as long as bits.
(define bv (bitvector-copy #*11000010)) (bitvector-clear-bits! bv #*10010001) bv ⇒ #*01000010
int
scm_is_bitvector (SCM obj)
¶SCM
scm_c_make_bitvector (size_t len, SCM fill)
¶int
scm_bitvector_bit_is_set (SCM vec, size_t idx)
¶int
scm_bitvector_bit_is_clear (SCM vec, size_t idx)
¶void
scm_c_bitvector_set_bit_x (SCM vec, size_t idx)
¶void
scm_c_bitvector_clear_bit_x (SCM vec, size_t idx)
¶void
scm_c_bitvector_set_bits_x (SCM vec, SCM bits)
¶void
scm_c_bitvector_clear_bits_x (SCM vec, SCM bits)
¶void
scm_c_bitvector_set_all_bits_x (SCM vec)
¶void
scm_c_bitvector_clear_all_bits_x (SCM vec)
¶void
scm_c_bitvector_flip_all_bits_x (SCM vec)
¶size_t
scm_c_bitvector_length (SCM bitvector)
¶size_t
scm_c_bitvector_count (SCM bitvector)
¶size_t
scm_c_bitvector_count_bits (SCM bitvector, SCM bits)
¶C API for the corresponding Scheme bitvector interfaces.
const scm_t_uint32 *
scm_bitvector_elements (SCM vec, scm_t_array_handle *handle, size_t *offp, size_t *lenp, ssize_t *incp)
¶Like scm_vector_elements
(see Vector Accessing from C), but
for bitvectors. The variable pointed to by offp is set to the
value returned by scm_array_handle_bit_elements_offset
. See
scm_array_handle_bit_elements
for how to use the returned
pointer and the offset.
scm_t_uint32 *
scm_bitvector_writable_elements (SCM vec, scm_t_array_handle *handle, size_t *offp, size_t *lenp, ssize_t *incp)
¶Like scm_bitvector_elements
, but the pointer is good for reading
and writing.