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 4ae8986
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 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) {

// Iterate over both iterators.
while let (Some(v1), Some(v2)) = (iv1, iv2) {
if v2.start <= v1.end && v1.start <= v2.end {
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);
}
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(),
},
if v1.end < v2.end {
iv1 = i1.next();
} else if v1.end > v2.end {
iv2 = i2.next();
} else {
iv1 = i1.next();
iv2 = i2.next();
}
}

Expand Down

0 comments on commit 4ae8986

Please sign in to comment.