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
impl FixedBitSet
sourcepub fn with_capacity(bits: usize) -> Self
pub fn with_capacity(bits: usize) -> Self
Create a new FixedBitSet with a specific number of bits, all initially clear.
sourcepub fn contains(&self, bit: usize) -> bool
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]
.
sourcepub fn put(&mut self, bit: usize) -> bool
pub fn put(&mut self, bit: usize) -> bool
Enable bit
, and return its previous value.
Panics if bit is out of bounds.
sourcepub fn copy_bit(&mut self, from: usize, to: usize)
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.
sourcepub fn count_ones<T: IndexRange>(&self, range: T) -> usize
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.
sourcepub fn set_range<T: IndexRange>(&mut self, range: T, enabled: bool)
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.
sourcepub fn insert_range<T: IndexRange>(&mut self, range: T)
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.
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.
sourcepub fn ones(&self) -> Ones<'_> ⓘ
pub fn ones(&self) -> Ones<'_> ⓘ
Iterates over all enabled bits.
Iterator element is the index of the 1
bit, type usize
.
sourcepub fn intersection<'a>(&'a self, other: &'a FixedBitSet) -> Intersection<'a> ⓘ
pub fn intersection<'a>(&'a self, other: &'a FixedBitSet) -> Intersection<'a> ⓘ
Returns a lazy iterator over the intersection of two FixedBitSet
s
sourcepub fn union<'a>(&'a self, other: &'a FixedBitSet) -> Union<'a> ⓘ
pub fn union<'a>(&'a self, other: &'a FixedBitSet) -> Union<'a> ⓘ
Returns a lazy iterator over the union of two FixedBitSet
s.
sourcepub fn difference<'a>(&'a self, other: &'a FixedBitSet) -> Difference<'a> ⓘ
pub fn difference<'a>(&'a self, other: &'a FixedBitSet) -> Difference<'a> ⓘ
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
.
Trait Implementations§
source§impl<'a> BitAnd for &'a FixedBitSet
impl<'a> BitAnd for &'a FixedBitSet
source§type Output = FixedBitSet
type Output = FixedBitSet
&
operator.source§fn bitand(self, other: &FixedBitSet) -> FixedBitSet
fn bitand(self, other: &FixedBitSet) -> FixedBitSet
&
operation. Read moresource§impl<'a> BitOr for &'a FixedBitSet
impl<'a> BitOr for &'a FixedBitSet
source§type Output = FixedBitSet
type Output = FixedBitSet
|
operator.source§fn bitor(self, other: &FixedBitSet) -> FixedBitSet
fn bitor(self, other: &FixedBitSet) -> FixedBitSet
|
operation. Read moresource§impl Clone for FixedBitSet
impl Clone for FixedBitSet
source§impl Debug for FixedBitSet
impl Debug for FixedBitSet
source§impl Default for FixedBitSet
impl Default for FixedBitSet
source§fn default() -> FixedBitSet
fn default() -> FixedBitSet
source§impl Extend<usize> for FixedBitSet
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)
fn extend<I: IntoIterator<Item = usize>>(&mut self, src: I)
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 FromIterator<usize> for FixedBitSet
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§impl Hash for FixedBitSet
impl Hash for FixedBitSet
source§impl Index<usize> for FixedBitSet
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§impl Ord for FixedBitSet
impl Ord for FixedBitSet
source§fn cmp(&self, other: &FixedBitSet) -> Ordering
fn cmp(&self, other: &FixedBitSet) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl PartialEq for FixedBitSet
impl PartialEq for FixedBitSet
source§impl PartialOrd for FixedBitSet
impl PartialOrd for FixedBitSet
impl Eq for FixedBitSet
impl StructuralPartialEq for FixedBitSet
Auto Trait Implementations§
impl Freeze for FixedBitSet
impl RefUnwindSafe for FixedBitSet
impl Send for FixedBitSet
impl Sync for FixedBitSet
impl Unpin for FixedBitSet
impl UnwindSafe for FixedBitSet
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)