From be9abfc4186485f31e42dcc1c0032e744fcb56ef Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Sat, 2 Oct 2021 00:00:15 -0700 Subject: [PATCH] Implement BitXor trait for Bitmap --- src/bitmap/bitmap_ops.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/bitmap/bitmap_ops.rs b/src/bitmap/bitmap_ops.rs index 8e4fc88344b..88a79993611 100644 --- a/src/bitmap/bitmap_ops.rs +++ b/src/bitmap/bitmap_ops.rs @@ -1,4 +1,4 @@ -use std::ops::{BitAnd, BitOr, Not}; +use std::ops::{BitAnd, BitOr, BitXor, Not}; use crate::buffer::MutableBuffer; @@ -132,14 +132,21 @@ where } } +#[inline] fn and(lhs: &Bitmap, rhs: &Bitmap) -> Bitmap { binary(lhs, rhs, |x, y| x & y) } +#[inline] fn or(lhs: &Bitmap, rhs: &Bitmap) -> Bitmap { binary(lhs, rhs, |x, y| x | y) } +#[inline] +fn xor(lhs: &Bitmap, rhs: &Bitmap) -> Bitmap { + binary(lhs, rhs, |x, y| x ^ y) +} + fn eq(lhs: &Bitmap, rhs: &Bitmap) -> bool { if lhs.len() != rhs.len() { return false; @@ -183,6 +190,14 @@ impl<'a, 'b> BitAnd<&'b Bitmap> for &'a Bitmap { } } +impl<'a, 'b> BitXor<&'b Bitmap> for &'a Bitmap { + type Output = Bitmap; + + fn bitxor(self, rhs: &'b Bitmap) -> Bitmap { + xor(self, rhs) + } +} + impl Not for &Bitmap { type Output = Bitmap;