diff --git a/src/container.rs b/src/container.rs index 772d0f6c..b46358d9 100644 --- a/src/container.rs +++ b/src/container.rs @@ -4,7 +4,7 @@ use std::fmt::{ Show, Formatter, Result }; use store::Store; use store::Store::{ Array, Bitmap }; -#[deriving(PartialEq, Clone)] +#[derive(PartialEq, Clone)] pub struct Container { key: u16, len: u16, @@ -56,10 +56,10 @@ impl Container { } #[inline] - pub fn iter<'a>(&'a self) -> Box + 'a> { + pub fn iter<'a>(&'a self) -> Box + 'a> { match self.store { - Array(ref vec) => box vec.iter().map(|x| *x) as Box + 'a>, - Bitmap(ref bits) => box BitmapIter::new(bits) as Box + 'a>, + Array(ref vec) => box vec.iter().map(|x| *x) as Box + 'a>, + Bitmap(ref bits) => box BitmapIter::new(bits) as Box + 'a>, } } @@ -144,7 +144,9 @@ impl<'a> BitmapIter<'a> { } } -impl<'a> Iterator for BitmapIter<'a> { +impl<'a> Iterator for BitmapIter<'a> { + type Item = u16; + fn next(&mut self) -> Option { loop { if self.key == 2047 && self.bit == (u32::BITS - 1) { diff --git a/src/imp.rs b/src/imp.rs index c13c1739..134bb084 100644 --- a/src/imp.rs +++ b/src/imp.rs @@ -1,6 +1,5 @@ use std::{ u16, u32 }; use std::slice; -use std::slice::BinarySearchResult::{ Found, NotFound }; use iter; use iter::{ Iter, UnionIter, IntersectionIter, DifferenceIter, SymmetricDifferenceIter }; @@ -15,9 +14,9 @@ pub fn new() -> RB { pub fn insert(this: &mut RB, value: u32) -> bool { let (key, index) = calc_loc(value); - let container = match this.containers.as_slice().binary_search(|container| container.key().cmp(&key)) { - Found(loc) => &mut this.containers[loc], - NotFound(loc) => { + let container = match this.containers.as_slice().binary_search_by(|container| container.key().cmp(&key)) { + Ok(loc) => &mut this.containers[loc], + Err(loc) => { this.containers.insert(loc, Container::new(key)); &mut this.containers[loc] }, @@ -27,8 +26,8 @@ pub fn insert(this: &mut RB, value: u32) -> bool { pub fn remove(this: &mut RB, value: u32) -> bool { let (key, index) = calc_loc(value); - match this.containers.as_slice().binary_search(|container| container.key().cmp(&key)) { - Found(loc) => { + match this.containers.as_slice().binary_search_by(|container| container.key().cmp(&key)) { + Ok(loc) => { if this.containers[loc].remove(index) { if this.containers[loc].len() == 0 { this.containers.remove(loc); @@ -44,9 +43,9 @@ pub fn remove(this: &mut RB, value: u32) -> bool { pub fn contains(this: &RB, value: u32) -> bool { let (key, index) = calc_loc(value); - match this.containers.as_slice().binary_search(|container| container.key().cmp(&key)) { - Found(loc) => this.containers[loc].contains(index), - NotFound(_) => false, + match this.containers.as_slice().binary_search_by(|container| container.key().cmp(&key)) { + Ok(loc) => this.containers[loc].contains(index), + Err(_) => false, } } @@ -119,9 +118,9 @@ pub fn symmetric_difference<'a>(this: &'a RB, other: &'a RB) -> SymmetricDiffere pub fn union_with(this: &mut RB, other: &RB) { for container in other.containers.iter() { let key = container.key(); - match this.containers.as_slice().binary_search(|container| container.key().cmp(&key)) { - NotFound(loc) => this.containers.insert(loc, (*container).clone()), - Found(loc) => this.containers[loc].union_with(container), + match this.containers.as_slice().binary_search_by(|container| container.key().cmp(&key)) { + Err(loc) => this.containers.insert(loc, (*container).clone()), + Ok(loc) => this.containers[loc].union_with(container), }; } } @@ -131,11 +130,11 @@ pub fn intersect_with(this: &mut RB, other: &RB) { let mut index = 0; while index < this.containers.len() { let key = this.containers[index].key(); - match other.containers.as_slice().binary_search(|container| container.key().cmp(&key)) { - NotFound(_) => { + match other.containers.as_slice().binary_search_by(|container| container.key().cmp(&key)) { + Err(_) => { this.containers.remove(index); }, - Found(loc) => { + Ok(loc) => { this.containers[index].intersect_with(&other.containers[loc]); index += 1; }, @@ -147,8 +146,8 @@ pub fn intersect_with(this: &mut RB, other: &RB) { pub fn difference_with(this: &mut RB, other: &RB) { for index in range(0, this.containers.len()) { let key = this.containers[index].key(); - match other.containers.as_slice().binary_search(|container| container.key().cmp(&key)) { - Found(loc) => { + match other.containers.as_slice().binary_search_by(|container| container.key().cmp(&key)) { + Ok(loc) => { this.containers[index].difference_with(&other.containers[loc]); if this.containers[index].len() == 0 { this.containers.remove(index); @@ -163,9 +162,9 @@ pub fn difference_with(this: &mut RB, other: &RB) { pub fn symmetric_difference_with(this: &mut RB, other: &RB) { for container in other.containers.iter() { let key = container.key(); - match this.containers.as_slice().binary_search(|container| container.key().cmp(&key)) { - NotFound(loc) => this.containers.insert(loc, (*container).clone()), - Found(loc) => { + match this.containers.as_slice().binary_search_by(|container| container.key().cmp(&key)) { + Err(loc) => this.containers.insert(loc, (*container).clone()), + Ok(loc) => { this.containers[loc].symmetric_difference_with(container); if this.containers[loc].len() == 0 { this.containers.remove(loc); @@ -176,28 +175,28 @@ pub fn symmetric_difference_with(this: &mut RB, other: &RB) { } #[inline] -pub fn from_iter>(iterator: I) -> RB { +pub fn from_iter>(iterator: I) -> RB { let mut rb = new(); rb.extend(iterator); rb } #[inline] -pub fn from_iter_ref<'a, I: Iterator<&'a u32>>(iterator: I) -> RB { +pub fn from_iter_ref<'a, I: Iterator>(iterator: I) -> RB { let mut rb = new(); rb.extend(iterator); rb } #[inline] -pub fn extend>(this: &mut RB, mut iterator: I) { +pub fn extend>(this: &mut RB, mut iterator: I) { for value in iterator { this.insert(value); } } #[inline] -pub fn extend_ref<'a, I: Iterator<&'a u32>>(this: &mut RB, mut iterator: I) { +pub fn extend_ref<'a, I: Iterator>(this: &mut RB, mut iterator: I) { for value in iterator { this.insert(*value); } @@ -243,7 +242,9 @@ impl<'a> Pairs<'a> { } } -impl<'a> Iterator<(Option<&'a Container>, Option<&'a Container>)> for Pairs<'a> { +impl<'a> Iterator for Pairs<'a> { + type Item = (Option<&'a Container>, Option<&'a Container>); + fn next(&mut self) -> Option<(Option<&'a Container>, Option<&'a Container>)> { match (self.current1, self.current2) { (None, None) => None, diff --git a/src/iter.rs b/src/iter.rs index 599cf563..97aa929a 100644 --- a/src/iter.rs +++ b/src/iter.rs @@ -7,7 +7,7 @@ use container::{ Container }; /// An iterator for `RoaringBitmap`. pub struct Iter<'a> { - inner_iter: Option<(u16, Box + 'a>)>, + inner_iter: Option<(u16, Box + 'a>)>, container_iter: slice::Iter<'a, Container>, } @@ -17,7 +17,7 @@ fn calc(key: u16, value: u16) -> u32 { } #[inline] -fn next_iter<'a>(container_iter: &mut slice::Iter<'a, Container>) -> Option<(u16, Box + 'a>)> { +fn next_iter<'a>(container_iter: &mut slice::Iter<'a, Container>) -> Option<(u16, Box + 'a>)> { container_iter.next().map(|container| (container.key(), container.iter())) } @@ -31,7 +31,7 @@ pub fn new<'a>(mut container_iter: slice::Iter<'a, Container>) -> Iter<'a> { impl<'a> Iter<'a> { #[inline] - fn choose_next(&mut self) -> Option + 'a>)>>> { + fn choose_next(&mut self) -> Option + 'a>)>>> { match self.inner_iter { Some((key, ref mut iter)) => Some(match iter.next() { Some(value) => Left(calc(key, value)), @@ -42,7 +42,9 @@ impl<'a> Iter<'a> { } } -impl<'a> Iterator for Iter<'a> { +impl<'a> Iterator for Iter<'a> { + type Item = u32; + fn next(&mut self) -> Option { match self.choose_next() { None => None, @@ -77,7 +79,9 @@ pub mod union { } } -impl<'a> Iterator for UnionIter<'a> { +impl<'a> Iterator for UnionIter<'a> { + type Item = u32; + fn next(&mut self) -> Option { match (self.current1, self.current2) { (None, None) => None, @@ -117,7 +121,9 @@ pub mod intersection { } } -impl<'a> Iterator for IntersectionIter<'a> { +impl<'a> Iterator for IntersectionIter<'a> { + type Item = u32; + fn next(&mut self) -> Option { match (self.current1, self.current2) { (None, _) | (_, None) => None, @@ -155,7 +161,9 @@ pub mod difference { } } -impl<'a> Iterator for DifferenceIter<'a> { +impl<'a> Iterator for DifferenceIter<'a> { + type Item = u32; + fn next(&mut self) -> Option { loop { match (self.current1, self.current2) { @@ -194,7 +202,9 @@ pub mod symmetric_difference { } } -impl<'a> Iterator for SymmetricDifferenceIter<'a> { +impl<'a> Iterator for SymmetricDifferenceIter<'a> { + type Item = u32; + fn next(&mut self) -> Option { match (self.current1, self.current2) { (None, _) | (_, None) => None, diff --git a/src/lib.rs b/src/lib.rs index e127c6f3..37603420 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,10 +9,14 @@ #![feature(slicing_syntax)] #![feature(advanced_slice_patterns)] +#![feature(associated_types)] +#![feature(default_type_params)] #![warn(missing_docs)] use std::fmt::{ Show, Formatter, Result }; +use std::ops::{ BitXor, BitAnd, BitOr, Sub }; +use std::iter::{ FromIterator }; pub use iter::{ Iter, UnionIter, IntersectionIter, DifferenceIter, SymmetricDifferenceIter }; @@ -27,6 +31,9 @@ mod container; /// # Examples /// /// ```rust +/// # #![feature(slicing_syntax)] +/// # extern crate roaring; +/// # fn main() { /// use roaring::RoaringBitmap; /// /// let mut rb = RoaringBitmap::new(); @@ -37,8 +44,9 @@ mod container; /// rb.insert(5); /// rb.insert(7); /// println!("total bits set to true: {}", rb.len()); +/// # } /// ``` -#[deriving(PartialEq, Clone)] +#[derive(PartialEq, Clone)] pub struct RoaringBitmap { containers: Vec, } @@ -49,8 +57,12 @@ impl RoaringBitmap { /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// let mut rb = RoaringBitmap::new(); + /// # } /// ``` #[inline] pub fn new() -> Self { @@ -62,12 +74,16 @@ impl RoaringBitmap { /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// /// let mut rb = RoaringBitmap::new(); /// assert_eq!(rb.insert(3), true); /// assert_eq!(rb.insert(3), false); /// assert_eq!(rb.contains(3), true); + /// # } /// ``` #[inline] pub fn insert(&mut self, value: u32) -> bool { @@ -79,6 +95,9 @@ impl RoaringBitmap { /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// /// let mut rb = RoaringBitmap::new(); @@ -86,6 +105,7 @@ impl RoaringBitmap { /// assert_eq!(rb.remove(3), true); /// assert_eq!(rb.remove(3), false); /// assert_eq!(rb.contains(3), false); + /// # } /// ``` #[inline] pub fn remove(&mut self, value: u32) -> bool { @@ -97,6 +117,9 @@ impl RoaringBitmap { /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// /// let mut rb = RoaringBitmap::new(); @@ -104,6 +127,7 @@ impl RoaringBitmap { /// assert_eq!(rb.contains(0), false); /// assert_eq!(rb.contains(1), true); /// assert_eq!(rb.contains(100), false); + /// # } /// ``` #[inline] pub fn contains(&self, value: u32) -> bool { @@ -115,6 +139,9 @@ impl RoaringBitmap { /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// /// let mut rb = RoaringBitmap::new(); @@ -122,6 +149,7 @@ impl RoaringBitmap { /// assert_eq!(rb.contains(1), true); /// rb.clear(); /// assert_eq!(rb.contains(1), false); + /// # } /// ``` #[inline] pub fn clear(&mut self) { @@ -133,6 +161,9 @@ impl RoaringBitmap { /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// /// let mut rb = RoaringBitmap::new(); @@ -140,6 +171,7 @@ impl RoaringBitmap { /// /// rb.insert(3); /// assert_eq!(rb.is_empty(), false); + /// # } /// ``` #[inline] pub fn is_empty(&self) -> bool { @@ -151,6 +183,9 @@ impl RoaringBitmap { /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// /// let mut rb = RoaringBitmap::new(); @@ -162,6 +197,7 @@ impl RoaringBitmap { /// rb.insert(3); /// rb.insert(4); /// assert_eq!(rb.len(), 2); + /// # } /// ``` #[inline] pub fn len(&self) -> uint { @@ -173,6 +209,9 @@ impl RoaringBitmap { /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// /// let mut rb = RoaringBitmap::new(); @@ -187,6 +226,7 @@ impl RoaringBitmap { /// assert_eq!(iter.next(), Some(4)); /// assert_eq!(iter.next(), Some(6)); /// assert_eq!(iter.next(), None); + /// # } /// ``` #[inline] pub fn iter<'a>(&'a self) -> Iter<'a> { @@ -199,6 +239,9 @@ impl RoaringBitmap { /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// /// let mut rb1 = RoaringBitmap::new(); @@ -212,6 +255,7 @@ impl RoaringBitmap { /// /// assert_eq!(rb1.is_disjoint(&rb2), false); /// + /// # } /// ``` #[inline] pub fn is_disjoint(&self, other: &Self) -> bool { @@ -223,6 +267,9 @@ impl RoaringBitmap { /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// /// let mut rb1 = RoaringBitmap::new(); @@ -239,6 +286,7 @@ impl RoaringBitmap { /// rb1.insert(2); /// /// assert_eq!(rb1.is_subset(&rb2), false); + /// # } /// ``` #[inline] pub fn is_subset(&self, other: &Self) -> bool { @@ -250,6 +298,9 @@ impl RoaringBitmap { /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// /// let mut rb1 = RoaringBitmap::new(); @@ -266,6 +317,7 @@ impl RoaringBitmap { /// rb1.insert(2); /// /// assert_eq!(rb2.is_superset(&rb1), false); + /// # } /// ``` #[inline] pub fn is_superset(&self, other: &Self) -> bool { @@ -277,6 +329,9 @@ impl RoaringBitmap { /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// /// let mut rb1 = RoaringBitmap::new(); @@ -294,6 +349,7 @@ impl RoaringBitmap { /// assert_eq!(iter.next(), Some(2)); /// assert_eq!(iter.next(), Some(3)); /// assert_eq!(iter.next(), None); + /// # } /// ``` #[inline] pub fn union<'a>(&'a self, other: &'a Self) -> UnionIter<'a> { @@ -305,6 +361,9 @@ impl RoaringBitmap { /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// /// let mut rb1 = RoaringBitmap::new(); @@ -323,6 +382,7 @@ impl RoaringBitmap { /// assert_eq!(iter.next(), Some(1)); /// assert_eq!(iter.next(), Some(4)); /// assert_eq!(iter.next(), None); + /// # } /// ``` #[inline] pub fn intersection<'a>(&'a self, other: &'a Self) -> IntersectionIter<'a> { @@ -334,6 +394,9 @@ impl RoaringBitmap { /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// /// let mut rb1 = RoaringBitmap::new(); @@ -356,6 +419,7 @@ impl RoaringBitmap { /// /// assert_eq!(iter2.next(), Some(3)); /// assert_eq!(iter2.next(), None); + /// # } /// ``` #[inline] pub fn difference<'a>(&'a self, other: &'a Self) -> DifferenceIter<'a> { @@ -368,6 +432,9 @@ impl RoaringBitmap { /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// /// let mut rb1 = RoaringBitmap::new(); @@ -386,6 +453,7 @@ impl RoaringBitmap { /// assert_eq!(iter.next(), Some(2)); /// assert_eq!(iter.next(), Some(3)); /// assert_eq!(iter.next(), None); + /// # } /// ``` #[inline] pub fn symmetric_difference<'a>(&'a self, other: &'a Self) -> SymmetricDifferenceIter<'a> { @@ -397,15 +465,19 @@ impl RoaringBitmap { /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// - /// let mut rb1: RoaringBitmap = FromIterator::from_iter(1..4); - /// let rb2: RoaringBitmap = FromIterator::from_iter(3..5); - /// let rb3: RoaringBitmap = FromIterator::from_iter(1..5); + /// let mut rb1: RoaringBitmap = (1..4).collect(); + /// let rb2: RoaringBitmap = (3..5).collect(); + /// let rb3: RoaringBitmap = (1..5).collect(); /// /// rb1.union_with(&rb2); /// /// assert_eq!(rb1, rb3); + /// # } /// ``` #[inline] pub fn union_with(&mut self, other: &Self) { @@ -417,15 +489,19 @@ impl RoaringBitmap { /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// - /// let mut rb1: RoaringBitmap = FromIterator::from_iter(1..4); - /// let rb2: RoaringBitmap = FromIterator::from_iter(3..5); - /// let rb3: RoaringBitmap = FromIterator::from_iter(3..4); + /// let mut rb1: RoaringBitmap = (1..4).collect(); + /// let rb2: RoaringBitmap = (3..5).collect(); + /// let rb3: RoaringBitmap = (3..4).collect(); /// /// rb1.intersect_with(&rb2); /// /// assert_eq!(rb1, rb3); + /// # } /// ``` #[inline] pub fn intersect_with(&mut self, other: &Self) { @@ -437,15 +513,19 @@ impl RoaringBitmap { /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// - /// let mut rb1: RoaringBitmap = FromIterator::from_iter(1..4); - /// let rb2: RoaringBitmap = FromIterator::from_iter(3..5); - /// let rb3: RoaringBitmap = FromIterator::from_iter(1..3); + /// let mut rb1: RoaringBitmap = (1..4).collect(); + /// let rb2: RoaringBitmap = (3..5).collect(); + /// let rb3: RoaringBitmap = (1..3).collect(); /// /// rb1.difference_with(&rb2); /// /// assert_eq!(rb1, rb3); + /// # } /// ``` #[inline] pub fn difference_with(&mut self, other: &Self) { @@ -457,15 +537,19 @@ impl RoaringBitmap { /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// - /// let mut rb1: RoaringBitmap = FromIterator::from_iter(1..4); - /// let rb2: RoaringBitmap = FromIterator::from_iter(3..6); - /// let rb3: RoaringBitmap = FromIterator::from_iter((1..3).chain(4..6)); + /// let mut rb1: RoaringBitmap = (1..4).collect(); + /// let rb2: RoaringBitmap = (3..6).collect(); + /// let rb3: RoaringBitmap = ((1..3).chain(4..6)).collect(); /// /// rb1.symmetric_difference_with(&rb2); /// /// assert_eq!(rb1, rb3); + /// # } /// ``` #[inline] pub fn symmetric_difference_with(&mut self, other: &Self) { @@ -475,47 +559,53 @@ impl RoaringBitmap { impl FromIterator for RoaringBitmap { #[inline] - fn from_iter>(iterator: I) -> RoaringBitmap { + fn from_iter>(iterator: I) -> RoaringBitmap { imp::from_iter(iterator) } } impl<'a> FromIterator<&'a u32> for RoaringBitmap { #[inline] - fn from_iter>(iterator: I) -> RoaringBitmap { + fn from_iter>(iterator: I) -> RoaringBitmap { imp::from_iter_ref(iterator) } } impl Extend for RoaringBitmap { #[inline] - fn extend>(&mut self, iterator: I) { + fn extend>(&mut self, iterator: I) { imp::extend(self, iterator) } } impl<'a> Extend<&'a u32> for RoaringBitmap { #[inline] - fn extend>(&mut self, iterator: I) { + fn extend>(&mut self, iterator: I) { imp::extend_ref(self, iterator) } } -impl BitOr for RoaringBitmap { +impl BitOr for RoaringBitmap { + type Output = RoaringBitmap; + /// Unions the `rhs` into this `RoaringBitmap`. /// /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// - /// let rb1: RoaringBitmap = FromIterator::from_iter(1..4); - /// let rb2: RoaringBitmap = FromIterator::from_iter(2..5); - /// let rb3: RoaringBitmap = FromIterator::from_iter(1..5); + /// let rb1: RoaringBitmap = (1..4).collect(); + /// let rb2: RoaringBitmap = (2..5).collect(); + /// let rb3: RoaringBitmap = (1..5).collect(); /// /// let rb4 = rb1 | rb2; /// /// assert_eq!(rb3, rb4); + /// # } /// ``` #[inline] fn bitor(mut self, rhs: RoaringBitmap) -> RoaringBitmap { @@ -524,21 +614,27 @@ impl BitOr for RoaringBitmap { } } -impl<'a> BitOr for &'a RoaringBitmap { +impl<'a> BitOr for &'a RoaringBitmap { + type Output = RoaringBitmap; + /// Unions`rhs` and `self`, writes result in place to `rhs`. /// /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// - /// let rb1: RoaringBitmap = FromIterator::from_iter(1..4); - /// let rb2: RoaringBitmap = FromIterator::from_iter(2..5); - /// let rb3: RoaringBitmap = FromIterator::from_iter(1..5); + /// let rb1: RoaringBitmap = (1..4).collect(); + /// let rb2: RoaringBitmap = (2..5).collect(); + /// let rb3: RoaringBitmap = (1..5).collect(); /// /// let rb4 = &rb1 | rb2; /// /// assert_eq!(rb3, rb4); + /// # } /// ``` #[inline] fn bitor(self, mut rhs: RoaringBitmap) -> RoaringBitmap { @@ -547,21 +643,27 @@ impl<'a> BitOr for &'a RoaringBitmap { } } -impl<'a, 'b> BitOr<&'a RoaringBitmap, RoaringBitmap> for &'b RoaringBitmap { +impl<'a, 'b> BitOr<&'a RoaringBitmap> for &'b RoaringBitmap { + type Output = RoaringBitmap; + /// Unions`rhs` and `self`, allocates new bitmap for result. /// /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// - /// let rb1: RoaringBitmap = FromIterator::from_iter(1..4); - /// let rb2: RoaringBitmap = FromIterator::from_iter(2..5); - /// let rb3: RoaringBitmap = FromIterator::from_iter(1..5); + /// let rb1: RoaringBitmap = (1..4).collect(); + /// let rb2: RoaringBitmap = (2..5).collect(); + /// let rb3: RoaringBitmap = (1..5).collect(); /// /// let rb4 = rb1 | &rb2; /// /// assert_eq!(rb3, rb4); + /// # } /// ``` #[inline] fn bitor(self, rhs: &'a RoaringBitmap) -> RoaringBitmap { @@ -571,21 +673,27 @@ impl<'a, 'b> BitOr<&'a RoaringBitmap, RoaringBitmap> for &'b RoaringBitmap { } } -impl<'a> BitOr<&'a RoaringBitmap, RoaringBitmap> for RoaringBitmap { +impl<'a> BitOr<&'a RoaringBitmap> for RoaringBitmap { + type Output = RoaringBitmap; + /// Unions the `rhs` into this `RoaringBitmap`. /// /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// - /// let rb1: RoaringBitmap = FromIterator::from_iter(1..4); - /// let rb2: RoaringBitmap = FromIterator::from_iter(2..5); - /// let rb3: RoaringBitmap = FromIterator::from_iter(1..5); + /// let rb1: RoaringBitmap = (1..4).collect(); + /// let rb2: RoaringBitmap = (2..5).collect(); + /// let rb3: RoaringBitmap = (1..5).collect(); /// /// let rb4 = rb1 | &rb2; /// /// assert_eq!(rb3, rb4); + /// # } /// ``` #[inline] fn bitor(mut self, rhs: &'a RoaringBitmap) -> RoaringBitmap { @@ -594,21 +702,27 @@ impl<'a> BitOr<&'a RoaringBitmap, RoaringBitmap> for RoaringBitmap { } } -impl BitAnd for RoaringBitmap { +impl BitAnd for RoaringBitmap { + type Output = RoaringBitmap; + /// Intersects the `rhs` into this `RoaringBitmap`. /// /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// - /// let rb1: RoaringBitmap = FromIterator::from_iter(1..4); - /// let rb2: RoaringBitmap = FromIterator::from_iter(2..5); - /// let rb3: RoaringBitmap = FromIterator::from_iter(2..4); + /// let rb1: RoaringBitmap = (1..4).collect(); + /// let rb2: RoaringBitmap = (2..5).collect(); + /// let rb3: RoaringBitmap = (2..4).collect(); /// /// let rb4 = rb1 & rb2; /// /// assert_eq!(rb3, rb4); + /// # } /// ``` #[inline] fn bitand(mut self, rhs: RoaringBitmap) -> RoaringBitmap { @@ -617,21 +731,27 @@ impl BitAnd for RoaringBitmap { } } -impl<'a> BitAnd<&'a RoaringBitmap, RoaringBitmap> for RoaringBitmap { +impl<'a> BitAnd<&'a RoaringBitmap> for RoaringBitmap { + type Output = RoaringBitmap; + /// Intersects the `rhs` into this `RoaringBitmap`. /// /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// - /// let rb1: RoaringBitmap = FromIterator::from_iter(1..4); - /// let rb2: RoaringBitmap = FromIterator::from_iter(2..5); - /// let rb3: RoaringBitmap = FromIterator::from_iter(2..4); + /// let rb1: RoaringBitmap = (1..4).collect(); + /// let rb2: RoaringBitmap = (2..5).collect(); + /// let rb3: RoaringBitmap = (2..4).collect(); /// /// let rb4 = rb1 & &rb2; /// /// assert_eq!(rb3, rb4); + /// # } /// ``` #[inline] fn bitand(mut self, rhs: &'a RoaringBitmap) -> RoaringBitmap { @@ -640,21 +760,27 @@ impl<'a> BitAnd<&'a RoaringBitmap, RoaringBitmap> for RoaringBitmap { } } -impl<'a> BitAnd for &'a RoaringBitmap { +impl<'a> BitAnd for &'a RoaringBitmap { + type Output = RoaringBitmap; + /// Intersects `self` into the `rhs` `RoaringBitmap`. /// /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// - /// let rb1: RoaringBitmap = FromIterator::from_iter(1..4); - /// let rb2: RoaringBitmap = FromIterator::from_iter(2..5); - /// let rb3: RoaringBitmap = FromIterator::from_iter(2..4); + /// let rb1: RoaringBitmap = (1..4).collect(); + /// let rb2: RoaringBitmap = (2..5).collect(); + /// let rb3: RoaringBitmap = (2..4).collect(); /// /// let rb4 = &rb1 & rb2; /// /// assert_eq!(rb3, rb4); + /// # } /// ``` #[inline] fn bitand(self, mut rhs: RoaringBitmap) -> RoaringBitmap { @@ -663,21 +789,27 @@ impl<'a> BitAnd for &'a RoaringBitmap { } } -impl<'a, 'b> BitAnd<&'a RoaringBitmap, RoaringBitmap> for &'b RoaringBitmap { +impl<'a, 'b> BitAnd<&'a RoaringBitmap> for &'b RoaringBitmap { + type Output = RoaringBitmap; + /// Intersects `self` and `rhs` into a new `RoaringBitmap`. /// /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// - /// let rb1: RoaringBitmap = FromIterator::from_iter(1..4); - /// let rb2: RoaringBitmap = FromIterator::from_iter(2..5); - /// let rb3: RoaringBitmap = FromIterator::from_iter(2..4); + /// let rb1: RoaringBitmap = (1..4).collect(); + /// let rb2: RoaringBitmap = (2..5).collect(); + /// let rb3: RoaringBitmap = (2..4).collect(); /// /// let rb4 = &rb1 & &rb2; /// /// assert_eq!(rb3, rb4); + /// # } /// ``` #[inline] fn bitand(self, rhs: &'a RoaringBitmap) -> RoaringBitmap { @@ -687,21 +819,27 @@ impl<'a, 'b> BitAnd<&'a RoaringBitmap, RoaringBitmap> for &'b RoaringBitmap { } } -impl Sub for RoaringBitmap { +impl Sub for RoaringBitmap { + type Output = RoaringBitmap; + /// Subtracts the `rhs` into this `RoaringBitmap`. /// /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// - /// let rb1: RoaringBitmap = FromIterator::from_iter(1..4); - /// let rb2: RoaringBitmap = FromIterator::from_iter(3..5); - /// let rb3: RoaringBitmap = FromIterator::from_iter(1..3); + /// let rb1: RoaringBitmap = (1..4).collect(); + /// let rb2: RoaringBitmap = (3..5).collect(); + /// let rb3: RoaringBitmap = (1..3).collect(); /// /// let rb4 = rb1 - rb2; /// /// assert_eq!(rb3, rb4); + /// # } /// ``` #[inline] fn sub(mut self, rhs: RoaringBitmap) -> RoaringBitmap { @@ -710,21 +848,27 @@ impl Sub for RoaringBitmap { } } -impl<'a> Sub<&'a RoaringBitmap, RoaringBitmap> for RoaringBitmap { +impl<'a> Sub<&'a RoaringBitmap> for RoaringBitmap { + type Output = RoaringBitmap; + /// Subtracts the `rhs` into this `RoaringBitmap`. /// /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// - /// let rb1: RoaringBitmap = FromIterator::from_iter(1..4); - /// let rb2: RoaringBitmap = FromIterator::from_iter(3..5); - /// let rb3: RoaringBitmap = FromIterator::from_iter(1..3); + /// let rb1: RoaringBitmap = (1..4).collect(); + /// let rb2: RoaringBitmap = (3..5).collect(); + /// let rb3: RoaringBitmap = (1..3).collect(); /// /// let rb4 = rb1 - &rb2; /// /// assert_eq!(rb3, rb4); + /// # } /// ``` #[inline] fn sub(mut self, rhs: &'a RoaringBitmap) -> RoaringBitmap { @@ -733,21 +877,27 @@ impl<'a> Sub<&'a RoaringBitmap, RoaringBitmap> for RoaringBitmap { } } -impl<'a, 'b> Sub<&'a RoaringBitmap, RoaringBitmap> for &'b RoaringBitmap { +impl<'a, 'b> Sub<&'a RoaringBitmap> for &'b RoaringBitmap { + type Output = RoaringBitmap; + /// Subtracts `rhs` from `self` and allocates a new `RoaringBitmap`. /// /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// - /// let rb1: RoaringBitmap = FromIterator::from_iter(1..4); - /// let rb2: RoaringBitmap = FromIterator::from_iter(3..5); - /// let rb3: RoaringBitmap = FromIterator::from_iter(1..3); + /// let rb1: RoaringBitmap = (1..4).collect(); + /// let rb2: RoaringBitmap = (3..5).collect(); + /// let rb3: RoaringBitmap = (1..3).collect(); /// /// let rb4 = &rb1 - &rb2; /// /// assert_eq!(rb3, rb4); + /// # } /// ``` #[inline] fn sub(self, rhs: &'a RoaringBitmap) -> RoaringBitmap { @@ -757,21 +907,27 @@ impl<'a, 'b> Sub<&'a RoaringBitmap, RoaringBitmap> for &'b RoaringBitmap { } } -impl BitXor for RoaringBitmap { +impl BitXor for RoaringBitmap { + type Output = RoaringBitmap; + /// Subtracts the `rhs` into this `RoaringBitmap`. /// /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// - /// let rb1: RoaringBitmap = FromIterator::from_iter(1..4); - /// let rb2: RoaringBitmap = FromIterator::from_iter(3..6); - /// let rb3: RoaringBitmap = FromIterator::from_iter((1..3).chain(4..6)); + /// let rb1: RoaringBitmap = (1..4).collect(); + /// let rb2: RoaringBitmap = (3..6).collect(); + /// let rb3: RoaringBitmap = ((1..3).chain(4..6)).collect(); /// /// let rb4 = rb1 ^ rb2; /// /// assert_eq!(rb3, rb4); + /// # } /// ``` #[inline] fn bitxor(mut self, rhs: RoaringBitmap) -> RoaringBitmap { @@ -780,21 +936,27 @@ impl BitXor for RoaringBitmap { } } -impl<'a> BitXor<&'a RoaringBitmap, RoaringBitmap> for RoaringBitmap { +impl<'a> BitXor<&'a RoaringBitmap> for RoaringBitmap { + type Output = RoaringBitmap; + /// Exclusive ors the `rhs` into this `RoaringBitmap`. /// /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// - /// let rb1: RoaringBitmap = FromIterator::from_iter(1..4); - /// let rb2: RoaringBitmap = FromIterator::from_iter(3..6); - /// let rb3: RoaringBitmap = FromIterator::from_iter((1..3).chain(4..6)); + /// let rb1: RoaringBitmap = (1..4).collect(); + /// let rb2: RoaringBitmap = (3..6).collect(); + /// let rb3: RoaringBitmap = ((1..3).chain(4..6)).collect(); /// /// let rb4 = rb1 ^ &rb2; /// /// assert_eq!(rb3, rb4); + /// # } /// ``` #[inline] fn bitxor(mut self, rhs: &'a RoaringBitmap) -> RoaringBitmap { @@ -803,21 +965,27 @@ impl<'a> BitXor<&'a RoaringBitmap, RoaringBitmap> for RoaringBitmap { } } -impl<'a> BitXor for &'a RoaringBitmap { +impl<'a> BitXor for &'a RoaringBitmap { + type Output = RoaringBitmap; + /// Exclusive ors `rhs` and `self`, writes result in place to `rhs`. /// /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// - /// let rb1: RoaringBitmap = FromIterator::from_iter(1..4); - /// let rb2: RoaringBitmap = FromIterator::from_iter(3..6); - /// let rb3: RoaringBitmap = FromIterator::from_iter((1..3).chain(4..6)); + /// let rb1: RoaringBitmap = (1..4).collect(); + /// let rb2: RoaringBitmap = (3..6).collect(); + /// let rb3: RoaringBitmap = ((1..3).chain(4..6)).collect(); /// /// let rb4 = &rb1 ^ rb2; /// /// assert_eq!(rb3, rb4); + /// # } /// ``` #[inline] fn bitxor(self, mut rhs: RoaringBitmap) -> RoaringBitmap { @@ -826,21 +994,27 @@ impl<'a> BitXor for &'a RoaringBitmap { } } -impl<'a, 'b> BitXor<&'a RoaringBitmap, RoaringBitmap> for &'b RoaringBitmap { +impl<'a, 'b> BitXor<&'a RoaringBitmap> for &'b RoaringBitmap { + type Output = RoaringBitmap; + /// Exclusive ors `rhs` and `self`, allocates a new bitmap for the result. /// /// # Examples /// /// ```rust + /// # #![feature(slicing_syntax)] + /// # extern crate roaring; + /// # fn main() { /// use roaring::RoaringBitmap; /// - /// let rb1: RoaringBitmap = FromIterator::from_iter(1..4); - /// let rb2: RoaringBitmap = FromIterator::from_iter(3..6); - /// let rb3: RoaringBitmap = FromIterator::from_iter((1..3).chain(4..6)); + /// let rb1: RoaringBitmap = (1..4).collect(); + /// let rb2: RoaringBitmap = (3..6).collect(); + /// let rb3: RoaringBitmap = ((1..3).chain(4..6)).collect(); /// /// let rb4 = &rb1 ^ &rb2; /// /// assert_eq!(rb3, rb4); + /// # } /// ``` #[inline] fn bitxor(self, rhs: &'a RoaringBitmap) -> RoaringBitmap { diff --git a/src/store.rs b/src/store.rs index 3d058c5d..756ae036 100644 --- a/src/store.rs +++ b/src/store.rs @@ -1,6 +1,5 @@ use std::{ u16, u32 }; use std::num::Int; -use std::slice::BinarySearchResult::{ Found, NotFound }; use store::Store::{ Array, Bitmap }; @@ -14,15 +13,15 @@ fn bitmap_location(index: u16) -> (uint, uint) { } fn insert_array(vec: &mut Vec, index: u16) -> bool { - match vec.binary_search(|elem| elem.cmp(&index)) { - NotFound(loc) => { vec.insert(loc, index); true }, + match vec.binary_search_by(|elem| elem.cmp(&index)) { + Err(loc) => { vec.insert(loc, index); true }, _ => false, } } fn remove_array(vec: &mut Vec, index: u16) -> bool { - match vec.binary_search(|elem| elem.cmp(&index)) { - Found(loc) => { vec.remove(loc); true }, + match vec.binary_search_by(|elem| elem.cmp(&index)) { + Ok(loc) => { vec.remove(loc); true }, _ => false, } } @@ -48,9 +47,9 @@ fn remove_bitmap(bits: &mut [u32; 2048], index: u16) -> bool { } fn contains_array(vec: &Vec, index: u16) -> bool { - match vec.binary_search(|elem| elem.cmp(&index)) { - Found(_) => true, - NotFound(_) => false, + match vec.binary_search_by(|elem| elem.cmp(&index)) { + Ok(_) => true, + Err(_) => false, } } diff --git a/tests/clone.rs b/tests/clone.rs index 715f3398..a4bcd05b 100644 --- a/tests/clone.rs +++ b/tests/clone.rs @@ -1,9 +1,11 @@ +#![feature(slicing_syntax)] + extern crate roaring; use roaring::RoaringBitmap; #[test] fn array() { - let original: RoaringBitmap = FromIterator::from_iter(0..2000); + let original: RoaringBitmap = (0..2000).collect(); let clone = original.clone(); assert_eq!(clone, original); @@ -11,7 +13,7 @@ fn array() { #[test] fn bitmap() { - let original: RoaringBitmap = FromIterator::from_iter(0..6000); + let original: RoaringBitmap = (0..6000).collect(); let clone = original.clone(); assert_eq!(clone, original); @@ -19,7 +21,7 @@ fn bitmap() { #[test] fn arrays() { - let original: RoaringBitmap = FromIterator::from_iter((0..2000).chain(1000000..1002000).chain(2000000..2001000)); + let original: RoaringBitmap = (0..2000).chain(1000000..1002000).chain(2000000..2001000).collect(); let clone = original.clone(); assert_eq!(clone, original); @@ -27,7 +29,7 @@ fn arrays() { #[test] fn bitmaps() { - let original: RoaringBitmap = FromIterator::from_iter((0..6000).chain(1000000..1012000).chain(2000000..2010000)); + let original: RoaringBitmap = (0..6000).chain(1000000..1012000).chain(2000000..2010000).collect(); let clone = original.clone(); assert_eq!(clone, original); diff --git a/tests/difference.rs b/tests/difference.rs index a6ae1c27..56d7c9b6 100644 --- a/tests/difference.rs +++ b/tests/difference.rs @@ -1,90 +1,92 @@ +#![feature(slicing_syntax)] + extern crate roaring; use roaring::RoaringBitmap; #[test] fn array() { - let bitmap1: RoaringBitmap = FromIterator::from_iter(0..2000); - let bitmap2: RoaringBitmap = FromIterator::from_iter(1000..3000); + let bitmap1: RoaringBitmap = (0..2000).collect(); + let bitmap2: RoaringBitmap = (1000..3000).collect(); - let expected: RoaringBitmap = FromIterator::from_iter(0..1000); - let actual: RoaringBitmap = FromIterator::from_iter(bitmap1.difference(&bitmap2)); + let expected: RoaringBitmap = (0..1000).collect(); + let actual: RoaringBitmap = bitmap1.difference(&bitmap2).collect(); assert_eq!(actual, expected); } #[test] fn array_and_bitmap() { - let bitmap1: RoaringBitmap = FromIterator::from_iter(0..2000); - let bitmap2: RoaringBitmap = FromIterator::from_iter(1000..8000); + let bitmap1: RoaringBitmap = (0..2000).collect(); + let bitmap2: RoaringBitmap = (1000..8000).collect(); - let expected: RoaringBitmap = FromIterator::from_iter(0..1000); - let actual: RoaringBitmap = FromIterator::from_iter(bitmap1.difference(&bitmap2)); + let expected: RoaringBitmap = (0..1000).collect(); + let actual: RoaringBitmap = bitmap1.difference(&bitmap2).collect(); assert_eq!(actual, expected); } #[test] fn bitmap_to_bitmap() { - let bitmap1: RoaringBitmap = FromIterator::from_iter(0..12000); - let bitmap2: RoaringBitmap = FromIterator::from_iter(6000..18000); + let bitmap1: RoaringBitmap = (0..12000).collect(); + let bitmap2: RoaringBitmap = (6000..18000).collect(); - let expected: RoaringBitmap = FromIterator::from_iter(0..6000); - let actual: RoaringBitmap = FromIterator::from_iter(bitmap1.difference(&bitmap2)); + let expected: RoaringBitmap = (0..6000).collect(); + let actual: RoaringBitmap = bitmap1.difference(&bitmap2).collect(); assert_eq!(actual, expected); } #[test] fn bitmap_to_array() { - let bitmap1: RoaringBitmap = FromIterator::from_iter(0..6000); - let bitmap2: RoaringBitmap = FromIterator::from_iter(3000..9000); + let bitmap1: RoaringBitmap = (0..6000).collect(); + let bitmap2: RoaringBitmap = (3000..9000).collect(); - let expected: RoaringBitmap = FromIterator::from_iter(0..3000); - let actual: RoaringBitmap = FromIterator::from_iter(bitmap1.difference(&bitmap2)); + let expected: RoaringBitmap = (0..3000).collect(); + let actual: RoaringBitmap = bitmap1.difference(&bitmap2).collect(); assert_eq!(actual, expected); } #[test] fn bitmap_and_array_to_bitmap() { - let bitmap1: RoaringBitmap = FromIterator::from_iter(0..12000); - let bitmap2: RoaringBitmap = FromIterator::from_iter(9000..12000); + let bitmap1: RoaringBitmap = (0..12000).collect(); + let bitmap2: RoaringBitmap = (9000..12000).collect(); - let expected: RoaringBitmap = FromIterator::from_iter(0..9000); - let actual: RoaringBitmap = FromIterator::from_iter(bitmap1.difference(&bitmap2)); + let expected: RoaringBitmap = (0..9000).collect(); + let actual: RoaringBitmap = bitmap1.difference(&bitmap2).collect(); assert_eq!(actual, expected); } #[test] fn bitmap_and_array_to_array() { - let bitmap1: RoaringBitmap = FromIterator::from_iter(0..6000); - let bitmap2: RoaringBitmap = FromIterator::from_iter(3000..6000); + let bitmap1: RoaringBitmap = (0..6000).collect(); + let bitmap2: RoaringBitmap = (3000..6000).collect(); - let expected: RoaringBitmap = FromIterator::from_iter(0..3000); - let actual: RoaringBitmap = FromIterator::from_iter(bitmap1.difference(&bitmap2)); + let expected: RoaringBitmap = (0..3000).collect(); + let actual: RoaringBitmap = bitmap1.difference(&bitmap2).collect(); assert_eq!(actual, expected); } #[test] fn arrays() { - let bitmap1: RoaringBitmap = FromIterator::from_iter((0..2000).chain(1000000..1002000).chain(2000000..2001000)); - let bitmap2: RoaringBitmap = FromIterator::from_iter((1000..3000).chain(1001000..1003000).chain(2000000..2001000)); + let bitmap1: RoaringBitmap = (0..2000).chain(1000000..1002000).chain(2000000..2001000).collect(); + let bitmap2: RoaringBitmap = (1000..3000).chain(1001000..1003000).chain(2000000..2001000).collect(); - let expected: RoaringBitmap = FromIterator::from_iter((0..1000).chain(1000000..1001000)); - let actual: RoaringBitmap = FromIterator::from_iter(bitmap1.difference(&bitmap2)); + let expected: RoaringBitmap = (0..1000).chain(1000000..1001000).collect(); + let actual: RoaringBitmap = bitmap1.difference(&bitmap2).collect(); assert_eq!(actual, expected); } #[test] fn bitmaps() { - let bitmap1: RoaringBitmap = FromIterator::from_iter((0..6000).chain(1000000..1012000).chain(2000000..2010000)); - let bitmap2: RoaringBitmap = FromIterator::from_iter((3000..9000).chain(1006000..1018000).chain(2000000..2010000)); + let bitmap1: RoaringBitmap = (0..6000).chain(1000000..1012000).chain(2000000..2010000).collect(); + let bitmap2: RoaringBitmap = (3000..9000).chain(1006000..1018000).chain(2000000..2010000).collect(); - let expected: RoaringBitmap = FromIterator::from_iter((0..3000).chain(1000000..1006000)); - let actual: RoaringBitmap = FromIterator::from_iter(bitmap1.difference(&bitmap2)); + let expected: RoaringBitmap = (0..3000).chain(1000000..1006000).collect(); + let actual: RoaringBitmap = bitmap1.difference(&bitmap2).collect(); assert_eq!(actual, expected); } diff --git a/tests/difference_with.rs b/tests/difference_with.rs index a00c183a..8d034f56 100644 --- a/tests/difference_with.rs +++ b/tests/difference_with.rs @@ -1,11 +1,13 @@ +#![feature(slicing_syntax)] + extern crate roaring; use roaring::RoaringBitmap; #[test] fn array() { - let mut bitmap1: RoaringBitmap = FromIterator::from_iter(0..2000); - let bitmap2: RoaringBitmap = FromIterator::from_iter(1000..3000); - let bitmap3: RoaringBitmap = FromIterator::from_iter(0..1000); + let mut bitmap1: RoaringBitmap = (0..2000).collect(); + let bitmap2: RoaringBitmap = (1000..3000).collect(); + let bitmap3: RoaringBitmap = (0..1000).collect(); bitmap1.difference_with(&bitmap2); @@ -14,9 +16,9 @@ fn array() { #[test] fn array_and_bitmap() { - let mut bitmap1: RoaringBitmap = FromIterator::from_iter(0..2000); - let bitmap2: RoaringBitmap = FromIterator::from_iter(1000..8000); - let bitmap3: RoaringBitmap = FromIterator::from_iter(0..1000); + let mut bitmap1: RoaringBitmap = (0..2000).collect(); + let bitmap2: RoaringBitmap = (1000..8000).collect(); + let bitmap3: RoaringBitmap = (0..1000).collect(); bitmap1.difference_with(&bitmap2); @@ -25,9 +27,9 @@ fn array_and_bitmap() { #[test] fn bitmap_to_bitmap() { - let mut bitmap1: RoaringBitmap = FromIterator::from_iter(0..12000); - let bitmap2: RoaringBitmap = FromIterator::from_iter(6000..18000); - let bitmap3: RoaringBitmap = FromIterator::from_iter(0..6000); + let mut bitmap1: RoaringBitmap = (0..12000).collect(); + let bitmap2: RoaringBitmap = (6000..18000).collect(); + let bitmap3: RoaringBitmap = (0..6000).collect(); bitmap1.difference_with(&bitmap2); @@ -36,9 +38,9 @@ fn bitmap_to_bitmap() { #[test] fn bitmap_to_array() { - let mut bitmap1: RoaringBitmap = FromIterator::from_iter(0..6000); - let bitmap2: RoaringBitmap = FromIterator::from_iter(3000..9000); - let bitmap3: RoaringBitmap = FromIterator::from_iter(0..3000); + let mut bitmap1: RoaringBitmap = (0..6000).collect(); + let bitmap2: RoaringBitmap = (3000..9000).collect(); + let bitmap3: RoaringBitmap = (0..3000).collect(); bitmap1.difference_with(&bitmap2); @@ -47,9 +49,9 @@ fn bitmap_to_array() { #[test] fn bitmap_and_array_to_bitmap() { - let mut bitmap1: RoaringBitmap = FromIterator::from_iter(0..12000); - let bitmap2: RoaringBitmap = FromIterator::from_iter(9000..12000); - let bitmap3: RoaringBitmap = FromIterator::from_iter(0..9000); + let mut bitmap1: RoaringBitmap = (0..12000).collect(); + let bitmap2: RoaringBitmap = (9000..12000).collect(); + let bitmap3: RoaringBitmap = (0..9000).collect(); bitmap1.difference_with(&bitmap2); @@ -58,9 +60,9 @@ fn bitmap_and_array_to_bitmap() { #[test] fn bitmap_and_array_to_array() { - let mut bitmap1: RoaringBitmap = FromIterator::from_iter(0..6000); - let bitmap2: RoaringBitmap = FromIterator::from_iter(3000..6000); - let bitmap3: RoaringBitmap = FromIterator::from_iter(0..3000); + let mut bitmap1: RoaringBitmap = (0..6000).collect(); + let bitmap2: RoaringBitmap = (3000..6000).collect(); + let bitmap3: RoaringBitmap = (0..3000).collect(); bitmap1.difference_with(&bitmap2); @@ -69,9 +71,9 @@ fn bitmap_and_array_to_array() { #[test] fn arrays() { - let mut bitmap1: RoaringBitmap = FromIterator::from_iter((0..2000).chain(1000000..1002000).chain(2000000..2001000)); - let bitmap2: RoaringBitmap = FromIterator::from_iter((1000..3000).chain(1001000..1003000).chain(2000000..2001000)); - let bitmap3: RoaringBitmap = FromIterator::from_iter((0..1000).chain(1000000..1001000)); + let mut bitmap1: RoaringBitmap = (0..2000).chain(1000000..1002000).chain(2000000..2001000).collect(); + let bitmap2: RoaringBitmap = (1000..3000).chain(1001000..1003000).chain(2000000..2001000).collect(); + let bitmap3: RoaringBitmap = (0..1000).chain(1000000..1001000).collect(); bitmap1.difference_with(&bitmap2); @@ -80,9 +82,9 @@ fn arrays() { #[test] fn bitmaps() { - let mut bitmap1: RoaringBitmap = FromIterator::from_iter((0..6000).chain(1000000..1012000).chain(2000000..2010000)); - let bitmap2: RoaringBitmap = FromIterator::from_iter((3000..9000).chain(1006000..1018000).chain(2000000..2010000)); - let bitmap3: RoaringBitmap = FromIterator::from_iter((0..3000).chain(1000000..1006000)); + let mut bitmap1: RoaringBitmap = (0..6000).chain(1000000..1012000).chain(2000000..2010000).collect(); + let bitmap2: RoaringBitmap = (3000..9000).chain(1006000..1018000).chain(2000000..2010000).collect(); + let bitmap3: RoaringBitmap = (0..3000).chain(1000000..1006000).collect(); bitmap1.difference_with(&bitmap2); diff --git a/tests/intersect_with.rs b/tests/intersect_with.rs index 7da46cb1..15148928 100644 --- a/tests/intersect_with.rs +++ b/tests/intersect_with.rs @@ -1,11 +1,13 @@ +#![feature(slicing_syntax)] + extern crate roaring; use roaring::RoaringBitmap; #[test] fn array() { - let mut bitmap1: RoaringBitmap = FromIterator::from_iter(0..2000); - let bitmap2: RoaringBitmap = FromIterator::from_iter(1000..3000); - let bitmap3: RoaringBitmap = FromIterator::from_iter(1000..2000); + let mut bitmap1: RoaringBitmap = (0..2000).collect(); + let bitmap2: RoaringBitmap = (1000..3000).collect(); + let bitmap3: RoaringBitmap = (1000..2000).collect(); bitmap1.intersect_with(&bitmap2); @@ -14,9 +16,9 @@ fn array() { #[test] fn array_and_bitmap() { - let mut bitmap1: RoaringBitmap = FromIterator::from_iter(0..2000); - let bitmap2: RoaringBitmap = FromIterator::from_iter(1000..8000); - let bitmap3: RoaringBitmap = FromIterator::from_iter(1000..2000); + let mut bitmap1: RoaringBitmap = (0..2000).collect(); + let bitmap2: RoaringBitmap = (1000..8000).collect(); + let bitmap3: RoaringBitmap = (1000..2000).collect(); bitmap1.intersect_with(&bitmap2); @@ -25,9 +27,9 @@ fn array_and_bitmap() { #[test] fn bitmap_to_bitmap() { - let mut bitmap1: RoaringBitmap = FromIterator::from_iter(0..12000); - let bitmap2: RoaringBitmap = FromIterator::from_iter(6000..18000); - let bitmap3: RoaringBitmap = FromIterator::from_iter(6000..12000); + let mut bitmap1: RoaringBitmap = (0..12000).collect(); + let bitmap2: RoaringBitmap = (6000..18000).collect(); + let bitmap3: RoaringBitmap = (6000..12000).collect(); bitmap1.intersect_with(&bitmap2); @@ -36,9 +38,9 @@ fn bitmap_to_bitmap() { #[test] fn bitmap_to_array() { - let mut bitmap1: RoaringBitmap = FromIterator::from_iter(0..6000); - let bitmap2: RoaringBitmap = FromIterator::from_iter(3000..9000); - let bitmap3: RoaringBitmap = FromIterator::from_iter(3000..6000); + let mut bitmap1: RoaringBitmap = (0..6000).collect(); + let bitmap2: RoaringBitmap = (3000..9000).collect(); + let bitmap3: RoaringBitmap = (3000..6000).collect(); bitmap1.intersect_with(&bitmap2); @@ -47,9 +49,9 @@ fn bitmap_to_array() { #[test] fn bitmap_and_array() { - let mut bitmap1: RoaringBitmap = FromIterator::from_iter(0..12000); - let bitmap2: RoaringBitmap = FromIterator::from_iter(7000..9000); - let bitmap3: RoaringBitmap = FromIterator::from_iter(7000..9000); + let mut bitmap1: RoaringBitmap = (0..12000).collect(); + let bitmap2: RoaringBitmap = (7000..9000).collect(); + let bitmap3: RoaringBitmap = (7000..9000).collect(); bitmap1.intersect_with(&bitmap2); @@ -58,9 +60,9 @@ fn bitmap_and_array() { #[test] fn arrays() { - let mut bitmap1: RoaringBitmap = FromIterator::from_iter((0..2000).chain(1000000..1002000).chain(3000000..3001000)); - let bitmap2: RoaringBitmap = FromIterator::from_iter((1000..3000).chain(1001000..1003000).chain(2000000..2001000)); - let bitmap3: RoaringBitmap = FromIterator::from_iter((1000..2000).chain(1001000..1002000)); + let mut bitmap1: RoaringBitmap = (0..2000).chain(1000000..1002000).chain(3000000..3001000).collect(); + let bitmap2: RoaringBitmap = (1000..3000).chain(1001000..1003000).chain(2000000..2001000).collect(); + let bitmap3: RoaringBitmap = (1000..2000).chain(1001000..1002000).collect(); bitmap1.intersect_with(&bitmap2); @@ -69,9 +71,9 @@ fn arrays() { #[test] fn bitmaps() { - let mut bitmap1: RoaringBitmap = FromIterator::from_iter((0..6000).chain(1000000..1012000).chain(3000000..3010000)); - let bitmap2: RoaringBitmap = FromIterator::from_iter((3000..9000).chain(1006000..1018000).chain(2000000..2010000)); - let bitmap3: RoaringBitmap = FromIterator::from_iter((3000..6000).chain(1006000..1012000)); + let mut bitmap1: RoaringBitmap = (0..6000).chain(1000000..1012000).chain(3000000..3010000).collect(); + let bitmap2: RoaringBitmap = (3000..9000).chain(1006000..1018000).chain(2000000..2010000).collect(); + let bitmap3: RoaringBitmap = (3000..6000).chain(1006000..1012000).collect(); bitmap1.intersect_with(&bitmap2); diff --git a/tests/is_disjoint.rs b/tests/is_disjoint.rs index 713f38ef..025dd700 100644 --- a/tests/is_disjoint.rs +++ b/tests/is_disjoint.rs @@ -1,58 +1,60 @@ +#![feature(slicing_syntax)] + extern crate roaring; use roaring::RoaringBitmap; #[test] fn array() { - let bitmap1: RoaringBitmap = FromIterator::from_iter(0..2000); - let bitmap2: RoaringBitmap = FromIterator::from_iter(4000..6000); + let bitmap1: RoaringBitmap = (0..2000).collect(); + let bitmap2: RoaringBitmap = (4000..6000).collect(); assert_eq!(bitmap1.is_disjoint(&bitmap2), true); } #[test] fn array_not() { - let bitmap1: RoaringBitmap = FromIterator::from_iter(0..4000); - let bitmap2: RoaringBitmap = FromIterator::from_iter(2000..6000); + let bitmap1: RoaringBitmap = (0..4000).collect(); + let bitmap2: RoaringBitmap = (2000..6000).collect(); assert_eq!(bitmap1.is_disjoint(&bitmap2), false); } #[test] fn bitmap() { - let bitmap1: RoaringBitmap = FromIterator::from_iter(0..6000); - let bitmap2: RoaringBitmap = FromIterator::from_iter(10000..16000); + let bitmap1: RoaringBitmap = (0..6000).collect(); + let bitmap2: RoaringBitmap = (10000..16000).collect(); assert_eq!(bitmap1.is_disjoint(&bitmap2), true); } #[test] fn bitmap_not() { - let bitmap1: RoaringBitmap = FromIterator::from_iter(0..10000); - let bitmap2: RoaringBitmap = FromIterator::from_iter(5000..15000); + let bitmap1: RoaringBitmap = (0..10000).collect(); + let bitmap2: RoaringBitmap = (5000..15000).collect(); assert_eq!(bitmap1.is_disjoint(&bitmap2), false); } #[test] fn arrays() { - let bitmap1: RoaringBitmap = FromIterator::from_iter((0..2000).chain(1000000..1002000).chain(2000000..2002000)); - let bitmap2: RoaringBitmap = FromIterator::from_iter((100000..102000).chain(1100000..1102000)); + let bitmap1: RoaringBitmap = (0..2000).chain(1000000..1002000).chain(2000000..2002000).collect(); + let bitmap2: RoaringBitmap = (100000..102000).chain(1100000..1102000).collect(); assert_eq!(bitmap1.is_disjoint(&bitmap2), true); } #[test] fn arrays_not() { - let bitmap1: RoaringBitmap = FromIterator::from_iter((0..2000).chain(0..1002000).chain(2000000..2002000)); - let bitmap2: RoaringBitmap = FromIterator::from_iter((100000..102000).chain(1001000..1003000)); + let bitmap1: RoaringBitmap = (0..2000).chain(0..1002000).chain(2000000..2002000).collect(); + let bitmap2: RoaringBitmap = (100000..102000).chain(1001000..1003000).collect(); assert_eq!(bitmap1.is_disjoint(&bitmap2), false); } #[test] fn bitmaps() { - let bitmap1: RoaringBitmap = FromIterator::from_iter((0..6000).chain(1000000..1006000).chain(2000000..2006000)); - let bitmap2: RoaringBitmap = FromIterator::from_iter((100000..106000).chain(1100000..1106000)); + let bitmap1: RoaringBitmap = (0..6000).chain(1000000..1006000).chain(2000000..2006000).collect(); + let bitmap2: RoaringBitmap = (100000..106000).chain(1100000..1106000).collect(); assert_eq!(bitmap1.is_disjoint(&bitmap2), true); } #[test] fn bitmaps_not() { - let bitmap1: RoaringBitmap = FromIterator::from_iter((0..6000).chain(0..1006000).chain(2000000..2006000)); - let bitmap2: RoaringBitmap = FromIterator::from_iter((100000..106000).chain(1004000..1008000)); + let bitmap1: RoaringBitmap = (0..6000).chain(0..1006000).chain(2000000..2006000).collect(); + let bitmap2: RoaringBitmap = (100000..106000).chain(1004000..1008000).collect(); assert_eq!(bitmap1.is_disjoint(&bitmap2), false); } diff --git a/tests/is_subset.rs b/tests/is_subset.rs index a4acaf0d..973bbb7c 100644 --- a/tests/is_subset.rs +++ b/tests/is_subset.rs @@ -1,79 +1,81 @@ +#![feature(slicing_syntax)] + extern crate roaring; use roaring::RoaringBitmap; #[test] fn array_not() { - let sup: RoaringBitmap = FromIterator::from_iter(0..2000); - let sub: RoaringBitmap = FromIterator::from_iter(1000..3000); + let sup: RoaringBitmap = (0..2000).collect(); + let sub: RoaringBitmap = (1000..3000).collect(); assert_eq!(sub.is_subset(&sup), false); } #[test] fn array() { - let sup: RoaringBitmap = FromIterator::from_iter(0..4000); - let sub: RoaringBitmap = FromIterator::from_iter(2000..3000); + let sup: RoaringBitmap = (0..4000).collect(); + let sub: RoaringBitmap = (2000..3000).collect(); assert_eq!(sub.is_subset(&sup), true); } #[test] fn array_bitmap_not() { - let sup: RoaringBitmap = FromIterator::from_iter(0..2000); - let sub: RoaringBitmap = FromIterator::from_iter(1000..15000); + let sup: RoaringBitmap = (0..2000).collect(); + let sub: RoaringBitmap = (1000..15000).collect(); assert_eq!(sub.is_subset(&sup), false); } #[test] fn bitmap_not() { - let sup: RoaringBitmap = FromIterator::from_iter(0..6000); - let sub: RoaringBitmap = FromIterator::from_iter(4000..10000); + let sup: RoaringBitmap = (0..6000).collect(); + let sub: RoaringBitmap = (4000..10000).collect(); assert_eq!(sub.is_subset(&sup), false); } #[test] fn bitmap() { - let sup: RoaringBitmap = FromIterator::from_iter(0..20000); - let sub: RoaringBitmap = FromIterator::from_iter(5000..15000); + let sup: RoaringBitmap = (0..20000).collect(); + let sub: RoaringBitmap = (5000..15000).collect(); assert_eq!(sub.is_subset(&sup), true); } #[test] fn bitmap_array_not() { - let sup: RoaringBitmap = FromIterator::from_iter(0..20000); - let sub: RoaringBitmap = FromIterator::from_iter(19000..21000); + let sup: RoaringBitmap = (0..20000).collect(); + let sub: RoaringBitmap = (19000..21000).collect(); assert_eq!(sub.is_subset(&sup), false); } #[test] fn bitmap_array() { - let sup: RoaringBitmap = FromIterator::from_iter(0..20000); - let sub: RoaringBitmap = FromIterator::from_iter(18000..20000); + let sup: RoaringBitmap = (0..20000).collect(); + let sub: RoaringBitmap = (18000..20000).collect(); assert_eq!(sub.is_subset(&sup), true); } #[test] fn arrays_not() { - let sup: RoaringBitmap = FromIterator::from_iter((0..2000).chain(1_000_000..1_002_000)); - let sub: RoaringBitmap = FromIterator::from_iter((100_000..102_000).chain(1_100_000..1_102_000)); + let sup: RoaringBitmap = (0..2000).chain(1_000_000..1_002_000).collect(); + let sub: RoaringBitmap = (100_000..102_000).chain(1_100_000..1_102_000).collect(); assert_eq!(sub.is_subset(&sup), false); } #[test] fn arrays() { - let sup: RoaringBitmap = FromIterator::from_iter((0..3000).chain(100000..103000)); - let sub: RoaringBitmap = FromIterator::from_iter((0..2000).chain(100000..102000)); + let sup: RoaringBitmap = (0..3000).chain(100000..103000).collect(); + let sub: RoaringBitmap = (0..2000).chain(100000..102000).collect(); assert_eq!(sub.is_subset(&sup), true); } #[test] fn bitmaps_not() { - let sup: RoaringBitmap = FromIterator::from_iter((0..6000).chain(1000000..1006000).chain(2000000..2010000)); - let sub: RoaringBitmap = FromIterator::from_iter((100000..106000).chain(1100000..1106000)); + let sup: RoaringBitmap = (0..6000).chain(1000000..1006000).chain(2000000..2010000).collect(); + let sub: RoaringBitmap = (100000..106000).chain(1100000..1106000).collect(); assert_eq!(sub.is_subset(&sup), false); } #[test] fn bitmaps() { - let sup: RoaringBitmap = FromIterator::from_iter((0..1_000_000).chain(2000000..2010000)); - let sub: RoaringBitmap = FromIterator::from_iter((0..10_000).chain(500_000..510_000)); + let sup: RoaringBitmap = (0..1_000_000).chain(2000000..2010000).collect(); + let sub: RoaringBitmap = (0..10_000).chain(500_000..510_000).collect(); assert_eq!(sub.is_subset(&sup), true); } diff --git a/tests/iter.rs b/tests/iter.rs index 11bc3ffc..0265df5f 100644 --- a/tests/iter.rs +++ b/tests/iter.rs @@ -1,34 +1,36 @@ +#![feature(slicing_syntax)] + extern crate roaring; use roaring::RoaringBitmap; #[test] fn array() { - let original: RoaringBitmap = FromIterator::from_iter(0..2000); - let clone: RoaringBitmap = FromIterator::from_iter(original.iter()); + let original: RoaringBitmap = (0..2000).collect(); + let clone: RoaringBitmap = (original.iter()).collect(); assert_eq!(clone, original); } #[test] fn bitmap() { - let original: RoaringBitmap = FromIterator::from_iter(0..6000); - let clone: RoaringBitmap = FromIterator::from_iter(original.iter()); + let original: RoaringBitmap = (0..6000).collect(); + let clone: RoaringBitmap = (original.iter()).collect(); assert_eq!(clone, original); } #[test] fn arrays() { - let original: RoaringBitmap = FromIterator::from_iter((0..2000).chain(1000000..1002000).chain(2000000..2001000)); - let clone: RoaringBitmap = FromIterator::from_iter(original.iter()); + let original: RoaringBitmap = (0..2000).chain(1000000..1002000).chain(2000000..2001000).collect(); + let clone: RoaringBitmap = (original.iter()).collect(); assert_eq!(clone, original); } #[test] fn bitmaps() { - let original: RoaringBitmap = FromIterator::from_iter((0..6000).chain(1000000..1012000).chain(2000000..2010000)); - let clone: RoaringBitmap = FromIterator::from_iter(original.iter()); + let original: RoaringBitmap = (0..6000).chain(1000000..1012000).chain(2000000..2010000).collect(); + let clone: RoaringBitmap = (original.iter()).collect(); assert_eq!(clone, original); } diff --git a/tests/lib.rs b/tests/lib.rs index 45490b86..c9d02d3b 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -1,3 +1,5 @@ +#![feature(slicing_syntax)] + extern crate roaring; use std::{ u32 }; @@ -38,7 +40,7 @@ fn smoke() { #[test] fn to_bitmap() { - let bitmap: RoaringBitmap = FromIterator::from_iter(0..5000); + let bitmap: RoaringBitmap = (0..5000).collect(); assert_eq!(bitmap.len(), 5000); for i in 1..5000 { assert_eq!(bitmap.contains(i), true); @@ -48,7 +50,7 @@ fn to_bitmap() { #[test] fn to_array() { - let mut bitmap: RoaringBitmap = FromIterator::from_iter(0..5000); + let mut bitmap: RoaringBitmap = (0..5000).collect(); for i in 3000..5000 { bitmap.remove(i); } diff --git a/tests/ops.rs b/tests/ops.rs index a7b12607..30cd4305 100644 --- a/tests/ops.rs +++ b/tests/ops.rs @@ -1,12 +1,14 @@ +#![feature(slicing_syntax)] + extern crate roaring; use roaring::RoaringBitmap; #[test] fn or() { - let rb1: RoaringBitmap = FromIterator::from_iter(1..4); - let rb2: RoaringBitmap = FromIterator::from_iter(3..6); - let rb3: RoaringBitmap = FromIterator::from_iter(1..6); + let rb1: RoaringBitmap = (1..4).collect(); + let rb2: RoaringBitmap = (3..6).collect(); + let rb3: RoaringBitmap = (1..6).collect(); assert_eq!(rb3, &rb1 | &rb2); assert_eq!(rb3, rb1 | rb2 | &rb3); @@ -14,9 +16,9 @@ fn or() { #[test] fn and() { - let rb1: RoaringBitmap = FromIterator::from_iter(1..4); - let rb2: RoaringBitmap = FromIterator::from_iter(3..6); - let rb3: RoaringBitmap = FromIterator::from_iter(3..4); + let rb1: RoaringBitmap = (1..4).collect(); + let rb2: RoaringBitmap = (3..6).collect(); + let rb3: RoaringBitmap = (3..4).collect(); assert_eq!(rb3, &rb1 & &rb2); assert_eq!(rb3, rb1 & rb2 & &rb3); @@ -24,10 +26,10 @@ fn and() { #[test] fn sub() { - let rb1: RoaringBitmap = FromIterator::from_iter(1..4); - let rb2: RoaringBitmap = FromIterator::from_iter(3..6); - let rb3: RoaringBitmap = FromIterator::from_iter(1..3); - let rb4: RoaringBitmap = FromIterator::from_iter(0..0); + let rb1: RoaringBitmap = (1..4).collect(); + let rb2: RoaringBitmap = (3..6).collect(); + let rb3: RoaringBitmap = (1..3).collect(); + let rb4: RoaringBitmap = (0..0).collect(); assert_eq!(rb3, &rb1 - &rb2); assert_eq!(rb4, rb1 - rb2 - rb3); @@ -35,10 +37,10 @@ fn sub() { #[test] fn xor() { - let rb1: RoaringBitmap = FromIterator::from_iter(1..4); - let rb2: RoaringBitmap = FromIterator::from_iter(3..6); - let rb3: RoaringBitmap = FromIterator::from_iter((1..3).chain(4..6)); - let rb4: RoaringBitmap = FromIterator::from_iter(0..0); + let rb1: RoaringBitmap = (1..4).collect(); + let rb2: RoaringBitmap = (3..6).collect(); + let rb3: RoaringBitmap = (1..3).chain(4..6).collect(); + let rb4: RoaringBitmap = (0..0).collect(); assert_eq!(rb3, &rb1 ^ &rb2); assert_eq!(rb4, rb1 ^ rb2 ^ rb3); diff --git a/tests/symmetric_difference_with.rs b/tests/symmetric_difference_with.rs index 386a16a6..a4e52958 100644 --- a/tests/symmetric_difference_with.rs +++ b/tests/symmetric_difference_with.rs @@ -1,12 +1,14 @@ +#![feature(slicing_syntax)] + extern crate roaring; use roaring::RoaringBitmap; #[test] fn array() { - let mut bitmap1: RoaringBitmap = FromIterator::from_iter(0..2000); - let bitmap2: RoaringBitmap = FromIterator::from_iter(1000..3000); - let bitmap3: RoaringBitmap = FromIterator::from_iter((0..1000).chain(2000..3000)); + let mut bitmap1: RoaringBitmap = (0..2000).collect(); + let bitmap2: RoaringBitmap = (1000..3000).collect(); + let bitmap3: RoaringBitmap = (0..1000).chain(2000..3000).collect(); bitmap1.symmetric_difference_with(&bitmap2); @@ -15,9 +17,9 @@ fn array() { #[test] fn array_and_bitmap() { - let mut bitmap1: RoaringBitmap = FromIterator::from_iter(0..2000); - let bitmap2: RoaringBitmap = FromIterator::from_iter(1000..8000); - let bitmap3: RoaringBitmap = FromIterator::from_iter((0..1000).chain(2000..8000)); + let mut bitmap1: RoaringBitmap = (0..2000).collect(); + let bitmap2: RoaringBitmap = (1000..8000).collect(); + let bitmap3: RoaringBitmap = (0..1000).chain(2000..8000).collect(); bitmap1.symmetric_difference_with(&bitmap2); @@ -26,9 +28,9 @@ fn array_and_bitmap() { #[test] fn bitmap_to_bitmap() { - let mut bitmap1: RoaringBitmap = FromIterator::from_iter(0..12000); - let bitmap2: RoaringBitmap = FromIterator::from_iter(6000..18000); - let bitmap3: RoaringBitmap = FromIterator::from_iter((0..6000).chain(12000..18000)); + let mut bitmap1: RoaringBitmap = (0..12000).collect(); + let bitmap2: RoaringBitmap = (6000..18000).collect(); + let bitmap3: RoaringBitmap = (0..6000).chain(12000..18000).collect(); bitmap1.symmetric_difference_with(&bitmap2); @@ -37,9 +39,9 @@ fn bitmap_to_bitmap() { #[test] fn bitmap_to_array() { - let mut bitmap1: RoaringBitmap = FromIterator::from_iter(0..6000); - let bitmap2: RoaringBitmap = FromIterator::from_iter(2000..7000); - let bitmap3: RoaringBitmap = FromIterator::from_iter((0..2000).chain(6000..7000)); + let mut bitmap1: RoaringBitmap = (0..6000).collect(); + let bitmap2: RoaringBitmap = (2000..7000).collect(); + let bitmap3: RoaringBitmap = (0..2000).chain(6000..7000).collect(); bitmap1.symmetric_difference_with(&bitmap2); @@ -48,9 +50,9 @@ fn bitmap_to_array() { #[test] fn bitmap_and_array_to_bitmap() { - let mut bitmap1: RoaringBitmap = FromIterator::from_iter(0..12000); - let bitmap2: RoaringBitmap = FromIterator::from_iter(11000..14000); - let bitmap3: RoaringBitmap = FromIterator::from_iter((0..11000).chain(12000..14000)); + let mut bitmap1: RoaringBitmap = (0..12000).collect(); + let bitmap2: RoaringBitmap = (11000..14000).collect(); + let bitmap3: RoaringBitmap = (0..11000).chain(12000..14000).collect(); bitmap1.symmetric_difference_with(&bitmap2); @@ -59,9 +61,9 @@ fn bitmap_and_array_to_bitmap() { #[test] fn bitmap_and_array_to_array() { - let mut bitmap1: RoaringBitmap = FromIterator::from_iter(0..6000); - let bitmap2: RoaringBitmap = FromIterator::from_iter(3000..7000); - let bitmap3: RoaringBitmap = FromIterator::from_iter((0..3000).chain(6000..7000)); + let mut bitmap1: RoaringBitmap = (0..6000).collect(); + let bitmap2: RoaringBitmap = (3000..7000).collect(); + let bitmap3: RoaringBitmap = (0..3000).chain(6000..7000).collect(); bitmap1.symmetric_difference_with(&bitmap2); @@ -70,9 +72,9 @@ fn bitmap_and_array_to_array() { #[test] fn arrays() { - let mut bitmap1: RoaringBitmap = FromIterator::from_iter((0..2000).chain(1000000..1002000).chain(3000000..3001000)); - let bitmap2: RoaringBitmap = FromIterator::from_iter((1000..3000).chain(1001000..1003000).chain(2000000..2000001)); - let bitmap3: RoaringBitmap = FromIterator::from_iter((0..1000).chain(1000000..1001000).chain(2000..3000).chain(1002000..1003000).chain(2000000..2000001).chain(3000000..3001000)); + let mut bitmap1: RoaringBitmap = (0..2000).chain(1000000..1002000).chain(3000000..3001000).collect(); + let bitmap2: RoaringBitmap = (1000..3000).chain(1001000..1003000).chain(2000000..2000001).collect(); + let bitmap3: RoaringBitmap = (0..1000).chain(1000000..1001000).chain(2000..3000).chain(1002000..1003000).chain(2000000..2000001).chain(3000000..3001000).collect(); bitmap1.symmetric_difference_with(&bitmap2); @@ -81,9 +83,9 @@ fn arrays() { #[test] fn bitmaps() { - let mut bitmap1: RoaringBitmap = FromIterator::from_iter((0..6000).chain(1000000..1012000).chain(3000000..3010000)); - let bitmap2: RoaringBitmap = FromIterator::from_iter((3000..7000).chain(1006000..1018000).chain(2000000..2010000)); - let bitmap3: RoaringBitmap = FromIterator::from_iter((0..3000).chain(1000000..1006000).chain(6000..7000).chain(1012000..1018000).chain(2000000..2010000).chain(3000000..3010000)); + let mut bitmap1: RoaringBitmap = (0..6000).chain(1000000..1012000).chain(3000000..3010000).collect(); + let bitmap2: RoaringBitmap = (3000..7000).chain(1006000..1018000).chain(2000000..2010000).collect(); + let bitmap3: RoaringBitmap = (0..3000).chain(1000000..1006000).chain(6000..7000).chain(1012000..1018000).chain(2000000..2010000).chain(3000000..3010000).collect(); bitmap1.symmetric_difference_with(&bitmap2); diff --git a/tests/union_with.rs b/tests/union_with.rs index 3ea4ce59..66198818 100644 --- a/tests/union_with.rs +++ b/tests/union_with.rs @@ -1,11 +1,13 @@ +#![feature(slicing_syntax)] + extern crate roaring; use roaring::RoaringBitmap; #[test] fn array_to_array() { - let mut bitmap1: RoaringBitmap = FromIterator::from_iter(0..2000); - let bitmap2: RoaringBitmap = FromIterator::from_iter(1000..3000); - let bitmap3: RoaringBitmap = FromIterator::from_iter(0..3000); + let mut bitmap1: RoaringBitmap = (0..2000).collect(); + let bitmap2: RoaringBitmap = (1000..3000).collect(); + let bitmap3: RoaringBitmap = (0..3000).collect(); bitmap1.union_with(&bitmap2); @@ -14,9 +16,9 @@ fn array_to_array() { #[test] fn array_to_bitmap() { - let mut bitmap1: RoaringBitmap = FromIterator::from_iter(0..4000); - let bitmap2: RoaringBitmap = FromIterator::from_iter(4000..8000); - let bitmap3: RoaringBitmap = FromIterator::from_iter(0..8000); + let mut bitmap1: RoaringBitmap = (0..4000).collect(); + let bitmap2: RoaringBitmap = (4000..8000).collect(); + let bitmap3: RoaringBitmap = (0..8000).collect(); bitmap1.union_with(&bitmap2); @@ -25,9 +27,9 @@ fn array_to_bitmap() { #[test] fn array_and_bitmap() { - let mut bitmap1: RoaringBitmap = FromIterator::from_iter(0..2000); - let bitmap2: RoaringBitmap = FromIterator::from_iter(1000..8000); - let bitmap3: RoaringBitmap = FromIterator::from_iter(0..8000); + let mut bitmap1: RoaringBitmap = (0..2000).collect(); + let bitmap2: RoaringBitmap = (1000..8000).collect(); + let bitmap3: RoaringBitmap = (0..8000).collect(); bitmap1.union_with(&bitmap2); @@ -36,9 +38,9 @@ fn array_and_bitmap() { #[test] fn bitmap() { - let mut bitmap1: RoaringBitmap = FromIterator::from_iter(0..12000); - let bitmap2: RoaringBitmap = FromIterator::from_iter(6000..18000); - let bitmap3: RoaringBitmap = FromIterator::from_iter(0..18000); + let mut bitmap1: RoaringBitmap = (0..12000).collect(); + let bitmap2: RoaringBitmap = (6000..18000).collect(); + let bitmap3: RoaringBitmap = (0..18000).collect(); bitmap1.union_with(&bitmap2); @@ -47,9 +49,9 @@ fn bitmap() { #[test] fn bitmap_and_array() { - let mut bitmap1: RoaringBitmap = FromIterator::from_iter(0..12000); - let bitmap2: RoaringBitmap = FromIterator::from_iter(10000..13000); - let bitmap3: RoaringBitmap = FromIterator::from_iter(0..13000); + let mut bitmap1: RoaringBitmap = (0..12000).collect(); + let bitmap2: RoaringBitmap = (10000..13000).collect(); + let bitmap3: RoaringBitmap = (0..13000).collect(); bitmap1.union_with(&bitmap2); @@ -58,9 +60,9 @@ fn bitmap_and_array() { #[test] fn arrays() { - let mut bitmap1: RoaringBitmap = FromIterator::from_iter((0..2000).chain(1000000..1002000).chain(3000000..3001000)); - let bitmap2: RoaringBitmap = FromIterator::from_iter((1000..3000).chain(1001000..1003000).chain(2000000..2001000)); - let bitmap3: RoaringBitmap = FromIterator::from_iter((0..3000).chain(1000000..1003000).chain(2000000..2001000).chain(3000000..3001000)); + let mut bitmap1: RoaringBitmap = (0..2000).chain(1000000..1002000).chain(3000000..3001000).collect(); + let bitmap2: RoaringBitmap = (1000..3000).chain(1001000..1003000).chain(2000000..2001000).collect(); + let bitmap3: RoaringBitmap = (0..3000).chain(1000000..1003000).chain(2000000..2001000).chain(3000000..3001000).collect(); bitmap1.union_with(&bitmap2); @@ -69,9 +71,9 @@ fn arrays() { #[test] fn bitmaps() { - let mut bitmap1: RoaringBitmap = FromIterator::from_iter((0..6000).chain(1000000..1012000).chain(3000000..3010000)); - let bitmap2: RoaringBitmap = FromIterator::from_iter((3000..9000).chain(1006000..1018000).chain(2000000..2010000)); - let bitmap3: RoaringBitmap = FromIterator::from_iter((0..9000).chain(1000000..1018000).chain(2000000..2010000).chain(3000000..3010000)); + let mut bitmap1: RoaringBitmap = (0..6000).chain(1000000..1012000).chain(3000000..3010000).collect(); + let bitmap2: RoaringBitmap = (3000..9000).chain(1006000..1018000).chain(2000000..2010000).collect(); + let bitmap3: RoaringBitmap = (0..9000).chain(1000000..1018000).chain(2000000..2010000).chain(3000000..3010000).collect(); bitmap1.union_with(&bitmap2);