pub struct Bitmap(/* private fields */);
Expand description
A compressed bitmap using the Roaring bitmap compression scheme.
§BCS
The BCS serialized form for this type is defined by the following ABNF:
roaring-bitmap = bytes ; where the contents of the bytes are valid
; according to the serialized spec for
; roaring bitmaps
Implementations§
Source§impl Bitmap
impl Bitmap
Sourcepub fn len(&self) -> u64
pub fn len(&self) -> u64
Returns the number of distinct integers added to the set.
§Examples
use sui_sdk_types::Bitmap;
let mut bitmap = Bitmap::new();
assert_eq!(bitmap.len(), 0);
bitmap.insert(3);
assert_eq!(bitmap.len(), 1);
bitmap.insert(3);
bitmap.insert(4);
assert_eq!(bitmap.len(), 2);
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears all integers in this set.
§Examples
use sui_sdk_types::Bitmap;
let mut bitmap = Bitmap::new();
bitmap.insert(1);
assert_eq!(bitmap.contains(1), true);
bitmap.clear();
assert_eq!(bitmap.contains(1), false);
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if there are no integers in this set.
§Examples
use sui_sdk_types::Bitmap;
let mut bitmap = Bitmap::new();
assert_eq!(bitmap.is_empty(), true);
bitmap.insert(3);
assert_eq!(bitmap.is_empty(), false);
Sourcepub fn insert(&mut self, value: u32) -> bool
pub fn insert(&mut self, value: u32) -> bool
Adds a value to the set.
Returns whether the value was absent from the set.
§Examples
use sui_sdk_types::Bitmap;
let mut bitmap = Bitmap::new();
assert_eq!(bitmap.insert(3), true);
assert_eq!(bitmap.insert(3), false);
assert_eq!(bitmap.contains(3), true);
Sourcepub fn insert_range<R>(&mut self, range: R) -> u64where
R: RangeBounds<u32>,
pub fn insert_range<R>(&mut self, range: R) -> u64where
R: RangeBounds<u32>,
Inserts a range of values. Returns the number of inserted values.
§Examples
use sui_sdk_types::Bitmap;
let mut bitmap = Bitmap::new();
bitmap.insert_range(2..4);
assert!(bitmap.contains(2));
assert!(bitmap.contains(3));
assert!(!bitmap.contains(4));
Sourcepub fn remove(&mut self, value: u32) -> bool
pub fn remove(&mut self, value: u32) -> bool
Removes a value from the set. Returns true
if the value was present in the set.
§Examples
use sui_sdk_types::Bitmap;
let mut bitmap = Bitmap::new();
bitmap.insert(3);
assert_eq!(bitmap.remove(3), true);
assert_eq!(bitmap.remove(3), false);
assert_eq!(bitmap.contains(3), false);
Sourcepub fn contains(&self, value: u32) -> bool
pub fn contains(&self, value: u32) -> bool
Returns true
if this set contains the specified integer.
§Examples
use sui_sdk_types::Bitmap;
let mut bitmap = Bitmap::new();
bitmap.insert(1);
assert_eq!(bitmap.contains(0), false);
assert_eq!(bitmap.contains(1), true);
assert_eq!(bitmap.contains(100), false);
Sourcepub fn iter(&self) -> impl Iterator<Item = u32> + use<'_>
pub fn iter(&self) -> impl Iterator<Item = u32> + use<'_>
Iterator over each value stored in the Bitmap, guarantees values are ordered by value.
§Examples
use core::iter::FromIterator;
use sui_sdk_types::Bitmap;
let bitmap = (1..3).collect::<Bitmap>();
let mut iter = bitmap.iter();
assert_eq!(iter.next(), Some(1));
assert_eq!(iter.next(), Some(2));
assert_eq!(iter.next(), None);
Sourcepub fn deserialize_from<R: Read>(reader: R) -> Result<Self>
Available on crate feature serde
only.
pub fn deserialize_from<R: Read>(reader: R) -> Result<Self>
serde
only.Deserialize a bitmap into memory from the standard Roaring on-disk format. This is compatible with the official C/C++, Java and Go implementations. This method checks that all of the internal values are valid.
§Examples
use sui_sdk_types::Bitmap;
let bitmap1: Bitmap = (1..4).collect();
let mut bytes = vec![];
bitmap1.serialize_into(&mut bytes).unwrap();
let bitmap2 = Bitmap::deserialize_from(&bytes[..]).unwrap();
assert_eq!(bitmap1, bitmap2);
Sourcepub fn serialize_into<W: Write>(&self, writer: W) -> Result<()>
Available on crate feature serde
only.
pub fn serialize_into<W: Write>(&self, writer: W) -> Result<()>
serde
only.Serialize this bitmap into the standard Roaring on-disk format. This is compatible with the official C/C++, Java and Go implementations.
§Examples
use sui_sdk_types::Bitmap;
let bitmap1: Bitmap = (1..4).collect();
let mut bytes = vec![];
bitmap1.serialize_into(&mut bytes).unwrap();
let bitmap2 = Bitmap::deserialize_from(&bytes[..]).unwrap();
assert_eq!(bitmap1, bitmap2);
Trait Implementations§
Source§impl Arbitrary for Bitmap
Available on crate feature proptest
only.
impl Arbitrary for Bitmap
proptest
only.Source§type Parameters = ()
type Parameters = ()
arbitrary_with
accepts for configuration
of the generated Strategy
. Parameters must implement Default
.Source§type Strategy = BoxedStrategy<Bitmap>
type Strategy = BoxedStrategy<Bitmap>
Strategy
used to generate values of type Self
.Source§fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
Source§impl<'de> Deserialize<'de> for Bitmap
Available on crate feature serde
only.
impl<'de> Deserialize<'de> for Bitmap
serde
only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<'a> Extend<&'a u32> for Bitmap
impl<'a> Extend<&'a u32> for Bitmap
Source§fn extend<I: IntoIterator<Item = &'a u32>>(&mut self, values: I)
fn extend<I: IntoIterator<Item = &'a u32>>(&mut self, values: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl Extend<u32> for Bitmap
impl Extend<u32> for Bitmap
Source§fn extend<I: IntoIterator<Item = u32>>(&mut self, values: I)
fn extend<I: IntoIterator<Item = u32>>(&mut self, values: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl<'a> FromIterator<&'a u32> for Bitmap
impl<'a> FromIterator<&'a u32> for Bitmap
Source§impl FromIterator<u32> for Bitmap
impl FromIterator<u32> for Bitmap
impl StructuralPartialEq for Bitmap
Auto Trait Implementations§
impl Freeze for Bitmap
impl RefUnwindSafe for Bitmap
impl Send for Bitmap
impl Sync for Bitmap
impl Unpin for Bitmap
impl UnwindSafe for Bitmap
Blanket Implementations§
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
fn as_<T>(self) -> Twhere
T: CastFrom<U>,
self
to type T
. The semantics of numeric casting with the as
operator are followed, so <T as As>::as_::<U>
can be used in the same way as T as U
for numeric conversions. Read moreSource§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more