Struct BooleanBufferBuilder
pub struct BooleanBufferBuilder {
buffer: MutableBuffer,
len: usize,
}
Expand description
Fields§
§buffer: MutableBuffer
§len: usize
Implementations§
§impl BooleanBufferBuilder
impl BooleanBufferBuilder
pub fn new(capacity: usize) -> BooleanBufferBuilder
pub fn new(capacity: usize) -> BooleanBufferBuilder
Creates a new BooleanBufferBuilder
with sufficient space for
capacity
bits (not bytes).
The capacity is rounded up to the nearest multiple of 8 for the allocation.
pub fn new_from_buffer(
buffer: MutableBuffer,
len: usize,
) -> BooleanBufferBuilder
pub fn new_from_buffer( buffer: MutableBuffer, len: usize, ) -> BooleanBufferBuilder
Creates a new BooleanBufferBuilder
from MutableBuffer
of len
pub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the capacity of the buffer, in bits (not bytes)
Note this
§Example
// empty requires 0 bytes
let b = BooleanBufferBuilder::new(0);
assert_eq!(0, b.capacity());
// Creating space for 1 bit results in 64 bytes (space for 512 bits)
// (64 is the minimum allocation size for 64 bit architectures)
let mut b = BooleanBufferBuilder::new(1);
assert_eq!(512, b.capacity());
// 1000 bits requires 128 bytes (space for 1024 bits)
b.append_n(1000, true);
assert_eq!(1024, b.capacity());
pub fn truncate(&mut self, len: usize)
pub fn truncate(&mut self, len: usize)
Truncates the builder to the given length
If len
is greater than the buffer’s current length, this has no effect
pub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserve space to at least additional
new bits.
Capacity will be >= self.len() + additional
.
New bytes are uninitialized and reading them is undefined behavior.
pub fn resize(&mut self, len: usize)
pub fn resize(&mut self, len: usize)
Resizes the buffer, either truncating its contents (with no change in capacity), or
growing it (potentially reallocating it) and writing false
in the newly available bits.
pub fn append_n(&mut self, additional: usize, v: bool)
pub fn append_n(&mut self, additional: usize, v: bool)
Appends n additional
bits of value v
into the buffer
pub fn append_slice(&mut self, slice: &[bool])
pub fn append_slice(&mut self, slice: &[bool])
Appends a slice of booleans into the buffer
pub fn append_packed_range(&mut self, range: Range<usize>, to_set: &[u8])
pub fn append_packed_range(&mut self, range: Range<usize>, to_set: &[u8])
Append range
bits from to_set
to_set
is a slice of bits packed LSB-first into [u8]
§Panics
Panics if to_set
does not contain ceil(range.end / 8)
bytes
pub fn append_buffer(&mut self, buffer: &BooleanBuffer)
pub fn append_buffer(&mut self, buffer: &BooleanBuffer)
Append BooleanBuffer
to this BooleanBufferBuilder
pub fn as_slice_mut(&mut self) -> &mut [u8] ⓘ
pub fn as_slice_mut(&mut self) -> &mut [u8] ⓘ
Returns the packed bits
pub fn finish(&mut self) -> BooleanBuffer
pub fn finish(&mut self) -> BooleanBuffer
Creates a BooleanBuffer
pub fn finish_cloned(&self) -> BooleanBuffer
pub fn finish_cloned(&self) -> BooleanBuffer
Builds the BooleanBuffer without resetting the builder.