From 2a405614800be09ce6ebb20b091f28ef3d25973c Mon Sep 17 00:00:00 2001 From: Zachary Dremann Date: Thu, 21 Mar 2024 23:27:12 -0400 Subject: [PATCH] Add Bitmap::remove_many --- croaring/src/bitmap/imp.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/croaring/src/bitmap/imp.rs b/croaring/src/bitmap/imp.rs index 8e0d771..4e02f7b 100644 --- a/croaring/src/bitmap/imp.rs +++ b/croaring/src/bitmap/imp.rs @@ -279,6 +279,29 @@ impl Bitmap { unsafe { ffi::roaring_bitmap_remove_checked(&mut self.bitmap, element) } } + /// Remove many values from the bitmap + /// + /// This should be faster than calling `remove` multiple times. + /// + /// In order to exploit this optimization, the caller should attempt to keep values with the same high 48 bits of + /// the value as consecutive elements in `vals` + /// + /// # Examples + /// + /// ``` + /// use croaring::Bitmap; + /// let mut bitmap = Bitmap::of(&[1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// bitmap.remove_many(&[1, 2, 3, 4, 5, 6, 7, 8]); + /// assert_eq!(bitmap.to_vec(), vec![9]); + /// ``` + #[inline] + #[doc(alias = "roaring_bitmap_remove_many")] + pub fn remove_many(&mut self, elements: &[u32]) { + unsafe { + ffi::roaring_bitmap_remove_many(&mut self.bitmap, elements.len(), elements.as_ptr()) + } + } + /// Contains returns true if the integer element is contained in the bitmap /// /// # Examples