Struct NullBufferBuilder
pub struct NullBufferBuilder {
bitmap_builder: Option<BooleanBufferBuilder>,
len: usize,
capacity: usize,
}
Expand description
Builder for creating NullBuffer
§Performance
This builder only materializes the buffer when we append false
.
If you only append true
s to the builder, what you get will be
None
when calling finish
.
This optimization is very important for the performance as it avoids allocating memory for the null buffer when there are no nulls.
See Self::allocated_size
to get the current memory allocated by the builder.
§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: usize
Implementations§
§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
true
s 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
false
s 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 finish(&mut self) -> Option<NullBuffer>
pub fn finish(&mut self) -> Option<NullBuffer>
Builds the null buffer and resets the builder.
Returns None
if the builder only contains true
s.
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.