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

source

pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error>

Decodes RLE+ encoded bytes into a bit field.

source

pub fn to_bytes(&self) -> Vec<u8>

Turns a bit field into its RLE+ encoded form.

source§

impl BitField

source

pub const fn new() -> Self

Creates an empty bit field.

source

pub fn from_ranges(iter: impl RangeIterator) -> Self

Creates a new bit field from a RangeIterator.

source

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).

source

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.

source

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.

source

pub fn unset(&mut self, bit: u64)

Removes the bit at a given index from the bit field.

source

pub fn get(&self, index: u64) -> bool

Returns true if the bit field contains the bit at a given index.

source

pub fn first(&self) -> Option<u64>

Returns the index of the lowest bit present in the bit field.

source

pub fn last(&self) -> Option<u64>

Returns the index of the highest bit present in the bit field.

source

pub fn iter(&self) -> impl Iterator<Item = u64> + '_

Returns an iterator over the indices of the bit field’s set bits.

source

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.

source

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.

source

pub fn is_empty(&self) -> bool

Returns true if the bit field is empty.

source

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.

source

pub fn len(&self) -> u64

Returns the number of set bits in the bit field.

source

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
source

pub fn union<'a>(bitfields: impl IntoIterator<Item = &'a Self>) -> Self

Returns the union of the given bit fields as a new bit field.

source

pub fn contains_any(&self, other: &BitField) -> bool

Returns true if self overlaps with other.

source

pub fn contains_all(&self, other: &BitField) -> bool

Returns true if the self is a superset of other.

Trait Implementations§

source§

impl BitAnd<&BitField> for &BitField

§

type Output = BitField

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: &BitField) -> Self::Output

Performs the & operation. Read more
source§

impl BitAnd<&BitField> for BitField

§

type Output = BitField

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: &BitField) -> Self::Output

Performs the & operation. Read more
source§

impl BitAnd<BitField> for &BitField

§

type Output = BitField

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: BitField) -> Self::Output

Performs the & operation. Read more
source§

impl BitAnd for BitField

§

type Output = BitField

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: BitField) -> Self::Output

Performs the & operation. Read more
source§

impl BitAndAssign<&BitField> for BitField

source§

fn bitand_assign(&mut self, rhs: &BitField)

Performs the &= operation. Read more
source§

impl BitAndAssign for BitField

source§

fn bitand_assign(&mut self, rhs: BitField)

Performs the &= operation. Read more
source§

impl BitOr<&BitField> for &BitField

§

type Output = BitField

The resulting type after applying the | operator.
source§

fn bitor(self, rhs: &BitField) -> Self::Output

Performs the | operation. Read more
source§

impl BitOr<&BitField> for BitField

§

type Output = BitField

The resulting type after applying the | operator.
source§

fn bitor(self, rhs: &BitField) -> Self::Output

Performs the | operation. Read more
source§

impl BitOr<BitField> for &BitField

§

type Output = BitField

The resulting type after applying the | operator.
source§

fn bitor(self, rhs: BitField) -> Self::Output

Performs the | operation. Read more
source§

impl BitOr for BitField

§

type Output = BitField

The resulting type after applying the | operator.
source§

fn bitor(self, rhs: BitField) -> Self::Output

Performs the | operation. Read more
source§

impl BitOrAssign<&BitField> for BitField

source§

fn bitor_assign(&mut self, rhs: &BitField)

Performs the |= operation. Read more
source§

impl BitOrAssign for BitField

source§

fn bitor_assign(&mut self, rhs: BitField)

Performs the |= operation. Read more
source§

impl BitXor<&BitField> for &BitField

§

type Output = BitField

The resulting type after applying the ^ operator.
source§

fn bitxor(self, rhs: &BitField) -> Self::Output

Performs the ^ operation. Read more
source§

impl BitXor<&BitField> for BitField

§

type Output = BitField

The resulting type after applying the ^ operator.
source§

fn bitxor(self, rhs: &BitField) -> Self::Output

Performs the ^ operation. Read more
source§

impl BitXor<BitField> for &BitField

§

type Output = BitField

The resulting type after applying the ^ operator.
source§

fn bitxor(self, rhs: BitField) -> Self::Output

Performs the ^ operation. Read more
source§

impl BitXor for BitField

§

type Output = BitField

The resulting type after applying the ^ operator.
source§

fn bitxor(self, rhs: BitField) -> Self::Output

Performs the ^ operation. Read more
source§

impl BitXorAssign<&BitField> for BitField

source§

fn bitxor_assign(&mut self, rhs: &BitField)

Performs the ^= operation. Read more
source§

impl BitXorAssign for BitField

source§

fn bitxor_assign(&mut self, rhs: BitField)

Performs the ^= operation. Read more
source§

impl Clone for BitField

source§

fn clone(&self) -> BitField

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for BitField

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for BitField

source§

fn default() -> BitField

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for BitField

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl From<BitField> for BitFieldJson

source§

fn from(wrapper: BitField) -> Self

Converts to this type from the input type.
source§

impl From<BitField> for UnvalidatedBitField

source§

fn from(bf: BitField) -> Self

Converts to this type from the input type.
source§

impl From<BitFieldJson> for BitField

source§

fn from(wrapper: BitFieldJson) -> Self

Converts to this type from the input type.
source§

impl PartialEq for BitField

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for BitField

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Sub<&BitField> for &BitField

§

type Output = BitField

The resulting type after applying the - operator.
source§

fn sub(self, rhs: &BitField) -> Self::Output

Performs the - operation. Read more
source§

impl Sub<&BitField> for BitField

§

type Output = BitField

The resulting type after applying the - operator.
source§

fn sub(self, rhs: &BitField) -> Self::Output

Performs the - operation. Read more
source§

impl Sub<BitField> for &BitField

§

type Output = BitField

The resulting type after applying the - operator.
source§

fn sub(self, rhs: BitField) -> Self::Output

Performs the - operation. Read more
source§

impl Sub for BitField

§

type Output = BitField

The resulting type after applying the - operator.
source§

fn sub(self, rhs: BitField) -> Self::Output

Performs the - operation. Read more
source§

impl SubAssign<&BitField> for BitField

source§

fn sub_assign(&mut self, rhs: &BitField)

Performs the -= operation. Read more
source§

impl SubAssign for BitField

source§

fn sub_assign(&mut self, rhs: BitField)

Performs the -= operation. Read more
source§

impl TryFrom<UnvalidatedBitField> for BitField

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(bf: UnvalidatedBitField) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'a> Validate<'a> for &'a BitField

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,