pub struct BitSet<I: Idx + From<usize>> { /* private fields */ }
Implementations§
Source§impl<I: Idx + From<usize>> BitSet<I>
impl<I: Idx + From<usize>> BitSet<I>
Sourcepub fn new_empty(end_index: I) -> Self
pub fn new_empty(end_index: I) -> Self
Create a new empty BitSet
which can hold elements x < end_index
Sourcepub fn new_filled(end_index: I) -> Self
pub fn new_filled(end_index: I) -> Self
Create a new empty BitSet
which can hold elements x < end_index
Sourcepub fn with_capacity_and_blocks<Iter: IntoIterator<Item = u32>>(
bits: I,
blocks: Iter,
) -> Self
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).
Sourcepub fn contains(&self, bit: I) -> bool
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]
.
Sourcepub fn put(&mut self, bit: I) -> bool
pub fn put(&mut self, bit: I) -> bool
Enable bit
, and return its previous value.
Panics if bit
is out of bounds.
Sourcepub fn toggle(&mut self, bit: I)
pub fn toggle(&mut self, bit: I)
Toggle bit
(inverting its state).
Panics
if bit
is out of bounds
Sourcepub fn copy_bit(&mut self, from: I, to: I)
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.
Sourcepub fn count_ones<T: IndexRange<I>>(&self, range: T) -> usize
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.
Sourcepub fn set_range<T: IndexRange<I>>(&mut self, range: T, enabled: bool)
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.
Sourcepub fn insert_range<T: IndexRange<I>>(&mut self, range: T)
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.
Sourcepub fn enable_all(&mut self)
pub fn enable_all(&mut self)
Equivalent to insert_range(..)
but significantly faster
Sourcepub fn toggle_range<T: IndexRange<I>>(&mut self, range: T)
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.
Sourcepub fn as_mut_slice(&mut self) -> &mut [u32]
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.
pub fn is_empty(&self) -> bool
Sourcepub fn ones(&self) -> Ones<'_, I>
pub fn ones(&self) -> Ones<'_, I>
Iterates over all enabled bits.
Iterator element is the index of the 1
bit, type usize
.
Sourcepub fn intersection<'a>(&'a self, other: &'a Self) -> Intersection<'a, I>
pub fn intersection<'a>(&'a self, other: &'a Self) -> Intersection<'a, I>
Returns a lazy iterator over the intersection of two FixedBitSet
s
Sourcepub fn union<'a>(&'a self, other: &'a Self) -> Union<'a, I>
pub fn union<'a>(&'a self, other: &'a Self) -> Union<'a, I>
Returns a lazy iterator over the union of two FixedBitSet
s.
Sourcepub fn difference<'a>(&'a self, other: &'a Self) -> Difference<'a, I>
pub fn difference<'a>(&'a self, other: &'a Self) -> Difference<'a, I>
Returns a lazy iterator over the difference of two FixedBitSet
s. The difference of a
and b
is the elements of a
which are not in b
.
Sourcepub fn symmetric_difference<'a>(
&'a self,
other: &'a Self,
) -> SymmetricDifference<'a, I>
pub fn symmetric_difference<'a>( &'a self, other: &'a Self, ) -> SymmetricDifference<'a, I>
Returns a lazy iterator over the symmetric difference of two FixedBitSet
s.
The symmetric difference of a
and b
is the elements of one, but not both, sets.
Sourcepub fn union_with(&mut self, other: &Self)
pub fn union_with(&mut self, other: &Self)
In-place union of two FixedBitSet
s.
On calling this method, self
’s capacity may be increased to match other
’s.
Sourcepub fn intersect_with(&mut self, other: &Self)
pub fn intersect_with(&mut self, other: &Self)
In-place intersection of two FixedBitSet
s.
On calling this method, self
’s capacity will remain the same as before.
Sourcepub fn difference_with(&mut self, other: &Self)
pub fn difference_with(&mut self, other: &Self)
In-place difference of two FixedBitSet
s.
On calling this method, self
’s capacity will remain the same as before.
Sourcepub fn symmetric_difference_with(&mut self, other: &Self)
pub fn symmetric_difference_with(&mut self, other: &Self)
In-place symmetric difference of two FixedBitSet
s.
On calling this method, self
’s capacity may be increased to match other
’s.
Sourcepub fn is_disjoint(&self, other: &Self) -> bool
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.
Sourcepub fn is_subset(&self, other: &Self) -> bool
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
.
Sourcepub fn is_superset(&self, other: &Self) -> bool
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<'a, I: Idx + From<usize>> BitAndAssign for BitSet<I>
impl<'a, I: Idx + From<usize>> BitAndAssign for BitSet<I>
Source§fn bitand_assign(&mut self, other: Self)
fn bitand_assign(&mut self, other: Self)
&=
operation. Read moreSource§impl<'a, I: Idx + From<usize>> BitOrAssign for BitSet<I>
impl<'a, I: Idx + From<usize>> BitOrAssign for BitSet<I>
Source§fn bitor_assign(&mut self, other: Self)
fn bitor_assign(&mut self, other: Self)
|=
operation. Read moreSource§impl<'a, I: Idx + From<usize>> BitXorAssign for BitSet<I>
impl<'a, I: Idx + From<usize>> BitXorAssign for BitSet<I>
Source§fn bitxor_assign(&mut self, other: Self)
fn bitxor_assign(&mut self, other: Self)
^=
operation. Read moreSource§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.
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)
fn extend<Iter: IntoIterator<Item = I>>(&mut self, src: Iter)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)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.
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
fn from_iter<Iter: IntoIterator<Item = I>>(src: Iter) -> Self
Source§impl<I: Idx + From<usize>> Index<I> for BitSet<I>
Return true if the bit is enabled in the bitset,
or false otherwise.
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§impl<I: Ord + Idx + From<usize>> Ord for BitSet<I>
impl<I: Ord + Idx + From<usize>> Ord for BitSet<I>
Source§impl<I: PartialOrd + Idx + From<usize>> PartialOrd for BitSet<I>
impl<I: PartialOrd + Idx + From<usize>> PartialOrd for BitSet<I>
impl<I: Eq + Idx + From<usize>> Eq for BitSet<I>
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> 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§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.