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

Implement BitXor trait for Bitmap #485

Merged
merged 1 commit into from
Oct 2, 2021
Merged
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
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