pub trait BitAccess {
Show 62 methods
// Required methods
fn get_bit(&self, bit_nr: usize) -> bool;
unsafe fn get_bit_unchecked(&self, bit_nr: usize) -> bool;
fn try_get_bit(&self, bit_nr: usize) -> Option<bool>;
fn set_bit_to(&mut self, bit_nr: usize, value: bool);
unsafe fn set_bit_to_unchecked(&mut self, bit_nr: usize, value: bool);
fn init_bit(&mut self, bit_nr: usize, value: bool);
unsafe fn init_bit_unchecked(&mut self, bit_nr: usize, value: bool);
fn set_bit(&mut self, bit_nr: usize);
unsafe fn set_bit_unchecked(&mut self, bit_nr: usize);
fn clear_bit(&mut self, bit_nr: usize);
unsafe fn clear_bit_unchecked(&mut self, bit_nr: usize);
fn try_get_bits_unmasked(&self, begin: usize, len: u8) -> Option<u64>;
unsafe fn get_bits_unmasked_unchecked(&self, begin: usize, len: u8) -> u64;
fn init_bits(&mut self, begin: usize, v: u64, len: u8);
unsafe fn init_bits_unchecked(&mut self, begin: usize, v: u64, len: u8);
fn set_bits(&mut self, begin: usize, v: u64, len: u8);
unsafe fn set_bits_unchecked(&mut self, begin: usize, v: u64, len: u8);
fn xor_bits(&mut self, begin: usize, v: u64, len: u8);
fn count_bit_zeros(&self) -> usize;
fn count_bit_ones(&self) -> usize;
fn bit_ones(&self) -> BitOnesIterator<'_>;
fn bit_zeros(&self) -> BitZerosIterator<'_>;
fn bit_iter(&self) -> BitIterator<'_> ⓘ;
fn bit_in_range_iter(&self, bit_range: Range<usize>) -> BitIterator<'_> ⓘ;
unsafe fn bit_in_unchecked_range_iter(
&self,
bit_range: Range<usize>,
) -> BitIterator<'_> ⓘ;
fn trailing_zero_bits(&self) -> usize;
unsafe fn find_bit_one_unchecked(&self, start_index: usize) -> usize;
fn find_bit_one(&self, start_index: usize) -> Option<usize>;
unsafe fn rfind_bit_one_unchecked(&self, start_index: usize) -> usize;
// Provided methods
fn get_successive_bit(&self, bit_nr: &mut usize) -> bool { ... }
fn set_successive_bit_to(&mut self, bit_nr: &mut usize, value: bool) { ... }
unsafe fn set_successive_bit_to_unchecked(
&mut self,
bit_nr: &mut usize,
value: bool,
) { ... }
fn init_successive_bit(&mut self, bit_nr: &mut usize, value: bool) { ... }
unsafe fn init_successive_bit_unchecked(
&mut self,
bit_nr: &mut usize,
value: bool,
) { ... }
fn get_bits_unmasked(&self, begin: usize, len: u8) -> u64 { ... }
fn get_bits(&self, begin: usize, len: u8) -> u64 { ... }
fn try_get_bits(&self, begin: usize, len: u8) -> Option<u64> { ... }
unsafe fn get_bits_unchecked(&self, begin: usize, len: u8) -> u64 { ... }
fn get_successive_bits(&self, begin: &mut usize, len: u8) -> u64 { ... }
fn init_successive_bits(&mut self, begin: &mut usize, v: u64, len: u8) { ... }
fn set_successive_bits(&mut self, begin: &mut usize, v: u64, len: u8) { ... }
fn xor_successive_bits(&mut self, begin: &mut usize, v: u64, len: u8) { ... }
fn get_fragment_unmasked(&self, index: usize, v_size: u8) -> u64 { ... }
fn get_fragment(&self, index: usize, v_size: u8) -> u64 { ... }
fn try_get_fragment_unmasked(&self, index: usize, v_size: u8) -> Option<u64> { ... }
fn try_get_fragment(&self, index: usize, v_size: u8) -> Option<u64> { ... }
unsafe fn get_fragment_unmasked_unchecked(
&self,
index: usize,
v_size: u8,
) -> u64 { ... }
unsafe fn get_fragment_unchecked(&self, index: usize, v_size: u8) -> u64 { ... }
fn get_successive_fragment(&self, index: &mut usize, v_size: u8) -> u64 { ... }
fn init_fragment(&mut self, index: usize, v: u64, v_size: u8) { ... }
fn init_successive_fragment(
&mut self,
index: &mut usize,
v: u64,
v_size: u8,
) { ... }
unsafe fn init_fragment_unchecked(
&mut self,
index: usize,
v: u64,
v_size: u8,
) { ... }
fn set_fragment(&mut self, index: usize, v: u64, v_size: u8) { ... }
unsafe fn set_fragment_unchecked(
&mut self,
index: usize,
v: u64,
v_size: u8,
) { ... }
fn set_successive_fragment(&mut self, index: &mut usize, v: u64, v_size: u8) { ... }
fn xor_fragment(&mut self, index: usize, v: u64, v_size: u8) { ... }
fn xor_successive_fragment(&mut self, index: &mut usize, v: u64, v_size: u8) { ... }
fn swap_fragments(&mut self, index1: usize, index2: usize, v_size: u8) { ... }
fn conditionally_change_bits<NewValue>(
&mut self,
new_value: NewValue,
begin: usize,
v_size: u8,
) -> u64
where NewValue: FnOnce(u64) -> Option<u64> { ... }
fn conditionally_change_fragment<NewValue>(
&mut self,
new_value: NewValue,
index: usize,
v_size: u8,
) -> u64
where NewValue: FnOnce(u64) -> Option<u64> { ... }
fn conditionally_copy_bits<Pred>(
&mut self,
src: &Self,
predicate: Pred,
begin: usize,
v_size: u8,
)
where Pred: FnOnce(u64, u64) -> bool { ... }
fn conditionally_copy_fragment<Pred>(
&mut self,
src: &Self,
predicate: Pred,
index: usize,
v_size: u8,
)
where Pred: FnOnce(u64, u64) -> bool { ... }
}Expand description
The trait that is implemented for the array of u64 and extends it with methods for
accessing and modifying single bits or arbitrary fragments consisted of few (up to 63) bits.
Required Methods§
Sourcefn get_bit(&self, bit_nr: usize) -> bool
fn get_bit(&self, bit_nr: usize) -> bool
Gets bit with given index bit_nr. Panics if bit_nr is out of bounds.
Sourceunsafe fn get_bit_unchecked(&self, bit_nr: usize) -> bool
unsafe fn get_bit_unchecked(&self, bit_nr: usize) -> bool
Gets bit with given index bit_nr, without bounds checking.
Sourcefn try_get_bit(&self, bit_nr: usize) -> Option<bool>
fn try_get_bit(&self, bit_nr: usize) -> Option<bool>
Gets bit with given index bit_nr. Returns None if bit_nr is out of bounds.
Sourcefn set_bit_to(&mut self, bit_nr: usize, value: bool)
fn set_bit_to(&mut self, bit_nr: usize, value: bool)
Set bit with given index bit_nr to value (1 if true, 0 otherwise). Panics if bit_nr is out of bounds.
Sourceunsafe fn set_bit_to_unchecked(&mut self, bit_nr: usize, value: bool)
unsafe fn set_bit_to_unchecked(&mut self, bit_nr: usize, value: bool)
Set bit with given index bit_nr to value (1 if true, 0 otherwise), without bounds checking.
Sourcefn init_bit(&mut self, bit_nr: usize, value: bool)
fn init_bit(&mut self, bit_nr: usize, value: bool)
Initialize bit with given index bit_nr to value (1 if true, 0 otherwise).
Before initialization, the bit is assumed to be cleared or already set to value.
Panics if bit_nr is out of bounds.
Sourceunsafe fn init_bit_unchecked(&mut self, bit_nr: usize, value: bool)
unsafe fn init_bit_unchecked(&mut self, bit_nr: usize, value: bool)
Initialize bit with given index bit_nr to value (1 if true, 0 otherwise).
Before initialization, the bit is assumed to be cleared or already set to value.
The result is undefined if bit_nr is out of bounds.
Sourcefn set_bit(&mut self, bit_nr: usize)
fn set_bit(&mut self, bit_nr: usize)
Sets bit with given index bit_nr to 1. Panics if bit_nr is out of bounds.
Sourceunsafe fn set_bit_unchecked(&mut self, bit_nr: usize)
unsafe fn set_bit_unchecked(&mut self, bit_nr: usize)
Sets bit with given index bit_nr to 1, without bounds checking.
Sourcefn clear_bit(&mut self, bit_nr: usize)
fn clear_bit(&mut self, bit_nr: usize)
Sets bit with given index bit_nr to 0. Panics if bit_nr is out of bounds.
Sourceunsafe fn clear_bit_unchecked(&mut self, bit_nr: usize)
unsafe fn clear_bit_unchecked(&mut self, bit_nr: usize)
Sets bit with given index bit_nr to 0, without bounds checking.
Sourcefn try_get_bits_unmasked(&self, begin: usize, len: u8) -> Option<u64>
fn try_get_bits_unmasked(&self, begin: usize, len: u8) -> Option<u64>
Gets at least len bits beginning from the bit index begin.
Returns None if the range is out of bounds.
Sourceunsafe fn get_bits_unmasked_unchecked(&self, begin: usize, len: u8) -> u64
unsafe fn get_bits_unmasked_unchecked(&self, begin: usize, len: u8) -> u64
Gets at least len bits beginning from the bit index begin without bounds checking.
Sourcefn init_bits(&mut self, begin: usize, v: u64, len: u8)
fn init_bits(&mut self, begin: usize, v: u64, len: u8)
Initialize bits [begin, begin+len) to v.
Before initialization, the bits are assumed to be cleared or already set to v.
Sourceunsafe fn init_bits_unchecked(&mut self, begin: usize, v: u64, len: u8)
unsafe fn init_bits_unchecked(&mut self, begin: usize, v: u64, len: u8)
Initialize bits [begin, begin+len) to v, without bounds checking.
Before initialization, the bits are assumed to be cleared or already set to v.
Sourcefn set_bits(&mut self, begin: usize, v: u64, len: u8)
fn set_bits(&mut self, begin: usize, v: u64, len: u8)
Sets bits [begin, begin+len) to the content of v. Panics if the range is out of bounds.
Sourceunsafe fn set_bits_unchecked(&mut self, begin: usize, v: u64, len: u8)
unsafe fn set_bits_unchecked(&mut self, begin: usize, v: u64, len: u8)
Sets bits [begin, begin+len) to the content of v, without bounds checking.
Sourcefn xor_bits(&mut self, begin: usize, v: u64, len: u8)
fn xor_bits(&mut self, begin: usize, v: u64, len: u8)
Xor at least len bits of self, staring from index begin, with v. Panics if the range is out of bounds.
Sourcefn count_bit_zeros(&self) -> usize
fn count_bit_zeros(&self) -> usize
Returns the number of zeros (cleared bits).
Sourcefn count_bit_ones(&self) -> usize
fn count_bit_ones(&self) -> usize
Returns the number of ones (set bits).
Sourcefn bit_ones(&self) -> BitOnesIterator<'_>
fn bit_ones(&self) -> BitOnesIterator<'_>
Returns iterator over indices of ones (set bits).
Sourcefn bit_zeros(&self) -> BitZerosIterator<'_>
fn bit_zeros(&self) -> BitZerosIterator<'_>
Returns iterator over indices of ones (set bits).
Sourcefn bit_iter(&self) -> BitIterator<'_> ⓘ
fn bit_iter(&self) -> BitIterator<'_> ⓘ
Returns iterator over all bits in self that yields true for each one and false for each zero.
Sourcefn bit_in_range_iter(&self, bit_range: Range<usize>) -> BitIterator<'_> ⓘ
fn bit_in_range_iter(&self, bit_range: Range<usize>) -> BitIterator<'_> ⓘ
Returns iterator over given range of self bits that yields true for each one and false for each zero.
Sourceunsafe fn bit_in_unchecked_range_iter(
&self,
bit_range: Range<usize>,
) -> BitIterator<'_> ⓘ
unsafe fn bit_in_unchecked_range_iter( &self, bit_range: Range<usize>, ) -> BitIterator<'_> ⓘ
Returns iterator over given range (whose bounds are unchecked) of self bits
that yields true for each one and false for each zero.
Sourcefn trailing_zero_bits(&self) -> usize
fn trailing_zero_bits(&self) -> usize
Returns the number of trailing 0 bits.
Sourceunsafe fn find_bit_one_unchecked(&self, start_index: usize) -> usize
unsafe fn find_bit_one_unchecked(&self, start_index: usize) -> usize
Returns the lowest index of 1-bit that is grater or equal to start_index.
The result is undefined if there is no such index.
Sourcefn find_bit_one(&self, start_index: usize) -> Option<usize>
fn find_bit_one(&self, start_index: usize) -> Option<usize>
Returns the lowest index of 1-bit that is grater or equal to start_index.
Retruns None if there is no such index.
Sourceunsafe fn rfind_bit_one_unchecked(&self, start_index: usize) -> usize
unsafe fn rfind_bit_one_unchecked(&self, start_index: usize) -> usize
Returns the greatest index of 1-bit that is lower or equal to start_index.
The result is undefined if there is no such index.
Provided Methods§
Sourcefn get_successive_bit(&self, bit_nr: &mut usize) -> bool
fn get_successive_bit(&self, bit_nr: &mut usize) -> bool
Gets bit with given index bit_nr and increase bit_nr by 1. Panics if bit_nr is out of bounds.
Sourcefn set_successive_bit_to(&mut self, bit_nr: &mut usize, value: bool)
fn set_successive_bit_to(&mut self, bit_nr: &mut usize, value: bool)
Set bit with given index bit_nr to value (1 if true, 0 otherwise) and increase bit_nr by 1.
Panics if bit_nr is out of bound.
Sourceunsafe fn set_successive_bit_to_unchecked(
&mut self,
bit_nr: &mut usize,
value: bool,
)
unsafe fn set_successive_bit_to_unchecked( &mut self, bit_nr: &mut usize, value: bool, )
Set bit with given index bit_nr to value (1 if true, 0 otherwise) and increase bit_nr by 1.
The result is undefined if bit_nr is out of bound.
Sourcefn init_successive_bit(&mut self, bit_nr: &mut usize, value: bool)
fn init_successive_bit(&mut self, bit_nr: &mut usize, value: bool)
Initialize bit with given index bit_nr to value (1 if true, 0 otherwise)
and increase bit_nr by 1.
Before initialization, the bit is assumed to be cleared or already set to value.
Panics if bit_nr is out of bounds.
Sourceunsafe fn init_successive_bit_unchecked(
&mut self,
bit_nr: &mut usize,
value: bool,
)
unsafe fn init_successive_bit_unchecked( &mut self, bit_nr: &mut usize, value: bool, )
Initialize bit with given index bit_nr to value (1 if true, 0 otherwise)
and increase bit_nr by 1.
Before initialization, the bit is assumed to be cleared or already set to value.
The result is undefined if bit_nr is out of bounds.
Sourcefn get_bits_unmasked(&self, begin: usize, len: u8) -> u64
fn get_bits_unmasked(&self, begin: usize, len: u8) -> u64
Gets at least len bits beginning from the bit index begin. Panics if the range is out of bounds.
Sourcefn get_bits(&self, begin: usize, len: u8) -> u64
fn get_bits(&self, begin: usize, len: u8) -> u64
Gets bits [begin, begin+len). Panics if the range is out of bounds.
Sourcefn try_get_bits(&self, begin: usize, len: u8) -> Option<u64>
fn try_get_bits(&self, begin: usize, len: u8) -> Option<u64>
Gets bits [begin, begin+len). Returns None if the range is out of bounds.
Sourceunsafe fn get_bits_unchecked(&self, begin: usize, len: u8) -> u64
unsafe fn get_bits_unchecked(&self, begin: usize, len: u8) -> u64
Gets bits [begin, begin+len) without bounds checking.
Sourcefn get_successive_bits(&self, begin: &mut usize, len: u8) -> u64
fn get_successive_bits(&self, begin: &mut usize, len: u8) -> u64
Gets bits [begin, begin+len) and increase bit_nr by len.
Sourcefn init_successive_bits(&mut self, begin: &mut usize, v: u64, len: u8)
fn init_successive_bits(&mut self, begin: &mut usize, v: u64, len: u8)
Initialize bits [begin, begin+len) to v and increase begin by len.
Before initialization, the bits are assumed to be cleared or already set to v.
Sourcefn set_successive_bits(&mut self, begin: &mut usize, v: u64, len: u8)
fn set_successive_bits(&mut self, begin: &mut usize, v: u64, len: u8)
Sets bits [begin, begin+len) to the content of v and increase begin by len. Panics if the range is out of bounds.
Sourcefn xor_successive_bits(&mut self, begin: &mut usize, v: u64, len: u8)
fn xor_successive_bits(&mut self, begin: &mut usize, v: u64, len: u8)
Xor at least len bits of self, staring from index begin, with v and increase begin by len.
Panics if the range is out of bounds.
Sourcefn get_fragment_unmasked(&self, index: usize, v_size: u8) -> u64
fn get_fragment_unmasked(&self, index: usize, v_size: u8) -> u64
Gets index-th fragment of at least v_size bits, i.e. bits with indices in range [index*v_size, index*v_size+v_size).
Panics if the range is out of bounds.
Sourcefn get_fragment(&self, index: usize, v_size: u8) -> u64
fn get_fragment(&self, index: usize, v_size: u8) -> u64
Gets index-th fragment of v_size bits, i.e. bits with indices in range [index*v_size, index*v_size+v_size).
Panics if the range is out of bounds.
Sourcefn try_get_fragment_unmasked(&self, index: usize, v_size: u8) -> Option<u64>
fn try_get_fragment_unmasked(&self, index: usize, v_size: u8) -> Option<u64>
Gets index-th fragment of at least v_size bits, i.e. bits with indices in range [index*v_size, index*v_size+v_size).
Returns None if the range is out of bounds.
Sourcefn try_get_fragment(&self, index: usize, v_size: u8) -> Option<u64>
fn try_get_fragment(&self, index: usize, v_size: u8) -> Option<u64>
Gets index-th fragment of v_size bits, i.e. bits with indices in range [index*v_size, index*v_size+v_size).
Returns None if the range is out of bounds.
Sourceunsafe fn get_fragment_unmasked_unchecked(
&self,
index: usize,
v_size: u8,
) -> u64
unsafe fn get_fragment_unmasked_unchecked( &self, index: usize, v_size: u8, ) -> u64
Gets index-th fragment of at least v_size bits, i.e. bits with indices in range [index*v_size, index*v_size+v_size),
without bounds checking.
Sourceunsafe fn get_fragment_unchecked(&self, index: usize, v_size: u8) -> u64
unsafe fn get_fragment_unchecked(&self, index: usize, v_size: u8) -> u64
Gets index-th fragment of v_size bits, i.e. bits with indices in range [index*v_size, index*v_size+v_size),
without bounds checking.
Sourcefn get_successive_fragment(&self, index: &mut usize, v_size: u8) -> u64
fn get_successive_fragment(&self, index: &mut usize, v_size: u8) -> u64
Gets index-th fragment of v_size bits and increases index by 1.
Sourcefn init_fragment(&mut self, index: usize, v: u64, v_size: u8)
fn init_fragment(&mut self, index: usize, v: u64, v_size: u8)
Initializes index-th fragment of v_size bits, i.e. bits with indices in range [index*v_size, index*v_size+v_size), to v.
Panics if the range is out of bounds. Before initialization, the bits are assumed to be cleared or already set to v.
Sourcefn init_successive_fragment(&mut self, index: &mut usize, v: u64, v_size: u8)
fn init_successive_fragment(&mut self, index: &mut usize, v: u64, v_size: u8)
Initializes index-th fragment of v_size bits, i.e. bits with indices in range [index*v_size, index*v_size+v_size), to v
Next, increases index by 1. Panics if the range is out of bounds.
Before initialization, the bits are assumed to be cleared or already set to v.
Sourceunsafe fn init_fragment_unchecked(&mut self, index: usize, v: u64, v_size: u8)
unsafe fn init_fragment_unchecked(&mut self, index: usize, v: u64, v_size: u8)
Initializes index-th fragment of v_size bits, i.e. bits with indices in range [index*v_size, index*v_size+v_size), to v.
The result is undefined if the range is out of bounds. Before initialization, the bits are assumed to be cleared or already set to v.
Sourcefn set_fragment(&mut self, index: usize, v: u64, v_size: u8)
fn set_fragment(&mut self, index: usize, v: u64, v_size: u8)
Sets index-th fragment of v_size bits, i.e. bits with indices in range [indexv_size, indexv_size+v_size), to v`.
Panics if the range is out of bounds.
Sourceunsafe fn set_fragment_unchecked(&mut self, index: usize, v: u64, v_size: u8)
unsafe fn set_fragment_unchecked(&mut self, index: usize, v: u64, v_size: u8)
Sets index-th fragment of v_size bits, i.e. bits with indices in range [index*v_size, index*v_size+v_size), to v.
The result is undefined if the range is out of bounds.
Sourcefn set_successive_fragment(&mut self, index: &mut usize, v: u64, v_size: u8)
fn set_successive_fragment(&mut self, index: &mut usize, v: u64, v_size: u8)
Sets index-th fragment of v_size bits, i.e. bits with indices in range [indexv_size, indexv_size+v_size), to v. Next, increases index` by 1. Panics if the range is out of bounds.
Sourcefn xor_fragment(&mut self, index: usize, v: u64, v_size: u8)
fn xor_fragment(&mut self, index: usize, v: u64, v_size: u8)
Xor at least v_size bits of self begging from index*v_size with v. Panics if the range is out of bounds.
Sourcefn xor_successive_fragment(&mut self, index: &mut usize, v: u64, v_size: u8)
fn xor_successive_fragment(&mut self, index: &mut usize, v: u64, v_size: u8)
Xor at least v_size bits of self begging from index*v_size with v and increase index by 1.
Panics if the range is out of bounds.
Sourcefn swap_fragments(&mut self, index1: usize, index2: usize, v_size: u8)
fn swap_fragments(&mut self, index1: usize, index2: usize, v_size: u8)
Swaps ranges of bits: [index1*v_size, index1*v_size+v_size) with [index2*v_size, index2*v_size+v_size).
Sourcefn conditionally_change_bits<NewValue>(
&mut self,
new_value: NewValue,
begin: usize,
v_size: u8,
) -> u64
fn conditionally_change_bits<NewValue>( &mut self, new_value: NewValue, begin: usize, v_size: u8, ) -> u64
Conditionally (if new_value does not return None) changes
the value old stored at bits [begin, begin+v_size)
to the one returned by new_value (whose argument is old).
Returns old (the value before change).
Sourcefn conditionally_change_fragment<NewValue>(
&mut self,
new_value: NewValue,
index: usize,
v_size: u8,
) -> u64
fn conditionally_change_fragment<NewValue>( &mut self, new_value: NewValue, index: usize, v_size: u8, ) -> u64
Conditionally (if new_value does not return None) changes
the value old stored at bits [index*v_size, index*v_size+v_size)
to the one returned by new_value (whose argument is old).
Returns old (the value before change).
Sourcefn conditionally_copy_bits<Pred>(
&mut self,
src: &Self,
predicate: Pred,
begin: usize,
v_size: u8,
)
fn conditionally_copy_bits<Pred>( &mut self, src: &Self, predicate: Pred, begin: usize, v_size: u8, )
Conditionally (if predicate return true) replaces the bits
[begin, begin+v_size) of self by the bits [begin, begin+v_size) of src.
Subsequent predicate arguments are the bits [begin, begin+v_size) of:
self and src.
Sourcefn conditionally_copy_fragment<Pred>(
&mut self,
src: &Self,
predicate: Pred,
index: usize,
v_size: u8,
)
fn conditionally_copy_fragment<Pred>( &mut self, src: &Self, predicate: Pred, index: usize, v_size: u8, )
Conditionally (if predicate return true) replaces the bits
[index*v_size, index*v_size+v_size) of self
by the bits [index*v_size, index*v_size+v_size) of src.
Subsequent predicate arguments are the bits [index*v_size, index*v_size+v_size) of:
self and src.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.