Skip to content

Commit

Permalink
Fix issues with latest compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemo157 committed Jan 5, 2015
1 parent 14f53fb commit f848c05
Show file tree
Hide file tree
Showing 16 changed files with 519 additions and 311 deletions.
12 changes: 7 additions & 5 deletions src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -56,10 +56,10 @@ impl Container {
}

#[inline]
pub fn iter<'a>(&'a self) -> Box<Iterator<u16> + 'a> {
pub fn iter<'a>(&'a self) -> Box<Iterator<Item = u16> + 'a> {
match self.store {
Array(ref vec) => box vec.iter().map(|x| *x) as Box<Iterator<u16> + 'a>,
Bitmap(ref bits) => box BitmapIter::new(bits) as Box<Iterator<u16> + 'a>,
Array(ref vec) => box vec.iter().map(|x| *x) as Box<Iterator<Item = u16> + 'a>,
Bitmap(ref bits) => box BitmapIter::new(bits) as Box<Iterator<Item = u16> + 'a>,
}
}

Expand Down Expand Up @@ -144,7 +144,9 @@ impl<'a> BitmapIter<'a> {
}
}

impl<'a> Iterator<u16> for BitmapIter<'a> {
impl<'a> Iterator for BitmapIter<'a> {
type Item = u16;

fn next(&mut self) -> Option<u16> {
loop {
if self.key == 2047 && self.bit == (u32::BITS - 1) {
Expand Down
51 changes: 26 additions & 25 deletions src/imp.rs
Original file line number Diff line number Diff line change
@@ -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 };
Expand All @@ -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]
},
Expand All @@ -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);
Expand All @@ -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,
}
}

Expand Down Expand Up @@ -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),
};
}
}
Expand All @@ -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;
},
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -176,28 +175,28 @@ pub fn symmetric_difference_with(this: &mut RB, other: &RB) {
}

#[inline]
pub fn from_iter<I: Iterator<u32>>(iterator: I) -> RB {
pub fn from_iter<I: Iterator<Item = u32>>(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<Item = &'a u32>>(iterator: I) -> RB {
let mut rb = new();
rb.extend(iterator);
rb
}

#[inline]
pub fn extend<I: Iterator<u32>>(this: &mut RB, mut iterator: I) {
pub fn extend<I: Iterator<Item = u32>>(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<Item = &'a u32>>(this: &mut RB, mut iterator: I) {
for value in iterator {
this.insert(*value);
}
Expand Down Expand Up @@ -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,
Expand Down
26 changes: 18 additions & 8 deletions src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use container::{ Container };

/// An iterator for `RoaringBitmap`.
pub struct Iter<'a> {
inner_iter: Option<(u16, Box<Iterator<u16> + 'a>)>,
inner_iter: Option<(u16, Box<Iterator<Item = u16> + 'a>)>,
container_iter: slice::Iter<'a, Container>,
}

Expand All @@ -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<Iterator<u16> + 'a>)> {
fn next_iter<'a>(container_iter: &mut slice::Iter<'a, Container>) -> Option<(u16, Box<Iterator<Item = u16> + 'a>)> {
container_iter.next().map(|container| (container.key(), container.iter()))
}

Expand All @@ -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<Either<u32, Option<(u16, Box<Iterator<u16> + 'a>)>>> {
fn choose_next(&mut self) -> Option<Either<u32, Option<(u16, Box<Iterator<Item = u16> + 'a>)>>> {
match self.inner_iter {
Some((key, ref mut iter)) => Some(match iter.next() {
Some(value) => Left(calc(key, value)),
Expand All @@ -42,7 +42,9 @@ impl<'a> Iter<'a> {
}
}

impl<'a> Iterator<u32> for Iter<'a> {
impl<'a> Iterator for Iter<'a> {
type Item = u32;

fn next(&mut self) -> Option<u32> {
match self.choose_next() {
None => None,
Expand Down Expand Up @@ -77,7 +79,9 @@ pub mod union {
}
}

impl<'a> Iterator<u32> for UnionIter<'a> {
impl<'a> Iterator for UnionIter<'a> {
type Item = u32;

fn next(&mut self) -> Option<u32> {
match (self.current1, self.current2) {
(None, None) => None,
Expand Down Expand Up @@ -117,7 +121,9 @@ pub mod intersection {
}
}

impl<'a> Iterator<u32> for IntersectionIter<'a> {
impl<'a> Iterator for IntersectionIter<'a> {
type Item = u32;

fn next(&mut self) -> Option<u32> {
match (self.current1, self.current2) {
(None, _) | (_, None) => None,
Expand Down Expand Up @@ -155,7 +161,9 @@ pub mod difference {
}
}

impl<'a> Iterator<u32> for DifferenceIter<'a> {
impl<'a> Iterator for DifferenceIter<'a> {
type Item = u32;

fn next(&mut self) -> Option<u32> {
loop {
match (self.current1, self.current2) {
Expand Down Expand Up @@ -194,7 +202,9 @@ pub mod symmetric_difference {
}
}

impl<'a> Iterator<u32> for SymmetricDifferenceIter<'a> {
impl<'a> Iterator for SymmetricDifferenceIter<'a> {
type Item = u32;

fn next(&mut self) -> Option<u32> {
match (self.current1, self.current2) {
(None, _) | (_, None) => None,
Expand Down
Loading

0 comments on commit f848c05

Please sign in to comment.