pub struct SparseMap { /* private fields */ }Expand description
A sparse, compressed, run-length-encoded bitset over u64 indices.
See the crate-level documentation for the data model.
Implementations§
Source§impl SparseMap
impl SparseMap
Source§impl SparseMap
impl SparseMap
Sourcepub fn union(&self, other: &SparseMap) -> SparseMap
pub fn union(&self, other: &SparseMap) -> SparseMap
Returns the union (self ∪ other): bits set in either map.
Sourcepub fn intersection(&self, other: &SparseMap) -> SparseMap
pub fn intersection(&self, other: &SparseMap) -> SparseMap
Returns the intersection (self ∩ other): bits set in both maps.
Sourcepub fn difference(&self, other: &SparseMap) -> SparseMap
pub fn difference(&self, other: &SparseMap) -> SparseMap
Returns the difference (self \ other): bits set in self but
not in other.
Sourcepub fn symmetric_difference(&self, other: &SparseMap) -> SparseMap
pub fn symmetric_difference(&self, other: &SparseMap) -> SparseMap
Returns the symmetric difference (self △ other): bits set in
exactly one map.
Sourcepub fn intersects(&self, other: &SparseMap) -> bool
pub fn intersects(&self, other: &SparseMap) -> bool
Returns true if self and other share at least one bit.
Sourcepub fn is_subset(&self, other: &SparseMap) -> bool
pub fn is_subset(&self, other: &SparseMap) -> bool
Returns true if every bit set in self is also set in other.
Sourcepub fn is_superset(&self, other: &SparseMap) -> bool
pub fn is_superset(&self, other: &SparseMap) -> bool
Returns true if every bit set in other is also set in self.
Source§impl SparseMap
impl SparseMap
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
Serializes the map into the C-compatible wire format (version 2: 8-byte chunk-start offsets, addressing the full 64-bit universe).
Sourcepub fn from_bytes(buf: &[u8]) -> Result<SparseMap, DecodeError>
pub fn from_bytes(buf: &[u8]) -> Result<SparseMap, DecodeError>
Deserializes a buffer produced by SparseMap::to_bytes or by
the C sm_serialize.
§Errors
Returns a DecodeError for any malformed input rather than
panicking; arbitrary bytes are safe to feed in.
Source§impl SparseMap
impl SparseMap
Sourcepub fn cardinality(&self) -> u64
pub fn cardinality(&self) -> u64
Returns the number of set bits (the cardinality).
Runs are counted in O(1), so this is cheap even for maps
dominated by long runs.
Sourcepub fn len(&self) -> u64
pub fn len(&self) -> u64
Returns the number of set bits.
An alias for cardinality, named to match
the Rust collection convention (and roaring::RoaringBitmap),
so the type drops in for code written against those APIs.
Sourcepub fn insert(&mut self, idx: u64) -> bool
pub fn insert(&mut self, idx: u64) -> bool
Sets bit idx. Returns true if the bit was newly set,
false if it was already set (mirroring alloc::collections::BTreeSet::insert).
Sourcepub fn remove(&mut self, idx: u64) -> bool
pub fn remove(&mut self, idx: u64) -> bool
Clears bit idx. Returns true if the bit had been set.
Sourcepub fn rank(&self, idx: u64) -> u64
pub fn rank(&self, idx: u64) -> u64
Returns the number of set bits strictly less than idx
(the standard succinct-structure rank).
rank(0) is always 0; rank(u64::MAX) + contains(u64::MAX) as u64 is the cardinality.
Sourcepub fn select(&self, n: u64) -> Option<u64>
pub fn select(&self, n: u64) -> Option<u64>
Returns the position of the n-th set bit (0-based), or None
if there are n or fewer set bits.
select(0) is min.
Sourcepub fn insert_range(&mut self, start: u64, end: u64)
pub fn insert_range(&mut self, start: u64, end: u64)
Sets every bit in the half-open range [start, end).
Sourcepub fn remove_range(&mut self, start: u64, end: u64)
pub fn remove_range(&mut self, start: u64, end: u64)
Clears every bit in the half-open range [start, end).
Trait Implementations§
Source§impl BitAndAssign<&SparseMap> for SparseMap
impl BitAndAssign<&SparseMap> for SparseMap
Source§fn bitand_assign(&mut self, rhs: &SparseMap)
fn bitand_assign(&mut self, rhs: &SparseMap)
&= operation. Read moreSource§impl BitOrAssign<&SparseMap> for SparseMap
impl BitOrAssign<&SparseMap> for SparseMap
Source§fn bitor_assign(&mut self, rhs: &SparseMap)
fn bitor_assign(&mut self, rhs: &SparseMap)
|= operation. Read moreSource§impl BitXorAssign<&SparseMap> for SparseMap
impl BitXorAssign<&SparseMap> for SparseMap
Source§fn bitxor_assign(&mut self, rhs: &SparseMap)
fn bitxor_assign(&mut self, rhs: &SparseMap)
^= operation. Read moreimpl Eq for SparseMap
Source§impl<'a> Extend<&'a u64> for SparseMap
impl<'a> Extend<&'a u64> for SparseMap
Source§fn extend<I: IntoIterator<Item = &'a u64>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = &'a u64>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: T)
fn extend_one(&mut self, item: T)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl Extend<u64> for SparseMap
impl Extend<u64> for SparseMap
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: T)
fn extend_one(&mut self, item: T)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)