Skip to content

Commit

Permalink
Add get_bit to BooleanBufferBuilder (#693)
Browse files Browse the repository at this point in the history
* Add get_bit to BooleanBufferBuilder

* fix clippy
  • Loading branch information
boazberman authored Aug 15, 2021
1 parent 1a5c26b commit 0b7ac79
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions arrow/src/array/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@ impl BooleanBufferBuilder {
}
}

#[inline]
pub fn get_bit(&mut self, index: usize) -> bool {
bit_util::get_bit(self.buffer.as_slice(), index)
}

#[inline]
pub fn is_empty(&self) -> bool {
self.len == 0
Expand Down Expand Up @@ -2647,6 +2652,31 @@ mod tests {
assert_eq!(buffer.finish().as_slice(), &[0b01010110_u8, 0b1011100_u8]);
}

#[test]
fn test_bool_buffer_builder_get_first_bit() {
let mut buffer = BooleanBufferBuilder::new(16);
buffer.append_n(8, true);
buffer.append_n(8, false);
assert!(buffer.get_bit(0));
}

#[test]
fn test_bool_buffer_builder_get_last_bit() {
let mut buffer = BooleanBufferBuilder::new(16);
buffer.append_n(8, true);
buffer.append_n(8, false);
assert!(!buffer.get_bit(15));
}

#[test]
fn test_bool_buffer_builder_get_an_inner_bit() {
let mut buffer = BooleanBufferBuilder::new(16);
buffer.append_n(4, false);
buffer.append_n(8, true);
buffer.append_n(4, false);
assert!(buffer.get_bit(11));
}

#[test]
fn test_boolean_array_builder_append_slice() {
let arr1 =
Expand Down

0 comments on commit 0b7ac79

Please sign in to comment.