Skip to content

Commit

Permalink
Try #83:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] authored Jan 19, 2021
2 parents 64886bb + 374a915 commit 85bb851
Showing 1 changed file with 20 additions and 45 deletions.
65 changes: 20 additions & 45 deletions src/bitmap/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,35 +323,23 @@ impl Store {
pub fn intersect_with(&mut self, other: &Self) {
match (self, other) {
(&mut Array(ref mut vec1), &Array(ref vec2)) => {
let mut i1 = 0usize;
let mut iter2 = vec2.iter();
let mut current2 = iter2.next();
while i1 < vec1.len() {
match current2.map(|c2| vec1[i1].cmp(c2)) {
None | Some(Less) => {
vec1.remove(i1);
}
Some(Greater) => {
current2 = iter2.next();
}
Some(Equal) => {
i1 += 1;
current2 = iter2.next();
}
}
}
let mut i = 0;
vec1.retain(|x| {
i += vec2
.iter()
.skip(i)
.position(|y| y >= x)
.unwrap_or(vec2.len());
vec2.get(i).map_or(false, |y| x == y)
});
}
(&mut Bitmap(ref mut bits1), &Bitmap(ref bits2)) => {
for (index1, &index2) in bits1.iter_mut().zip(bits2.iter()) {
*index1 &= index2;
}
}
(&mut Array(ref mut vec), store @ &Bitmap(..)) => {
for i in (0..(vec.len())).rev() {
if !store.contains(vec[i]) {
vec.remove(i);
}
}
vec.retain(|x| store.contains(*x));
}
(this @ &mut Bitmap(..), &Array(..)) => {
let mut new = other.clone();
Expand All @@ -364,24 +352,15 @@ impl Store {
pub fn difference_with(&mut self, other: &Self) {
match (self, other) {
(&mut Array(ref mut vec1), &Array(ref vec2)) => {
let mut i1 = 0usize;
let mut iter2 = vec2.iter();
let mut current2 = iter2.next();
while i1 < vec1.len() {
match current2.map(|c2| vec1[i1].cmp(c2)) {
None => break,
Some(Less) => {
i1 += 1;
}
Some(Greater) => {
current2 = iter2.next();
}
Some(Equal) => {
vec1.remove(i1);
current2 = iter2.next();
}
}
}
let mut i = 0;
vec1.retain(|x| {
i += vec2
.iter()
.skip(i)
.position(|y| y >= x)
.unwrap_or(vec2.len());
vec2.get(i).map_or(true, |y| x != y)
});
}
(ref mut this @ &mut Bitmap(..), &Array(ref vec2)) => {
for index in vec2.iter() {
Expand All @@ -394,11 +373,7 @@ impl Store {
}
}
(&mut Array(ref mut vec), store @ &Bitmap(..)) => {
for i in (0..vec.len()).rev() {
if store.contains(vec[i]) {
vec.remove(i);
}
}
vec.retain(|x| !store.contains(*x));
}
}
}
Expand Down

0 comments on commit 85bb851

Please sign in to comment.