Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Implement BitXor trait for Bitmap (#485)
Browse files Browse the repository at this point in the history
  • Loading branch information
houqp authored Oct 2, 2021
1 parent a15044a commit 2173ac0
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/bitmap/bitmap_ops.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::ops::{BitAnd, BitOr, Not};
use std::ops::{BitAnd, BitOr, BitXor, Not};

use crate::buffer::MutableBuffer;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 2173ac0

Please sign in to comment.