diff --git a/croaring/src/bitmap/iter.rs b/croaring/src/bitmap/iter.rs index 9b2ae11..b65f19e 100644 --- a/croaring/src/bitmap/iter.rs +++ b/croaring/src/bitmap/iter.rs @@ -4,6 +4,12 @@ use std::mem::MaybeUninit; use super::Bitmap; +/// A cusrsr over the values of a bitmap +/// +/// A Cursor is like an iterator, except that it can freely seek back-and-forth. +/// +/// A cursor points at a single value in the bitmap, or at a "ghost" position, +/// either one before the beginning of the bitmap, or one after the end of the bitmap. #[derive(Clone)] pub struct BitmapCursor<'a> { raw: ffi::roaring_uint32_iterator_t, diff --git a/croaring/src/bitmap/mod.rs b/croaring/src/bitmap/mod.rs index 658fcea..c9239a3 100644 --- a/croaring/src/bitmap/mod.rs +++ b/croaring/src/bitmap/mod.rs @@ -89,6 +89,6 @@ mod ops; mod serialization; mod view; -pub use self::iter::BitmapIterator; +pub use self::iter::{BitmapCursor, BitmapIterator}; pub use self::lazy::LazyBitmap; pub use self::serialization::{Deserializer, Serializer, ViewDeserializer}; diff --git a/croaring/src/bitmap/serialization.rs b/croaring/src/bitmap/serialization.rs index 7e19d6f..96e0006 100644 --- a/croaring/src/bitmap/serialization.rs +++ b/croaring/src/bitmap/serialization.rs @@ -42,9 +42,9 @@ pub trait Deserializer { /// /// # Safety /// - /// Unlike its safe counterpart, [`try_deserialize`], this function assumes the data is valid, - /// passing data which does not contain/start with a bitmap serialized with this format will - /// result in undefined behavior. + /// Unlike its safe counterpart ([`Self::try_deserialize`]) this function assumes the data is + /// valid, passing data which does not contain/start with a bitmap serialized with this format + /// will result in undefined behavior. unsafe fn try_deserialize_unchecked(buffer: &[u8]) -> Bitmap; } diff --git a/croaring/src/bitmap64/imp.rs b/croaring/src/bitmap64/imp.rs index 3261948..832dd24 100644 --- a/croaring/src/bitmap64/imp.rs +++ b/croaring/src/bitmap64/imp.rs @@ -329,6 +329,23 @@ impl Bitmap64 { unsafe { ffi::roaring64_bitmap_remove_range_closed(self.raw.as_ptr(), start, end) } } + /// Empty the bitmap + /// + /// # Examples + /// + /// ``` + /// use croaring::Bitmap64; + /// + /// let mut bitmap = Bitmap64::from([1, 2, 3]); + /// assert!(!bitmap.is_empty()); + /// bitmap.clear(); + /// assert!(bitmap.is_empty()); + /// ``` + #[inline] + pub fn clear(&mut self) { + self.remove_range(..); + } + /// Returns the number of values in the bitmap /// /// # Examples diff --git a/croaring/src/bitmap64/serialization.rs b/croaring/src/bitmap64/serialization.rs index 8d34137..f03188c 100644 --- a/croaring/src/bitmap64/serialization.rs +++ b/croaring/src/bitmap64/serialization.rs @@ -6,9 +6,9 @@ use std::num::NonZeroUsize; pub trait Serializer { /// Serialize a bitmap into bytes, using the provided vec buffer to store the serialized data /// - /// Note that some serializers ([Frozen]) may require that the bitmap is aligned specially, - /// this method will ensure that the returned slice of bytes is aligned correctly, by adding - /// additional padding before the serialized data if required. + /// Note that some serializers ([Frozen][crate::Frozen]) may require that the + /// bitmap is aligned specially, this method will ensure that the returned slice of bytes is + /// aligned correctly, by adding additional padding before the serialized data if required. /// /// The contents of the provided vec buffer will not be overwritten: only new data will be /// appended to the end of the buffer. If the buffer has enough capacity, and the current @@ -41,7 +41,7 @@ pub trait Deserializer { /// /// # Safety /// - /// Unlike its safe counterpart, [`try_deserialize`], this function assumes the data is valid, + /// Unlike its safe counterpart, [`Self::try_deserialize`], this function assumes the data is valid, /// passing data which does not contain/start with a bitmap serialized with this format will /// result in undefined behavior. unsafe fn try_deserialize_unchecked(buffer: &[u8]) -> Bitmap64;