Skip to content

Commit

Permalink
Merge branch 'RoaringBitmap:main' into from-bitmap-bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
lemolatoon authored Oct 19, 2024
2 parents a1f6848 + c4e3b34 commit 2706bd9
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 34 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion roaring/src/bitmap/arbitrary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ mod test {

impl RoaringBitmap {
prop_compose! {
pub fn arbitrary()(bitmap in (0usize..=16).prop_flat_map(containers)) -> RoaringBitmap {
pub(crate) fn arbitrary()(bitmap in (0usize..=16).prop_flat_map(containers)) -> RoaringBitmap {
bitmap
}
}
Expand Down
2 changes: 1 addition & 1 deletion roaring/src/bitmap/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ impl IntoIterator for Container {
}
}

impl<'a> Iterator for Iter<'a> {
impl Iterator for Iter<'_> {
type Item = u32;
fn next(&mut self) -> Option<u32> {
self.inner.next().map(|i| util::join(self.key, i))
Expand Down
2 changes: 1 addition & 1 deletion roaring/src/bitmap/store/array_store/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl VecWriter {

pub fn into_inner(self) -> Vec<u16> {
// Consider shrinking the vec here.
// Exacty len could be too aggressive. Len rounded up to next power of 2?
// Exactly len could be too aggressive. Len rounded up to next power of 2?
// Related, but not exact issue: https://github.com/RoaringBitmap/roaring-rs/issues/136
self.vec
}
Expand Down
48 changes: 26 additions & 22 deletions roaring/src/bitmap/store/bitmap_store.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use core::borrow::Borrow;
use core::cmp::Ordering;
use core::fmt::{Display, Formatter};
use core::mem::size_of;
use core::ops::{BitAndAssign, BitOrAssign, BitXorAssign, RangeInclusive, SubAssign};
Expand Down Expand Up @@ -446,9 +445,9 @@ impl Display for Error {
impl std::error::Error for Error {}

pub struct BitmapIter<B: Borrow<[u64; BITMAP_LENGTH]>> {
key: usize,
key: u16,
value: u64,
key_back: usize,
key_back: u16,
value_back: u64,
bits: B,
}
Expand All @@ -458,7 +457,7 @@ impl<B: Borrow<[u64; BITMAP_LENGTH]>> BitmapIter<B> {
BitmapIter {
key: 0,
value: bits.borrow()[0],
key_back: BITMAP_LENGTH - 1,
key_back: BITMAP_LENGTH as u16 - 1,
value_back: bits.borrow()[BITMAP_LENGTH - 1],
bits,
}
Expand All @@ -469,24 +468,28 @@ impl<B: Borrow<[u64; BITMAP_LENGTH]>> Iterator for BitmapIter<B> {
type Item = u16;

fn next(&mut self) -> Option<u16> {
loop {
if self.value == 0 {
self.key += 1;
let cmp = self.key.cmp(&self.key_back);
// Match arms can be reordered, this ordering is perf sensitive
self.value = if cmp == Ordering::Less {
unsafe { *self.bits.borrow().get_unchecked(self.key) }
} else if cmp == Ordering::Equal {
self.value_back
} else {
if self.value == 0 {
'get_val: {
if self.key >= self.key_back {
return None;
};
continue;
}
for key in self.key + 1..self.key_back {
self.value = unsafe { *self.bits.borrow().get_unchecked(key as usize) };
if self.value != 0 {
self.key = key;
break 'get_val;
}
}
self.key = self.key_back;
self.value = self.value_back;
if self.value == 0 {
return None;
}
}
let index = self.value.trailing_zeros() as usize;
self.value &= self.value - 1;
return Some((64 * self.key + index) as u16);
}
let index = self.value.trailing_zeros() as u16;
self.value &= self.value - 1;
Some(64 * self.key + index)
}
}

Expand All @@ -500,13 +503,14 @@ impl<B: Borrow<[u64; BITMAP_LENGTH]>> DoubleEndedIterator for BitmapIter<B> {
return None;
}
self.key_back -= 1;
self.value_back = unsafe { *self.bits.borrow().get_unchecked(self.key_back) };
self.value_back =
unsafe { *self.bits.borrow().get_unchecked(self.key_back as usize) };
continue;
}
let index_from_left = value.leading_zeros() as usize;
let index_from_left = value.leading_zeros() as u16;
let index = 63 - index_from_left;
*value &= !(1 << index);
return Some((64 * self.key_back + index) as u16);
return Some(64 * self.key_back + index);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion roaring/src/bitmap/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ impl PartialEq for Store {
}
}

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

fn next(&mut self) -> Option<u16> {
Expand Down
2 changes: 1 addition & 1 deletion roaring/src/treemap/arbitrary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod test {

impl RoaringTreemap {
prop_compose! {
pub fn arbitrary()(map in btree_map(0u32..=16, RoaringBitmap::arbitrary(), 0usize..=16)) -> RoaringTreemap {
pub(crate) fn arbitrary()(map in btree_map(0u32..=16, RoaringBitmap::arbitrary(), 0usize..=16)) -> RoaringTreemap {
// we’re NEVER supposed to start with a treemap containing empty bitmaps
// Since we can’t configure this in arbitrary we’re simply going to ignore the generated empty bitmaps
let map = map.into_iter().filter(|(_, v)| !v.is_empty()).collect();
Expand Down
6 changes: 3 additions & 3 deletions roaring/src/treemap/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct To64Iter<'a> {
inner: Iter32<'a>,
}

impl<'a> Iterator for To64Iter<'a> {
impl Iterator for To64Iter<'_> {
type Item = u64;
fn next(&mut self) -> Option<u64> {
self.inner.next().map(|n| util::join(self.hi, n))
Expand Down Expand Up @@ -109,7 +109,7 @@ pub struct IntoIter {
size_hint: u64,
}

impl<'a> Iter<'a> {
impl Iter<'_> {
fn new(map: &BTreeMap<u32, RoaringBitmap>) -> Iter {
let size_hint: u64 = map.iter().map(|(_, r)| r.len()).sum();
let i = map.iter().flat_map(to64iter as _);
Expand All @@ -125,7 +125,7 @@ impl IntoIter {
}
}

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

fn next(&mut self) -> Option<u64> {
Expand Down
8 changes: 4 additions & 4 deletions roaring/src/treemap/multiops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ where
(key, bitmap)
}
None => {
let poped = PeekMut::pop(peek);
(poped.key, poped.bitmap)
let popped = PeekMut::pop(peek);
(popped.key, popped.bitmap)
}
};

Expand Down Expand Up @@ -209,8 +209,8 @@ where
(key, bitmap)
}
None => {
let poped = PeekMut::pop(peek);
(poped.key, poped.bitmap)
let popped = PeekMut::pop(peek);
(popped.key, popped.bitmap)
}
};

Expand Down

0 comments on commit 2706bd9

Please sign in to comment.