Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions rust/arrow/src/bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

use super::buffer::Buffer;
use crate::util::bit_util;
use std::ops::{BitAnd, BitOr};

#[derive(PartialEq, Debug)]
pub struct Bitmap {
Expand Down Expand Up @@ -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 }
Expand All @@ -71,6 +88,26 @@ mod tests {
assert_eq!(128, Bitmap::new(65 * 8).len());
}

#[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]));
Expand Down