Skip to content

Commit

Permalink
Make the insert_many method accept an Iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerollmops committed Jan 7, 2025
1 parent 7f0d5f0 commit 0e5728f
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions roaring/src/bitmap/inherent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,26 @@ impl RoaringBitmap {
///
/// The provided integers values don't have to be in sorted order, but it may be preferable
/// to sort them from a performance point of view.
///
/// # Examples
///
/// ```rust
/// use roaring::RoaringBitmap;
///
/// let mut rb = RoaringBitmap::new();
/// rb.insert_many([1, 2, 3, 4, 1500, 1508, 1507, 1509]);
/// assert!(rb.contains(2));
/// assert!(rb.contains(1508));
/// assert!(!rb.contains(5));
/// ```
#[inline]
pub fn insert_many(&mut self, values: &[u32]) -> u64 {
let (&value, values) = match values.split_first() {
Some(split) => split,
pub fn insert_many<I>(&mut self, values: I) -> u64
where
I: IntoIterator<Item = u32>,
{
let mut values = values.into_iter();
let value = match values.next() {
Some(value) => value,
None => return 0,
};

Expand All @@ -93,7 +109,7 @@ impl RoaringBitmap {
let mut current_cont = &mut self.containers[current_container_index];
inserted += current_cont.insert(lowbit) as u64;

for val in values.iter().copied() {
for val in values {
let (newhb, lowbit) = util::split(val);
if currenthb == newhb {
// easy case, this could be quite frequent
Expand Down

0 comments on commit 0e5728f

Please sign in to comment.