You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ks...@apache.org on 2019/02/13 11:34:43 UTC

[arrow] branch master updated: ARROW-4513: [Rust] Implement BitAnd/BitOr for &Bitmap

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 27ba26c  ARROW-4513: [Rust] Implement BitAnd/BitOr for &Bitmap
27ba26c is described below

commit 27ba26cad39d92713e17d811a65ad0b87c587610
Author: Paddy Horan <pa...@hotmail.com>
AuthorDate: Wed Feb 13 12:34:28 2019 +0100

    ARROW-4513: [Rust] Implement BitAnd/BitOr for &Bitmap
    
    Author: Paddy Horan <pa...@hotmail.com>
    
    Closes #3632 from paddyhoran/bitmap-and-or and squashes the following commits:
    
    b32b6d0c <Paddy Horan> Implemented `BitAnd` and `BitOr` for `Bitmap`
---
 rust/arrow/src/bitmap.rs | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/rust/arrow/src/bitmap.rs b/rust/arrow/src/bitmap.rs
index 93b6ee8..17dc548 100644
--- a/rust/arrow/src/bitmap.rs
+++ b/rust/arrow/src/bitmap.rs
@@ -20,6 +20,7 @@
 
 use super::buffer::Buffer;
 use crate::util::bit_util;
+use std::ops::{BitAnd, BitOr};
 
 #[derive(PartialEq, Debug)]
 pub struct Bitmap {
@@ -54,6 +55,22 @@ impl Bitmap {
     }
 }
 
+impl<'a, 'b> BitAnd<&'b Bitmap> for &'a Bitmap {
+    type Output = Bitmap;
+
+    fn bitand(self, rhs: &'b Bitmap) -> Bitmap {
+        Bitmap::from(&self.bits & &rhs.bits)
+    }
+}
+
+impl<'a, 'b> BitOr<&'b Bitmap> for &'a Bitmap {
+    type Output = Bitmap;
+
+    fn bitor(self, rhs: &'b Bitmap) -> Bitmap {
+        Bitmap::from(&self.bits | &rhs.bits)
+    }
+}
+
 impl From<Buffer> for Bitmap {
     fn from(buf: Buffer) -> Self {
         Self { bits: buf }
@@ -72,6 +89,26 @@ mod tests {
     }
 
     #[test]
+    fn test_bitwise_and() {
+        let bitmap1 = Bitmap::from(Buffer::from([0b01101010]));
+        let bitmap2 = Bitmap::from(Buffer::from([0b01001110]));
+        assert_eq!(
+            Bitmap::from(Buffer::from([0b01001010])),
+            &bitmap1 & &bitmap2
+        );
+    }
+
+    #[test]
+    fn test_bitwise_or() {
+        let bitmap1 = Bitmap::from(Buffer::from([0b01101010]));
+        let bitmap2 = Bitmap::from(Buffer::from([0b01001110]));
+        assert_eq!(
+            Bitmap::from(Buffer::from([0b01101110])),
+            &bitmap1 | &bitmap2
+        );
+    }
+
+    #[test]
     fn test_bitmap_is_set() {
         let bitmap = Bitmap::from(Buffer::from([0b01001010]));
         assert_eq!(false, bitmap.is_set(0));