This is an automated email from the ASF dual-hosted git repository.

dheres pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/master by this push:
     new 0b7ac79  Add get_bit to BooleanBufferBuilder (#693)
0b7ac79 is described below

commit 0b7ac7975113314eb523c34e79ca50de25a29534
Author: Boaz <[email protected]>
AuthorDate: Sun Aug 15 21:58:14 2021 +0300

    Add get_bit to BooleanBufferBuilder (#693)
    
    * Add get_bit to BooleanBufferBuilder
    
    * fix clippy
---
 arrow/src/array/builder.rs | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/arrow/src/array/builder.rs b/arrow/src/array/builder.rs
index 8a4ebbf..8065f16 100644
--- a/arrow/src/array/builder.rs
+++ b/arrow/src/array/builder.rs
@@ -312,6 +312,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
     }
@@ -2648,6 +2653,31 @@ mod tests {
     }
 
     #[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 =
             BooleanArray::from(vec![Some(true), Some(false), None, None, 
Some(false)]);

Reply via email to