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§
source§impl 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>
pub fn try_from_bits<I>(iter: I) -> Result<Self, OutOfRangeError>
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--x
sourcepub 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§
source§impl BitAndAssign<&BitField> for BitField
impl BitAndAssign<&BitField> for BitField
source§fn bitand_assign(&mut self, rhs: &BitField)
fn bitand_assign(&mut self, rhs: &BitField)
&=
operation. Read moresource§impl BitAndAssign for BitField
impl BitAndAssign for BitField
source§fn bitand_assign(&mut self, rhs: BitField)
fn bitand_assign(&mut self, rhs: BitField)
&=
operation. Read moresource§impl BitOrAssign<&BitField> for BitField
impl BitOrAssign<&BitField> for BitField
source§fn bitor_assign(&mut self, rhs: &BitField)
fn bitor_assign(&mut self, rhs: &BitField)
|=
operation. Read moresource§impl BitOrAssign for BitField
impl BitOrAssign for BitField
source§fn bitor_assign(&mut self, rhs: BitField)
fn bitor_assign(&mut self, rhs: BitField)
|=
operation. Read moresource§impl BitXorAssign<&BitField> for BitField
impl BitXorAssign<&BitField> for BitField
source§fn bitxor_assign(&mut self, rhs: &BitField)
fn bitxor_assign(&mut self, rhs: &BitField)
^=
operation. Read moresource§impl BitXorAssign for BitField
impl BitXorAssign for BitField
source§fn bitxor_assign(&mut self, rhs: BitField)
fn bitxor_assign(&mut self, rhs: BitField)
^=
operation. Read moresource§impl<'de> Deserialize<'de> for BitField
impl<'de> Deserialize<'de> for BitField
source§fn 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>,
source§impl From<BitField> for BitFieldJson
impl From<BitField> for BitFieldJson
source§impl From<BitField> for UnvalidatedBitField
impl From<BitField> for UnvalidatedBitField
source§impl From<BitFieldJson> for BitField
impl From<BitFieldJson> for BitField
source§fn from(wrapper: BitFieldJson) -> Self
fn from(wrapper: BitFieldJson) -> Self
source§impl PartialEq for BitField
impl PartialEq for BitField
source§impl SubAssign<&BitField> for BitField
impl SubAssign<&BitField> for BitField
source§fn sub_assign(&mut self, rhs: &BitField)
fn sub_assign(&mut self, rhs: &BitField)
-=
operation. Read moresource§impl SubAssign for BitField
impl SubAssign for BitField
source§fn sub_assign(&mut self, rhs: BitField)
fn sub_assign(&mut self, rhs: BitField)
-=
operation. Read moresource§impl TryFrom<UnvalidatedBitField> for BitField
impl TryFrom<UnvalidatedBitField> for BitField
Auto Trait Implementations§
impl Freeze for BitField
impl RefUnwindSafe for BitField
impl Send for BitField
impl Sync for BitField
impl Unpin for BitField
impl UnwindSafe for BitField
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)