Skip to main content

BooleanBufferBuilder

Struct BooleanBufferBuilder 

pub struct BooleanBufferBuilder {
    buffer: MutableBuffer,
    len: usize,
}
Expand description

Builder for BooleanBuffer

Builds a packed buffer of bits representing boolean values. Each bit in the buffer corresponds to a boolean value,

§See Also

§Example

let mut builder = BooleanBufferBuilder::new(10);
builder.append(true);
builder.append(false);
builder.append_n(3, true); // append 3 trues
let buffer = builder.build();
assert_eq!(buffer.len(), 5); // 5 bits appended
assert_eq!(buffer.values(), &[0b00011101_u8]); // packed bits

Fields§

§buffer: MutableBuffer§len: usize

Implementations§

§

impl 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

Creates a new BooleanBufferBuilder from MutableBuffer of len

pub fn len(&self) -> usize

Returns the length of the buffer

pub fn set_bit(&mut self, index: usize, v: bool)

Sets a bit in the buffer at index

pub fn get_bit(&self, index: usize) -> bool

Gets a bit in the buffer at index

pub fn is_empty(&self) -> bool

Returns true if empty

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 advance(&mut self, additional: usize)

Advances the buffer by additional bits

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)

Reserve space to at least additional new bits. Capacity will be >= self.len() + additional.

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(&mut self, v: bool)

Appends a boolean v into the buffer

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])

Appends a slice of booleans into the buffer

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 as_slice(&self) -> &[u8]

Returns the packed bits

pub fn as_slice_mut(&mut self) -> &mut [u8]

Returns the packed bits

pub fn finish(&mut self) -> BooleanBuffer

Resets this builder and returns a BooleanBuffer.

Use Self::build when you don’t need to reuse this builder.

pub fn build(self) -> BooleanBuffer

Builds a BooleanBuffer without resetting the builder.

This consumes the builder. Use Self::finish to reuse it.

pub fn finish_cloned(&self) -> BooleanBuffer

Builds the BooleanBuffer without resetting the builder.

pub unsafe fn extend_trusted_len<I>(&mut self, iterator: I)
where I: Iterator<Item = bool>,

Extends the builder from a trusted length iterator of booleans.

§Safety

Callers must ensure that iter reports an exact size via size_hint.

Trait Implementations§

§

impl Debug for BooleanBufferBuilder

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl From<BooleanBufferBuilder> for BooleanBuffer

§

fn from(builder: BooleanBufferBuilder) -> BooleanBuffer

Converts to this type from the input type.
§

impl From<BooleanBufferBuilder> for Buffer

§

fn from(builder: BooleanBufferBuilder) -> Buffer

Converts to this type from the input type.
§

impl From<BooleanBufferBuilder> for NullBuffer

§

fn from(builder: BooleanBufferBuilder) -> NullBuffer

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

§

impl<T> Ungil for T
where T: Send,