Skip to content

Commit

Permalink
Add functionality to BooleanBufferBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
srh committed Nov 11, 2024
1 parent 47412b8 commit 24097bd
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions arrow/src/array/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,24 @@ impl BooleanBufferBuilder {
Self { buffer, len: 0 }
}

#[inline]
pub fn new_from_buffer(buffer: MutableBuffer, len: usize) -> BooleanBufferBuilder {
assert_eq!(len.div_ceil(8), buffer.len());
Self { buffer, len }
}

#[inline]
pub fn len(&self) -> usize {
self.len
}

// TODO: Remove, and don't use the elem-by-elem peek_evaluate function.
#[inline]
pub fn get_bit(&self, index: usize) -> bool {
bit_util::get_bit(self.buffer.as_ref(), index)
}

// TODO: Probably, make set_bit be branchless
#[inline]
pub fn set_bit(&mut self, index: usize, v: bool) {
if v {
Expand Down Expand Up @@ -352,6 +365,12 @@ impl BooleanBufferBuilder {
}
}

#[inline]
pub fn append_8_bits(&mut self, vs: u8) {
// TODO: Unsafe; this assumes we are aligned.
self.buffer.push(vs);
}

#[inline]
pub fn append_n(&mut self, additional: usize, v: bool) {
self.advance(additional);
Expand Down Expand Up @@ -382,6 +401,12 @@ impl BooleanBufferBuilder {
self.len = 0;
buf.into()
}

#[inline]
/// Builds the [Buffer] without resetting the builder.
pub fn finish_cloned(&self) -> Buffer {
Buffer::from_slice_ref(&self.buffer.as_slice())
}
}

impl From<BooleanBufferBuilder> for Buffer {
Expand Down

0 comments on commit 24097bd

Please sign in to comment.