Struct BitSet

Source
pub struct BitSet<I: Idx + From<usize>> { /* private fields */ }

Implementations§

Source§

impl<I: Idx + From<usize>> BitSet<I>

Source

pub fn new_empty(end_index: I) -> Self

Create a new empty BitSet which can hold elements x < end_index

Source

pub fn new_filled(end_index: I) -> Self

Create a new empty BitSet which can hold elements x < end_index

Source

pub fn with_capacity_and_blocks<Iter: IntoIterator<Item = u32>>( bits: I, blocks: Iter, ) -> Self

Create a new BitSet with a specific number of bits, initialized from provided blocks.

If the blocks are not the exact size needed for the capacity they will be padded with zeros (if shorter) or truncated to the capacity (if longer).

Source

pub fn grow(&mut self, len_idx: I)

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 len_idx(&self) -> I

Return the length of the FixedBitSet in bits.

Source

pub fn max(&self) -> I

Return the length of the FixedBitSet in bits.

Source

pub fn contains(&self, bit: I) -> 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: I)

Enable bit.

Panics if bit is out of bounds.

Source

pub fn remove(&mut self, bit: I) -> bool

Disable bit.

Panics if bit is out of bounds.

Source

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

Enable bit, and return its previous value.

Panics if bit is out of bounds.

Source

pub fn toggle(&mut self, bit: I)

Toggle bit (inverting its state).

Panics if bit is out of bounds

Source

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

Panics if bit is out of bounds.

Source

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

Copies boolean value from specified bit to the specified bit.

Panics if to is out of bounds.

Source

pub fn count_ones<T: IndexRange<I>>(&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<I>>(&mut self, range: T, enabled: bool)

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

Use .. to set the whole bitset.

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

Source

pub fn insert_range<T: IndexRange<I>>(&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 enable_all(&mut self)

Equivalent to insert_range(..) but significantly faster

Source

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

Toggles (inverts) every bit in the given range.

Use .. to toggle the whole bitset.

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 is_empty(&self) -> bool

Source

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

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 Self) -> Intersection<'a, I>

Returns a lazy iterator over the intersection of two FixedBitSets

Source

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

Returns a lazy iterator over the union of two FixedBitSets.

Source

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

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.

Source

pub fn symmetric_difference<'a>( &'a self, other: &'a Self, ) -> SymmetricDifference<'a, I>

Returns a lazy iterator over the symmetric difference of two FixedBitSets. The symmetric difference of a and b is the elements of one, but not both, sets.

Source

pub fn union_with(&mut self, other: &Self)

In-place union of two FixedBitSets.

On calling this method, self’s capacity may be increased to match other’s.

Source

pub fn intersect_with(&mut self, other: &Self)

In-place intersection of two FixedBitSets.

On calling this method, self’s capacity will remain the same as before.

Source

pub fn difference_with(&mut self, other: &Self)

In-place difference of two FixedBitSets.

On calling this method, self’s capacity will remain the same as before.

Source

pub fn symmetric_difference_with(&mut self, other: &Self)

In-place symmetric difference of two FixedBitSets.

On calling this method, self’s capacity may be increased to match other’s.

Source

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

Returns true if self has no elements in common with other. This is equivalent to checking for an empty intersection.

Source

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

Returns true if the set is a subset of another, i.e. other contains at least all the values in self.

Source

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

Returns true if the set is a superset of another, i.e. self contains at least all the values in other.

Trait Implementations§

Source§

impl<I: Idx + From<usize>> Binary for BitSet<I>

Source§

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

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

impl<'a, I: Idx + From<usize>> BitAnd for &'a BitSet<I>

Source§

type Output = BitSet<I>

The resulting type after applying the & operator.
Source§

fn bitand(self, other: &BitSet<I>) -> BitSet<I>

Performs the & operation. Read more
Source§

impl<'a, I: Idx + From<usize>> BitAndAssign for BitSet<I>

Source§

fn bitand_assign(&mut self, other: Self)

Performs the &= operation. Read more
Source§

impl<'a, I: Idx + From<usize>> BitOr for &'a BitSet<I>

Source§

type Output = BitSet<I>

The resulting type after applying the | operator.
Source§

fn bitor(self, other: &BitSet<I>) -> BitSet<I>

Performs the | operation. Read more
Source§

impl<'a, I: Idx + From<usize>> BitOrAssign for BitSet<I>

Source§

fn bitor_assign(&mut self, other: Self)

Performs the |= operation. Read more
Source§

impl<'a, I: Idx + From<usize>> BitXor for &'a BitSet<I>

Source§

type Output = BitSet<I>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, other: &BitSet<I>) -> BitSet<I>

Performs the ^ operation. Read more
Source§

impl<'a, I: Idx + From<usize>> BitXorAssign for BitSet<I>

Source§

fn bitxor_assign(&mut self, other: Self)

Performs the ^= operation. Read more
Source§

impl<I: Idx + From<usize>> Clone for BitSet<I>

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<I: Debug + Idx + From<usize>> Debug for BitSet<I>

Source§

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

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

impl<I: Default + Idx + From<usize>> Default for BitSet<I>

Source§

fn default() -> BitSet<I>

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

impl<I: Idx + From<usize> + Display> Display for BitSet<I>

Source§

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

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

impl<I: Idx + From<usize>> Extend<I> for BitSet<I>

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

Source§

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

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<I: Idx + From<usize>> From<BitSet<I>> for WorkQueue<I>

Source§

fn from(set: BitSet<I>) -> Self

Converts to this type from the input type.
Source§

impl<I: Idx + From<usize>> FromIterator<I> for BitSet<I>

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<Iter: IntoIterator<Item = I>>(src: Iter) -> Self

Creates a value from an iterator. Read more
Source§

impl<I: Hash + Idx + From<usize>> Hash for BitSet<I>

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<I: Idx + From<usize>> Index<I> for BitSet<I>

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: I) -> &bool

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

impl<I: Ord + Idx + From<usize>> Ord for BitSet<I>

Source§

fn cmp(&self, other: &BitSet<I>) -> 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,

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

impl<I: PartialEq + Idx + From<usize>> PartialEq for BitSet<I>

Source§

fn eq(&self, other: &BitSet<I>) -> 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<I: PartialOrd + Idx + From<usize>> PartialOrd for BitSet<I>

Source§

fn partial_cmp(&self, other: &BitSet<I>) -> 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<I: Eq + Idx + From<usize>> Eq for BitSet<I>

Source§

impl<I: Idx + From<usize>> StructuralPartialEq for BitSet<I>

Auto Trait Implementations§

§

impl<I> Freeze for BitSet<I>

§

impl<I> RefUnwindSafe for BitSet<I>

§

impl<I> Send for BitSet<I>

§

impl<I> Sync for BitSet<I>

§

impl<I> Unpin for BitSet<I>

§

impl<I> UnwindSafe for BitSet<I>

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, dest: *mut u8)

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

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.