Struct fixedbitset::FixedBitSet

source ·
pub struct FixedBitSet {
    pub(crate) data: Vec<u32>,
    pub(crate) length: usize,
}
Expand description

FixedBitSet is a simple fixed size set of bits that each can be enabled (1 / true) or disabled (0 / false).

The bit set has a fixed capacity in terms of enabling bits (and the capacity can grow using the grow method).

Fields§

§data: Vec<u32>§length: usize

length in bits

Implementations§

source§

impl FixedBitSet

source

pub fn with_capacity(bits: usize) -> Self

Create a new FixedBitSet with a specific number of bits, all initially clear.

source

pub fn grow(&mut self, bits: usize)

Grow capacity to bits, all new bits initialized to zero

source

pub fn len(&self) -> usize

Return the length of the FixedBitSet in bits.

source

pub fn contains(&self, bit: usize) -> bool

Return true if the bit is enabled in the FixedBitSet, false otherwise.

Note: bits outside the capacity are always disabled.

Note: Also available with index syntax: bitset[bit].

source

pub fn clear(&mut self)

Clear all bits.

source

pub fn insert(&mut self, bit: usize)

Enable bit.

Panics if bit is out of bounds.

source

pub fn put(&mut self, bit: usize) -> bool

Enable bit, and return its previous value.

Panics if bit is out of bounds.

source

pub fn set(&mut self, bit: usize, enabled: bool)

Panics if bit is out of bounds.

source

pub fn copy_bit(&mut self, from: usize, to: usize)

Copies boolean value from specified bit to the specified bit.

Panics if to is out of bounds.

source

pub fn count_ones<T: IndexRange>(&self, range: T) -> usize

Count the number of set bits in the given bit range.

Use .. to count the whole content of the bitset.

Panics if the range extends past the end of the bitset.

source

pub fn set_range<T: IndexRange>(&mut self, range: T, enabled: bool)

Sets every bit in the given range to the given state (enabled)

Use .. to toggle the whole bitset.

Panics if the range extends past the end of the bitset.

source

pub fn insert_range<T: IndexRange>(&mut self, range: T)

Enables every bit in the given range.

Use .. to make the whole bitset ones.

Panics if the range extends past the end of the bitset.

source

pub fn as_slice(&self) -> &[u32]

View the bitset as a slice of u32 blocks

source

pub fn as_mut_slice(&mut self) -> &mut [u32]

View the bitset as a mutable slice of u32 blocks. Writing past the bitlength in the last will cause contains to return potentially incorrect results for bits past the bitlength.

source

pub fn ones(&self) -> Ones<'_>

Iterates over all enabled bits.

Iterator element is the index of the 1 bit, type usize.

source

pub fn intersection<'a>(&'a self, other: &'a FixedBitSet) -> Intersection<'a>

Returns a lazy iterator over the intersection of two FixedBitSets

source

pub fn union<'a>(&'a self, other: &'a FixedBitSet) -> Union<'a>

Returns a lazy iterator over the union of two FixedBitSets.

source

pub fn difference<'a>(&'a self, other: &'a FixedBitSet) -> Difference<'a>

Returns a lazy iterator over the difference of two FixedBitSets. The difference of a and b is the elements of a which are not in b.

Trait Implementations§

source§

impl<'a> BitAnd for &'a FixedBitSet

source§

type Output = FixedBitSet

The resulting type after applying the & operator.
source§

fn bitand(self, other: &FixedBitSet) -> FixedBitSet

Performs the & operation. Read more
source§

impl<'a> BitOr for &'a FixedBitSet

source§

type Output = FixedBitSet

The resulting type after applying the | operator.
source§

fn bitor(self, other: &FixedBitSet) -> FixedBitSet

Performs the | operation. Read more
source§

impl Clone for FixedBitSet

source§

fn clone(&self) -> Self

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 FixedBitSet

source§

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

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

impl Default for FixedBitSet

source§

fn default() -> FixedBitSet

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

impl Extend<usize> for FixedBitSet

Sets the bit at index i to true for each item i in the input src.

source§

fn extend<I: IntoIterator<Item = usize>>(&mut self, src: I)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl FromIterator<usize> for FixedBitSet

Return a FixedBitSet containing bits set to true for every bit index in the iterator, other bits are set to false.

source§

fn from_iter<I: IntoIterator<Item = usize>>(src: I) -> Self

Creates a value from an iterator. Read more
source§

impl Hash for FixedBitSet

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Index<usize> for FixedBitSet

Return true if the bit is enabled in the bitset, or false otherwise.

Note: bits outside the capacity are always disabled, and thus indexing a FixedBitSet will not panic.

source§

type Output = bool

The returned type after indexing.
source§

fn index(&self, bit: usize) -> &bool

Performs the indexing (container[index]) operation. Read more
source§

impl Ord for FixedBitSet

source§

fn cmp(&self, other: &FixedBitSet) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for FixedBitSet

source§

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

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

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

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

impl PartialOrd for FixedBitSet

source§

fn partial_cmp(&self, other: &FixedBitSet) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Eq for FixedBitSet

source§

impl StructuralPartialEq for FixedBitSet

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§

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> ToOwned for T
where T: Clone,

source§

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>,

source§

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>,

source§

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.