diff --git a/src/bitmap/store/array_store/mod.rs b/src/bitmap/store/array_store/mod.rs index 32ec08da..c8747075 100644 --- a/src/bitmap/store/array_store/mod.rs +++ b/src/bitmap/store/array_store/mod.rs @@ -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}; @@ -368,44 +368,6 @@ impl BitXor 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::*; diff --git a/src/bitmap/store/mod.rs b/src/bitmap/store/mod.rs index 3534ef45..22e4b7a9 100644 --- a/src/bitmap/store/mod.rs +++ b/src/bitmap/store/mod.rs @@ -365,13 +365,12 @@ impl BitXor<&Store> for &Store { impl BitXorAssign 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); @@ -388,7 +387,8 @@ 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); @@ -396,10 +396,10 @@ impl BitXorAssign<&Store> for Store { (&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; } } }