Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
179: Remove size hint and exact size from bitmap inner iterators r=Kerollmops a=saik0

Closes RoaringBitmap#176 

Co-authored-by: saik0 <[email protected]>
  • Loading branch information
bors[bot] and saik0 authored Feb 7, 2022
2 parents f52fe0e + 79e0d0c commit 55b350f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 46 deletions.
9 changes: 0 additions & 9 deletions src/bitmap/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,6 @@ impl<'a> Iterator for Iter<'a> {
fn next(&mut self) -> Option<u32> {
self.inner.next().map(|i| util::join(self.key, i))
}
fn size_hint(&self) -> (usize, Option<usize>) {
self.inner.size_hint()
}
}

impl ExactSizeIterator for Iter<'_> {
fn len(&self) -> usize {
self.inner.len()
}
}

impl fmt::Debug for Container {
Expand Down
21 changes: 4 additions & 17 deletions src/bitmap/store/bitmap_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,11 @@ impl BitmapStore {
}

pub fn iter(&self) -> BitmapIter<&[u64; BITMAP_LENGTH]> {
BitmapIter::new(self.len, &self.bits)
BitmapIter::new(&self.bits)
}

pub fn into_iter(self) -> BitmapIter<Box<[u64; BITMAP_LENGTH]>> {
BitmapIter::new(self.len, self.bits)
BitmapIter::new(self.bits)
}

pub fn as_array(&self) -> &[u64; BITMAP_LENGTH] {
Expand Down Expand Up @@ -293,13 +293,12 @@ impl std::error::Error for Error {}
pub struct BitmapIter<B: Borrow<[u64; BITMAP_LENGTH]>> {
key: usize,
value: u64,
len: u64,
bits: B,
}

impl<B: Borrow<[u64; BITMAP_LENGTH]>> BitmapIter<B> {
fn new(len: u64, bits: B) -> BitmapIter<B> {
BitmapIter { key: 0, value: bits.borrow()[0], len, bits }
fn new(bits: B) -> BitmapIter<B> {
BitmapIter { key: 0, value: bits.borrow()[0], bits }
}
}

Expand All @@ -311,28 +310,16 @@ impl<B: Borrow<[u64; BITMAP_LENGTH]>> Iterator for BitmapIter<B> {
if self.value == 0 {
self.key += 1;
if self.key >= BITMAP_LENGTH {
debug_assert!(self.len == 0);
return None;
}
self.value = unsafe { *self.bits.borrow().get_unchecked(self.key) };
continue;
}
let index = self.value.trailing_zeros() as usize;
self.value &= self.value - 1;
self.len -= 1;
return Some((64 * self.key + index) as u16);
}
}

fn size_hint(&self) -> (usize, Option<usize>) {
(self.len as usize, Some(self.len as usize))
}
}

impl<B: Borrow<[u64; BITMAP_LENGTH]>> ExactSizeIterator for BitmapIter<B> {
fn len(&self) -> usize {
self.len as usize
}
}

#[inline]
Expand Down
20 changes: 0 additions & 20 deletions src/bitmap/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,24 +442,4 @@ impl<'a> Iterator for Iter<'a> {
Iter::BitmapOwned(inner) => inner.next(),
}
}

fn size_hint(&self) -> (usize, Option<usize>) {
match self {
Iter::Array(inner) => inner.size_hint(),
Iter::Vec(inner) => inner.size_hint(),
Iter::BitmapBorrowed(inner) => inner.size_hint(),
Iter::BitmapOwned(inner) => inner.size_hint(),
}
}
}

impl ExactSizeIterator for Iter<'_> {
fn len(&self) -> usize {
match self {
Iter::Array(inner) => inner.len(),
Iter::Vec(inner) => inner.len(),
Iter::BitmapBorrowed(inner) => inner.len(),
Iter::BitmapOwned(inner) => inner.len(),
}
}
}

0 comments on commit 55b350f

Please sign in to comment.