Struct NullBufferBuilder
pub struct NullBufferBuilder {
bitmap_builder: Option<BooleanBufferBuilder>,
len: usize,
capacity: usize,
}Expand description
Builder for creating NullBuffers (bitmaps indicating validity/nulls).
§See also
BooleanBufferBuilderfor a lower-level bitmap builder.Self::allocated_sizefor the current memory allocated by the builder.
§Performance
This builder only materializes the buffer when null values (false) are
appended. If you only append non-null, (true) to the builder, no buffer is
allocated and build or finish return
None.
This optimization is very important for the performance as it avoids allocating memory for the null buffer when there are no nulls.
§Example
let mut builder = NullBufferBuilder::new(8);
builder.append_n_non_nulls(8);
// If no non null values are appended, the null buffer is not created
let buffer = builder.finish();
assert!(buffer.is_none());
// however, if a null value is appended, the null buffer is created
let mut builder = NullBufferBuilder::new(8);
builder.append_n_non_nulls(7);
builder.append_null();
let buffer = builder.finish().unwrap();
assert_eq!(buffer.len(), 8);
assert_eq!(buffer.iter().collect::<Vec<_>>(), vec![true, true, true, true, true, true, true, false]);Fields§
§bitmap_builder: Option<BooleanBufferBuilder>§len: usize§capacity: usizeImplementations§
§impl NullBufferBuilder
impl NullBufferBuilder
pub fn new(capacity: usize) -> NullBufferBuilder
pub fn new(capacity: usize) -> NullBufferBuilder
Creates a new empty builder.
Note that this method does not allocate any memory, regardless of the
capacity parameter. If an allocation is required, capacity is the
size in bits (not bytes) that will be allocated at minimum.
pub fn new_with_len(len: usize) -> NullBufferBuilder
pub fn new_with_len(len: usize) -> NullBufferBuilder
Creates a new builder with given length.
pub fn new_from_buffer(buffer: MutableBuffer, len: usize) -> NullBufferBuilder
pub fn new_from_buffer(buffer: MutableBuffer, len: usize) -> NullBufferBuilder
Creates a new builder from a MutableBuffer.
pub fn append_n_non_nulls(&mut self, n: usize)
pub fn append_n_non_nulls(&mut self, n: usize)
Appends n trues into the builder
to indicate that these n items are not nulls.
pub fn append_non_null(&mut self)
pub fn append_non_null(&mut self)
Appends a true into the builder
to indicate that this item is not null.
pub fn append_n_nulls(&mut self, n: usize)
pub fn append_n_nulls(&mut self, n: usize)
Appends n falses into the builder
to indicate that these n items are nulls.
pub fn append_null(&mut self)
pub fn append_null(&mut self)
Appends a false into the builder
to indicate that this item is null.
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 append_slice(&mut self, slice: &[bool])
pub fn append_slice(&mut self, slice: &[bool])
Appends a boolean slice into the builder to indicate the validations of these items.
pub fn append_buffer(&mut self, buffer: &NullBuffer)
pub fn append_buffer(&mut self, buffer: &NullBuffer)
Append NullBuffer to this NullBufferBuilder
This is useful when you want to concatenate two null buffers.
pub fn finish(&mut self) -> Option<NullBuffer>
pub fn finish(&mut self) -> Option<NullBuffer>
Builds the NullBuffer and resets the builder.
Returns None if the builder only contains trues. Use Self::build
when you don’t need to reuse this builder.
pub fn build(self) -> Option<NullBuffer>
pub fn build(self) -> Option<NullBuffer>
Builds the NullBuffer without resetting the builder.
This consumes the builder. Use Self::finish to reuse it.
pub fn finish_cloned(&self) -> Option<NullBuffer>
pub fn finish_cloned(&self) -> Option<NullBuffer>
Builds the NullBuffer without resetting the builder.
pub fn as_slice_mut(&mut self) -> Option<&mut [u8]>
pub fn as_slice_mut(&mut self) -> Option<&mut [u8]>
Return a mutable reference to the inner bitmap slice.
pub fn allocated_size(&self) -> usize
pub fn allocated_size(&self) -> usize
Return the allocated size of this builder, in bytes, useful for memory accounting.