Skip to main content

Bitmap

Struct Bitmap 

Source
pub struct Bitmap { /* private fields */ }
Expand description

A 64-bit roaring-style compressed bitmap.

This is an append-only data structure optimized for memory efficiency and fast set operations. Values can be inserted but not removed.

§Example

use commonware_utils::bitmap::roaring::Bitmap;

let mut bitmap = Bitmap::new();
bitmap.insert(42);
bitmap.insert(100);
bitmap.insert_range(1000..2000);

assert!(bitmap.contains(42));
assert!(bitmap.contains(1500));
assert!(!bitmap.contains(500));

// Iterate over values
for value in bitmap.iter().take(10) {
    println!("{}", value);
}

Implementations§

Source§

impl Bitmap

Source

pub fn union(&self, other: &Self, limit: u64) -> Self

Computes the union of two bitmaps, returning at most limit values.

Pass u64::MAX for unlimited results.

Source

pub fn intersection(&self, other: &Self, limit: u64) -> Self

Computes the intersection of two bitmaps, returning at most limit values.

Pass u64::MAX for unlimited results.

Source

pub fn difference(&self, other: &Self, limit: u64) -> Self

Computes the difference self - other, returning at most limit values.

Pass u64::MAX for unlimited results.

Source

pub fn is_subset(&self, other: &Self) -> bool

Returns true if every value in this bitmap is present in other.

Source

pub fn intersects(&self, other: &Self) -> bool

Returns true if the bitmaps share at least one value.

Source§

impl Bitmap

Source

pub const fn new() -> Self

Creates an empty roaring bitmap.

Source

pub fn len(&self) -> u64

Returns the number of values in the bitmap.

Source

pub fn is_empty(&self) -> bool

Returns whether the bitmap is empty.

Source

pub fn container_count(&self) -> usize

Returns the number of containers in the bitmap.

Source

pub fn clear(&mut self)

Clears all values from the bitmap.

Source

pub fn contains(&self, value: u64) -> bool

Checks if the bitmap contains the given value.

Source

pub fn insert(&mut self, value: u64) -> bool

Inserts a value into the bitmap.

Returns true if the value was newly inserted, false if it already existed.

Source

pub fn insert_range(&mut self, range: Range<u64>) -> u64

Inserts a range of values into the bitmap.

Returns the number of values newly inserted.

Source

pub fn iter(&self) -> impl Iterator<Item = u64> + '_

Returns an iterator over the values in sorted order.

Source

pub fn iter_range(&self, range: Range<u64>) -> impl Iterator<Item = u64> + '_

Returns an iterator over the values in the range in sorted order.

Source

pub fn min(&self) -> Option<u64>

Returns the minimum value in the bitmap, if any.

Source

pub fn max(&self) -> Option<u64>

Returns the maximum value in the bitmap, if any.

Trait Implementations§

Source§

impl Clone for Bitmap

Source§

fn clone(&self) -> Bitmap

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 EncodeSize for Bitmap

Source§

fn encode_size(&self) -> usize

Returns the encoded size of this value (in bytes).
Source§

fn encode_inline_size(&self) -> usize

Returns the encoded size excluding bytes passed to BufsMut::push during Write::write_bufs. Used to size the working buffer for inline writes. Override alongside Write::write_bufs for types where large Bytes fields go via push; failing to do so will over-allocate.
Source§

impl Extend<u64> for Bitmap

Source§

fn extend<I: IntoIterator<Item = u64>>(&mut self, iter: 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 FromIterator<u64> for Bitmap

Source§

fn from_iter<I: IntoIterator<Item = u64>>(iter: I) -> Self

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 (const: unstable) · 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 Read for Bitmap

Source§

type Cfg = RangeCfg<usize>

Configuration for decoding: range limit on number of containers.

Use RangeCfg::new(..=max_containers) to limit memory allocation.

Source§

fn read_cfg(buf: &mut impl Buf, cfg: &Self::Cfg) -> Result<Self, CodecError>

Reads a value from the buffer using the provided configuration cfg. Read more
Source§

impl Write for Bitmap

Source§

fn write(&self, buf: &mut impl BufMut)

Writes the binary representation of self to the provided buffer buf. Read more
Source§

fn write_bufs(&self, buf: &mut impl BufsMut)

Writes to a BufsMut, allowing existing Bytes chunks to be appended via BufsMut::push instead of written inline. Must encode to the same format as Write::write. Defaults to Write::write.
Source§

impl Eq for Bitmap

Source§

impl StructuralPartialEq for Bitmap

Auto Trait Implementations§

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
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> Decode for T
where T: Read,

Source§

fn decode_cfg(buf: impl Buf, cfg: &Self::Cfg) -> Result<Self, Error>

Decodes a value from buf using cfg, ensuring the entire buffer is consumed. Read more
Source§

impl<T> Encode for T
where T: Write + EncodeSize,

Source§

fn encode(&self) -> Bytes

Encodes self into a new Bytes buffer. Read more
Source§

fn encode_mut(&self) -> BytesMut

Encodes self into a new BytesMut buffer. 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> 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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> Codec for T
where T: Encode + Decode,

Source§

impl<T> CodecShared for T
where T: Codec + Send + Sync,

Source§

impl<T> EncodeShared for T
where T: Encode + Send + Sync,