Skip to content

Commit

Permalink
Implement the run run intersect_with operation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerollmops committed Sep 12, 2020
1 parent 613163f commit 0a66483
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/bitmap/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,36 @@ impl Store {
}
// TODO(jpg) intersect_with bitmap, run
(_this @ &mut Bitmap(..), &Run(..)) => unimplemented!(),
// TODO(jpg) intersect_with run, *
(&mut Run(ref mut _intervals1), &Run(ref _intervals2)) => unimplemented!(),
(&mut Run(ref mut intervals1), &Run(ref intervals2)) => {
let mut merged = Vec::new();

let (mut i1, mut i2) = (intervals1.iter(), intervals2.iter());
let (mut iv1, mut iv2) = (i1.next(), i2.next());
loop {
if let (Some(v1), Some(v2)) = (iv1, iv2) {
let start = cmp::max(v1.start, v2.start);
let end = cmp::min(v1.end, v2.end);
let iv = Interval::new(start, end);
if iv.run_len() > 0 {
merged.push(iv);
}
}

// Iterate over two iterators, consuming the lowest first, like merge join.
match (iv1, iv2) {
(None, None) => break,
(Some(v1), None) => iv1 = i1.next(),
(None, Some(v2)) => iv2 = i2.next(),
(Some(v1), Some(v2)) => match v1.start.cmp(&v2.start) {
Equal => { iv1 = i1.next(); iv2 = i2.next(); },
Less => iv1 = i1.next(),
Greater => iv2 = i2.next(),
},
}
}

*intervals1 = merged;
},
(this @ &mut Run(..), &Array(..)) => {
let mut new = other.clone();
new.intersect_with(this);
Expand Down

0 comments on commit 0a66483

Please sign in to comment.