pub struct BitSet { /* private fields */ }
Implementations§
Source§impl BitSet
impl BitSet
Sourcepub fn with_capacity(nbits: usize) -> Self
pub fn with_capacity(nbits: usize) -> Self
Sourcepub fn from_vec64(vec: &Vec<u64>) -> Self
pub fn from_vec64(vec: &Vec<u64>) -> Self
Sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
Return the actual bits count.
§Example
use bitset::BitSet;
let bs = BitSet::with_capacity(100);
assert!(bs.size() == 100);
Sourcepub fn count(&self) -> u64
pub fn count(&self) -> u64
Return the count of 1
.
§Example
use bitset::BitSet;
let bs = BitSet::with_capacity(100);
assert!(bs.count() == 0);
Sourcepub fn test(&self, bit_idx: usize) -> bool
pub fn test(&self, bit_idx: usize) -> bool
Return if the given bit index has been set to 1
.
§Example
use bitset::BitSet;
let bs = BitSet::with_capacity(100);
assert!(bs.test(99) == false);
Sourcepub fn any(&self) -> bool
pub fn any(&self) -> bool
Return if there is one bit has been set to 1
in the whole bitset..
§Example
use bitset::BitSet;
let bs = BitSet::with_capacity(100);
assert!(bs.any() == false);
Sourcepub fn none(&self) -> bool
pub fn none(&self) -> bool
Return if all bits are set to 0
.
§Example
use bitset::BitSet;
let bs = BitSet::with_capacity(100);
assert!(bs.none() == true);
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset all bits to 0
.
§Example
use bitset::BitSet;
let mut bs = BitSet::with_capacity(100);
bs.set(99, true);
assert!(bs.test(99) == true);
bs.reset();
assert!(bs.test(99) == false);
Sourcepub fn flip(&mut self, bit_idx: usize)
pub fn flip(&mut self, bit_idx: usize)
Flip the bit specified by bit_idx
to the reverse value.
If the bit value is true
, then it will be flipped to false
.
The other case is like the same.
§Arguments
bit_idx
- the index of the bit we want to flip.
§Example
use bitset::BitSet;
let mut bs = BitSet::with_capacity(100);
assert!(bs.test(99) == false);
bs.flip(99);
assert!(bs.test(99) == true);
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BitSet
impl RefUnwindSafe for BitSet
impl Send for BitSet
impl Sync for BitSet
impl Unpin for BitSet
impl UnwindSafe for BitSet
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
Mutably borrows from an owned value. Read more