Struct fvm_ipld_bitfield::BitField
source · [−]pub struct BitField { /* private fields */ }Expand description
A bit field with buffered insertion/removal that serializes to/from RLE+. Similar to
HashSet<u64>, but more memory-efficient when long runs of 1s and 0s are present.
Implementations
sourceimpl BitField
impl BitField
sourcepub fn from_ranges(iter: impl RangeIterator) -> Self
pub fn from_ranges(iter: impl RangeIterator) -> Self
Creates a new bit field from a RangeIterator.
sourcepub fn get(&self, index: u64) -> bool
pub fn get(&self, index: u64) -> bool
Returns true if the bit field contains the bit at a given index.
sourcepub fn first(&self) -> Option<u64>
pub fn first(&self) -> Option<u64>
Returns the index of the lowest bit present in the bit field.
sourcepub fn iter(&self) -> impl Iterator<Item = u64> + '_
pub fn iter(&self) -> impl Iterator<Item = u64> + '_
Returns an iterator over the indices of the bit field’s set bits.
sourcepub fn bounded_iter(
&self,
max: u64
) -> Result<impl Iterator<Item = u64> + '_, &'static str>
pub fn bounded_iter(
&self,
max: u64
) -> Result<impl Iterator<Item = u64> + '_, &'static str>
Returns an iterator over the indices of the bit field’s set bits if the number
of set bits in the bit field does not exceed max. Returns an error otherwise.
sourcepub fn ranges(&self) -> impl RangeIterator + '_
pub fn ranges(&self) -> impl RangeIterator + '_
Returns an iterator over the ranges of set bits that make up the bit field. The ranges are in ascending order, are non-empty, and don’t overlap.
sourcepub fn slice(&self, start: u64, len: u64) -> Result<Self, &'static str>
pub fn slice(&self, start: u64, len: u64) -> Result<Self, &'static str>
Returns a slice of the bit field with the start index of set bits
and number of bits to include in the slice. Returns an error if the
bit field contains fewer than start + len set bits.
sourcepub fn cut(&self, other: &Self) -> Self
pub fn cut(&self, other: &Self) -> Self
Returns a new bit field containing the bits in self that remain
after “cutting” out the bits in other, and shifting remaining
bits to the left if necessary. For example:
lhs: xx-xxx--x
rhs: -xx-x----
cut: x x x--x
output: xxx--xsourcepub fn union<'a>(bitfields: impl IntoIterator<Item = &'a Self>) -> Self
pub fn union<'a>(bitfields: impl IntoIterator<Item = &'a Self>) -> Self
Returns the union of the given bit fields as a new bit field.
sourcepub fn contains_any(&self, other: &BitField) -> bool
pub fn contains_any(&self, other: &BitField) -> bool
Returns true if self overlaps with other.
sourcepub fn contains_all(&self, other: &BitField) -> bool
pub fn contains_all(&self, other: &BitField) -> bool
Returns true if the self is a superset of other.
Trait Implementations
sourceimpl BitAndAssign<&'_ BitField> for BitField
impl BitAndAssign<&'_ BitField> for BitField
sourcefn bitand_assign(&mut self, rhs: &BitField)
fn bitand_assign(&mut self, rhs: &BitField)
Performs the &= operation. Read more
sourceimpl BitOrAssign<&'_ BitField> for BitField
impl BitOrAssign<&'_ BitField> for BitField
sourcefn bitor_assign(&mut self, rhs: &BitField)
fn bitor_assign(&mut self, rhs: &BitField)
Performs the |= operation. Read more
sourceimpl BitXorAssign<&'_ BitField> for BitField
impl BitXorAssign<&'_ BitField> for BitField
sourcefn bitxor_assign(&mut self, rhs: &BitField)
fn bitxor_assign(&mut self, rhs: &BitField)
Performs the ^= operation. Read more
sourceimpl<'de> Deserialize<'de> for BitField
impl<'de> Deserialize<'de> for BitField
sourcefn 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>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl From<BitField> for UnvalidatedBitField
impl From<BitField> for UnvalidatedBitField
sourceimpl FromIterator<bool> for BitField
impl FromIterator<bool> for BitField
sourcefn from_iter<I: IntoIterator<Item = bool>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = bool>>(iter: I) -> Self
Creates a value from an iterator. Read more
sourceimpl FromIterator<u64> for BitField
impl FromIterator<u64> for BitField
sourcefn from_iter<I: IntoIterator<Item = u64>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = u64>>(iter: I) -> Self
Creates a value from an iterator. Read more
Auto Trait Implementations
impl RefUnwindSafe for BitField
impl Send for BitField
impl Sync for BitField
impl Unpin for BitField
impl UnwindSafe for BitField
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more