Skip to content

Commit

Permalink
use u16 keys for bitmap store iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr-Emann committed Oct 2, 2024
1 parent 08560aa commit 20a43fa
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions roaring/src/bitmap/store/bitmap_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,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 @@ -415,7 +415,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 @@ -432,7 +432,7 @@ impl<B: Borrow<[u64; BITMAP_LENGTH]>> Iterator for BitmapIter<B> {
return None;
}
for key in self.key + 1..self.key_back {
self.value = unsafe { *self.bits.borrow().get_unchecked(key) };
self.value = unsafe { *self.bits.borrow().get_unchecked(key as usize) };
if self.value != 0 {
self.key = key;
break 'get_val;
Expand All @@ -445,7 +445,7 @@ impl<B: Borrow<[u64; BITMAP_LENGTH]>> Iterator for BitmapIter<B> {
}
}
}
let index = self.value.trailing_zeros() as usize;
let index = self.value.trailing_zeros() as u16;
self.value &= self.value - 1;
Some((64 * self.key + index) as u16)

Check failure on line 450 in roaring/src/bitmap/store/bitmap_store.rs

View workflow job for this annotation

GitHub Actions / ci (beta)

casting to the same type is unnecessary (`u16` -> `u16`)

Check failure on line 450 in roaring/src/bitmap/store/bitmap_store.rs

View workflow job for this annotation

GitHub Actions / ci (nightly)

casting to the same type is unnecessary (`u16` -> `u16`)
}
Expand All @@ -461,13 +461,13 @@ 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

0 comments on commit 20a43fa

Please sign in to comment.