diff --git a/src/bitmap/cmp.rs b/src/bitmap/cmp.rs index 908453b7..85649ace 100644 --- a/src/bitmap/cmp.rs +++ b/src/bitmap/cmp.rs @@ -1,3 +1,4 @@ +use std::cmp::Ordering; use std::iter::Peekable; use std::slice; @@ -39,8 +40,8 @@ impl RoaringBitmap { /// ``` pub fn is_disjoint(&self, other: &Self) -> bool { self.pairs(other) - .filter(|&(c1, c2)| c1.is_some() && c2.is_some()) - .all(|(c1, c2)| c1.unwrap().is_disjoint(c2.unwrap())) + .filter_map(|(c1, c2)| c1.zip(c2)) + .all(|(c1, c2)| c1.is_disjoint(c2)) } /// Returns `true` if this set is a subset of `other`. @@ -113,28 +114,15 @@ impl<'a> Iterator for Pairs<'a> { type Item = (Option<&'a Container>, Option<&'a Container>); fn next(&mut self) -> Option { - enum Which { - Left, - Right, - Both, - None, - } - let which = match (self.0.peek(), self.1.peek()) { - (None, None) => Which::None, - (Some(_), None) => Which::Left, - (None, Some(_)) => Which::Right, - (Some(c1), Some(c2)) => match (c1.key, c2.key) { - (key1, key2) if key1 == key2 => Which::Both, - (key1, key2) if key1 < key2 => Which::Left, - (key1, key2) if key1 > key2 => Which::Right, - (_, _) => unreachable!(), + match (self.0.peek(), self.1.peek()) { + (None, None) => None, + (Some(_), None) => Some((self.0.next(), None)), + (None, Some(_)) => Some((None, self.1.next())), + (Some(c1), Some(c2)) => match c1.key.cmp(&c2.key) { + Ordering::Equal => Some((self.0.next(), self.1.next())), + Ordering::Less => Some((self.0.next(), None)), + Ordering::Greater => Some((None, self.1.next())), }, - }; - match which { - Which::Left => Some((self.0.next(), None)), - Which::Right => Some((None, self.1.next())), - Which::Both => Some((self.0.next(), self.1.next())), - Which::None => None, } } }