pub struct BitArray { /* private fields */ }
Implementations§
Source§impl BitArray
impl BitArray
Sourcepub fn first_unset_bit(&self) -> Option<usize>
pub fn first_unset_bit(&self) -> Option<usize>
Finds the first bit that is not set in the array.
§Returns
- The index of the first unset bit, or
None
if all bits are set.
Sourcepub fn first_set_bit(&self) -> Option<usize>
pub fn first_set_bit(&self) -> Option<usize>
Finds the first bit that is set in the array.
§Returns
- The index of the first set bit, or
None
if no bits are set.
Sourcepub const fn count_set_bits(&self) -> usize
pub const fn count_set_bits(&self) -> usize
Returns the number of bits that are currently set to 1
.
§Returns
The number of bits that are set in the BitArray
.
Sourcepub const fn bit_count(&self) -> usize
pub const fn bit_count(&self) -> usize
Returns the total number of bits in the BitArray
.
§Returns
The total number of bits in the BitArray
.
Sourcepub fn atom_from_index(&self, from_index: usize) -> u64
pub fn atom_from_index(&self, from_index: usize) -> u64
Trait Implementations§
Source§impl Debug for BitArray
impl Debug for BitArray
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the BitArray
as a binary string with groups of 8 bits separated by a space.
§Arguments
f
- The formatter used to output the debug string.
§Returns
A Result
indicating whether the formatting was successful.
§Example
use bit_array_rs::BitArray;
let mut bit_array = BitArray::new(16);
bit_array.set(3);
bit_array.set(7);
bit_array.set(9);
bit_array.set(15);
assert_eq!(format!("{:?}", bit_array), "00010001 01000001");
Source§impl Display for BitArray
impl Display for BitArray
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the BitArray
as a continuous binary string without any spaces.
§Arguments
f
- The formatter used to output the display string.
§Returns
A Result
indicating whether the formatting was successful.
§Example
use bit_array_rs::BitArray;
let mut bit_array = BitArray::new(16);
bit_array.set(3);
bit_array.set(7);
bit_array.set(9);
bit_array.set(15);
assert_eq!(format!("{}", bit_array), "0001000101000001");
Source§impl Index<usize> for BitArray
impl Index<usize> for BitArray
Source§fn index(&self, index: usize) -> &Self::Output
fn index(&self, index: usize) -> &Self::Output
Provides indexed access to individual bits in the BitArray
.
§Arguments
index
- The zero-based index of the bit to access.
§Returns
A reference to a boolean value (true
or false
) representing the state of the bit
at the specified index.
§Panics
This function will panic if the index
is out of bounds.
§Example
use bit_array_rs::BitArray;
let mut bit_array = BitArray::new(16);
bit_array.set(3);
assert_eq!(bit_array[3], true);
assert_eq!(bit_array[0], false);