pub trait BitAccess {
Show 37 methods
// Required methods
fn get_bit(&self, bit_nr: usize) -> bool;
fn set_bit(&mut self, bit_nr: usize);
fn clear_bit(&mut self, bit_nr: usize);
fn get_bits(&self, begin: usize, len: u8) -> u64;
fn set_bits(&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 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_bit_to(&mut self, bit_nr: usize, value: bool) { ... }
fn set_successive_bit_to(&mut self, bit_nr: &mut usize, value: bool) { ... }
fn init_bit(&mut self, bit_nr: usize, value: bool) { ... }
fn init_successive_bit(&mut self, bit_nr: &mut usize, value: bool) { ... }
fn get_successive_bits(&self, begin: &mut usize, len: u8) -> u64 { ... }
fn init_bits(&mut self, begin: usize, v: u64, len: u8) { ... }
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(&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
) { ... }
fn set_fragment(&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 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.
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.
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 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.
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).
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.
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.
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.
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_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.
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.
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.
sourcefn get_fragment(&self, index: usize, v_size: u8) -> u64
fn get_fragment(&self, index: usize, v_size: u8) -> u64
Gets v_size bits with indices in range [index*v_size, index*v_size+v_size).
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 v_size bits with indices in range [index*v_size, index*v_size+v_size) and increase 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)
Inits v_size bits with indices in range [index*v_size, index*v_size+v_size) to v.
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)
Inits v_size bits with indices in range [index*v_size, index*v_size+v_size) to v
and increase index by 1.
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 v_size bits with indices in range [index*v_size, index*v_size+v_size) to v.
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 v_size bits with indices in range [index*v_size, index*v_size+v_size) to v and increase index by 1.
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.
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.
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.