Skip to content

Commit

Permalink
Simplify 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 9612ae9 commit c016371
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions src/bitmap/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,26 +521,23 @@ impl Store {

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 joins.
while 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(),
match v1.start.cmp(&v2.start) {
Equal => {
iv1 = i1.next();
iv2 = i2.next();
},
Less => iv1 = i1.next(),
Greater => iv2 = i2.next(),
}
}

Expand Down

0 comments on commit c016371

Please sign in to comment.