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 try_from_bits<I>(iter: I) -> Result<Self, OutOfRangeError> where
I: IntoIterator,
MaybeBitField: FromIterator<I::Item>,
pub fn try_from_bits<I>(iter: I) -> Result<Self, OutOfRangeError> where
I: IntoIterator,
MaybeBitField: FromIterator<I::Item>,
Tries to create a new bitfield from a bit iterator. It fails if the resulting bitfield would
contain values not in the range 0..u64::MAX (non-inclusive).
sourcepub fn set(&mut self, bit: u64)
pub fn set(&mut self, bit: u64)
Adds the bit at a given index to the bit field, panicing if it’s out of range.
Panics
Panics if bit is u64::MAX.
sourcepub fn try_set(&mut self, bit: u64) -> Result<(), OutOfRangeError>
pub fn try_set(&mut self, bit: u64) -> Result<(), OutOfRangeError>
Adds the bit at a given index to the bit field, returning an error if it’s out of range.
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 last(&self) -> Option<u64>
pub fn last(&self) -> Option<u64>
Returns the index of the highest 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) -> Option<impl Iterator<Item = u64> + '_>
pub fn bounded_iter(&self, max: u64) -> Option<impl Iterator<Item = u64> + '_>
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 None 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) -> Option<Self>
pub fn slice(&self, start: u64, len: u64) -> Option<Self>
Returns a slice of the bit field with the start index of set bits
and number of bits to include in the slice. Returns None 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 SubAssign<&'_ BitField> for BitField
impl SubAssign<&'_ BitField> for BitField
sourcefn sub_assign(&mut self, rhs: &BitField)
fn sub_assign(&mut self, rhs: &BitField)
Performs the -= operation. Read more
sourceimpl TryFrom<UnvalidatedBitField> for BitField
impl TryFrom<UnvalidatedBitField> for BitField
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