Struct Bitmap

Source
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

Source

pub fn new() -> Self

Creates an empty Bitmap.

§Examples
use sui_sdk_types::Bitmap;
let bitmap = Bitmap::new();
Source

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);
Source

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);
Source

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);
Source

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);
Source

pub fn insert_range<R>(&mut self, range: R) -> u64
where 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));
Source

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);
Source

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);
Source

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);
Source

pub fn deserialize_from<R: Read>(reader: R) -> Result<Self>

Available on crate feature 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);
Source

pub fn serialize_into<W: Write>(&self, writer: W) -> Result<()>

Available on crate feature 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.
Source§

type Parameters = ()

The type of parameters that arbitrary_with accepts for configuration of the generated Strategy. Parameters must implement Default.
Source§

type Strategy = BoxedStrategy<Bitmap>

The type of Strategy used to generate values of type Self.
Source§

fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy

Generates a Strategy for producing arbitrary values of type the implementing type (Self). The strategy is passed the arguments given in args. Read more
§

fn arbitrary() -> Self::Strategy

Generates a Strategy for producing arbitrary values of type the implementing type (Self). Read more
Source§

impl Clone for Bitmap

Source§

fn clone(&self) -> Bitmap

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Bitmap

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Bitmap

Source§

fn default() -> Bitmap

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Bitmap

Available on crate feature serde only.
Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'a> Extend<&'a u32> for Bitmap

Source§

fn extend<I: IntoIterator<Item = &'a u32>>(&mut self, values: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl Extend<u32> for Bitmap

Source§

fn extend<I: IntoIterator<Item = u32>>(&mut self, values: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<'a> FromIterator<&'a u32> for Bitmap

Source§

fn from_iter<I: IntoIterator<Item = &'a u32>>(iterator: I) -> Bitmap

Creates a value from an iterator. Read more
Source§

impl FromIterator<u32> for Bitmap

Source§

fn from_iter<I: IntoIterator<Item = u32>>(iterator: I) -> Bitmap

Creates a value from an iterator. Read more
Source§

impl PartialEq for Bitmap

Source§

fn eq(&self, other: &Bitmap) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Bitmap

Available on crate feature serde only.
Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

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§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<U> As for U

§

fn as_<T>(self) -> T
where T: CastFrom<U>,

Casts 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 more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,