Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Clone on the bitmap::Iter type #289

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions roaring/src/bitmap/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct Container {
pub store: Store,
}

#[derive(Clone)]
pub struct Iter<'a> {
pub key: u16,
inner: store::Iter<'a>,
Expand All @@ -41,6 +42,7 @@ impl Container {
self.store.is_empty()
}

#[inline]
pub fn insert(&mut self, index: u16) -> bool {
if self.store.insert(index) {
self.ensure_correct_store();
Expand Down
1 change: 1 addition & 0 deletions roaring/src/bitmap/inherent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ impl RoaringBitmap {
/// assert_eq!(rb.insert(3), false);
/// assert_eq!(rb.contains(3), true);
/// ```
#[inline]
pub fn insert(&mut self, value: u32) -> bool {
let (key, index) = util::split(value);
let container = match self.containers.binary_search_by_key(&key, |c| c.key) {
Expand Down
2 changes: 2 additions & 0 deletions roaring/src/bitmap/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ use crate::{NonSortedIntegers, RoaringBitmap};
use alloc::vec::Vec;

/// An iterator for `RoaringBitmap`.
#[derive(Clone)]
pub struct Iter<'a> {
inner: iter::Flatten<slice::Iter<'a, Container>>,
size_hint: u64,
}

/// An iterator for `RoaringBitmap`.
#[derive(Clone)]
pub struct IntoIter {
inner: iter::Flatten<vec::IntoIter<Container>>,
size_hint: u64,
Expand Down
1 change: 1 addition & 0 deletions roaring/src/bitmap/store/array_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ impl ArrayStore {
}
}

#[inline]
pub fn insert(&mut self, index: u16) -> bool {
self.vec.binary_search(&index).map_err(|loc| self.vec.insert(loc, index)).is_err()
}
Expand Down
2 changes: 2 additions & 0 deletions roaring/src/bitmap/store/bitmap_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ impl BitmapStore {
}
}

#[inline]
pub fn insert(&mut self, index: u16) -> bool {
let (key, bit) = (key(index), bit(index));
let old_w = self.bits[key];
Expand Down Expand Up @@ -403,6 +404,7 @@ impl Display for Error {
#[cfg(feature = "std")]
impl std::error::Error for Error {}

#[derive(Clone)]
pub struct BitmapIter<B: Borrow<[u64; BITMAP_LENGTH]>> {
key: usize,
value: u64,
Expand Down
2 changes: 2 additions & 0 deletions roaring/src/bitmap/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub enum Store {
Bitmap(BitmapStore),
}

#[derive(Clone)]
pub enum Iter<'a> {
Array(slice::Iter<'a, u16>),
Vec(vec::IntoIter<u16>),
Expand All @@ -49,6 +50,7 @@ impl Store {
Store::Bitmap(BitmapStore::full())
}

#[inline]
pub fn insert(&mut self, index: u16) -> bool {
match self {
Array(vec) => vec.insert(index),
Expand Down
Loading