Skip to content

Commit

Permalink
Merge #205
Browse files Browse the repository at this point in the history
205: remove in place array-array xor operation r=Kerollmops a=saik0

Closes #191

Co-authored-by: saik0 <[email protected]>
  • Loading branch information
bors[bot] and saik0 authored Feb 11, 2022
2 parents 100ce5f + 81f49f2 commit d37d202
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 49 deletions.
40 changes: 1 addition & 39 deletions src/bitmap/store/array_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::cmp::Ordering;
use std::cmp::Ordering::*;
use std::convert::{TryFrom, TryInto};
use std::fmt::{Display, Formatter};
use std::ops::{BitAnd, BitAndAssign, BitOr, BitXor, BitXorAssign, RangeInclusive, Sub, SubAssign};
use std::ops::{BitAnd, BitAndAssign, BitOr, BitXor, RangeInclusive, Sub, SubAssign};

use super::bitmap_store::{bit, key, BitmapStore, BITMAP_LENGTH};

Expand Down Expand Up @@ -368,44 +368,6 @@ impl BitXor<Self> for &ArrayStore {
}
}

impl BitXorAssign<&Self> for ArrayStore {
fn bitxor_assign(&mut self, rhs: &Self) {
#[cfg(feature = "simd")]
{
let mut visitor = VecWriter::new(self.vec.len().min(rhs.vec.len()));
vector::xor(self.as_slice(), rhs.as_slice(), &mut visitor);
self.vec = visitor.into_inner()
}
#[cfg(not(feature = "simd"))]
{
let mut i1 = 0usize;
let mut iter2 = rhs.vec.iter();
let mut current2 = iter2.next();
while i1 < self.vec.len() {
match current2.map(|c2| self.vec[i1].cmp(c2)) {
None => break,
Some(Less) => {
i1 += 1;
}
Some(Greater) => {
self.vec.insert(i1, *current2.unwrap());
i1 += 1;
current2 = iter2.next();
}
Some(Equal) => {
self.vec.remove(i1);
current2 = iter2.next();
}
}
}
if let Some(current) = current2 {
self.vec.push(*current);
self.vec.extend(iter2.cloned());
}
}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
20 changes: 10 additions & 10 deletions src/bitmap/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,13 +365,12 @@ impl BitXor<&Store> for &Store {

impl BitXorAssign<Store> for Store {
fn bitxor_assign(&mut self, mut rhs: Store) {
// TODO improve this function
match (self, &mut rhs) {
(&mut Array(ref mut vec1), &mut Array(ref mut vec2)) => {
BitXorAssign::bitxor_assign(vec1, vec2);
(&mut Array(ref mut vec1), &mut Array(ref vec2)) => {
*vec1 = BitXor::bitxor(&*vec1, vec2);
}
(&mut Bitmap(ref mut bits1), &mut Array(ref mut vec2)) => {
BitXorAssign::bitxor_assign(bits1, &*vec2);
(&mut Bitmap(ref mut bits1), &mut Array(ref vec2)) => {
BitXorAssign::bitxor_assign(bits1, vec2);
}
(&mut Bitmap(ref mut bits1), &mut Bitmap(ref bits2)) => {
BitXorAssign::bitxor_assign(bits1, bits2);
Expand All @@ -388,18 +387,19 @@ impl BitXorAssign<&Store> for Store {
fn bitxor_assign(&mut self, rhs: &Store) {
match (self, rhs) {
(&mut Array(ref mut vec1), &Array(ref vec2)) => {
BitXorAssign::bitxor_assign(vec1, vec2);
let this = mem::take(vec1);
*vec1 = BitXor::bitxor(&this, vec2);
}
(&mut Bitmap(ref mut bits1), &Array(ref vec2)) => {
BitXorAssign::bitxor_assign(bits1, vec2);
}
(&mut Bitmap(ref mut bits1), &Bitmap(ref bits2)) => {
BitXorAssign::bitxor_assign(bits1, bits2);
}
(this @ &mut Array(..), &Bitmap(..)) => {
let mut new = rhs.clone();
BitXorAssign::bitxor_assign(&mut new, &*this);
*this = new;
(this @ &mut Array(..), &Bitmap(ref bits2)) => {
let mut lhs: Store = Bitmap(bits2.clone());
BitXorAssign::bitxor_assign(&mut lhs, &*this);
*this = lhs;
}
}
}
Expand Down

0 comments on commit d37d202

Please sign in to comment.