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
impl Bitmap
Sourcepub fn union(&self, other: &Self, limit: u64) -> Self
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.
Sourcepub fn intersection(&self, other: &Self, limit: u64) -> Self
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.
Sourcepub fn difference(&self, other: &Self, limit: u64) -> Self
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.
Sourcepub fn is_subset(&self, other: &Self) -> bool
pub fn is_subset(&self, other: &Self) -> bool
Returns true if every value in this bitmap is present in other.
Sourcepub fn intersects(&self, other: &Self) -> bool
pub fn intersects(&self, other: &Self) -> bool
Returns true if the bitmaps share at least one value.
Source§impl Bitmap
impl Bitmap
Sourcepub fn container_count(&self) -> usize
pub fn container_count(&self) -> usize
Returns the number of containers in the bitmap.
Sourcepub fn insert(&mut self, value: u64) -> bool
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.
Sourcepub fn insert_range(&mut self, range: Range<u64>) -> u64
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.
Sourcepub fn iter(&self) -> impl Iterator<Item = u64> + '_
pub fn iter(&self) -> impl Iterator<Item = u64> + '_
Returns an iterator over the values in sorted order.
Trait Implementations§
Source§impl EncodeSize for Bitmap
impl EncodeSize for Bitmap
Source§fn encode_size(&self) -> usize
fn encode_size(&self) -> usize
Source§fn encode_inline_size(&self) -> usize
fn encode_inline_size(&self) -> usize
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
impl Extend<u64> for Bitmap
Source§fn extend<I: IntoIterator<Item = u64>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = u64>>(&mut self, iter: 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 FromIterator<u64> for Bitmap
impl FromIterator<u64> for Bitmap
Source§impl Read for Bitmap
impl Read for Bitmap
Source§impl Write for Bitmap
impl Write for Bitmap
Source§fn write_bufs(&self, buf: &mut impl BufsMut)
fn write_bufs(&self, buf: &mut impl BufsMut)
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.