BitAccess

Trait BitAccess 

Source
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§

Source

fn get_bit(&self, bit_nr: usize) -> bool

Gets bit with given index bit_nr. Panics if bit_nr is out of bounds.

Source

unsafe fn get_bit_unchecked(&self, bit_nr: usize) -> bool

Gets bit with given index bit_nr, without bounds checking.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

unsafe fn set_bit_unchecked(&mut self, bit_nr: usize)

Sets bit with given index bit_nr to 1, without bounds checking.

Source

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.

Source

unsafe fn clear_bit_unchecked(&mut self, bit_nr: usize)

Sets bit with given index bit_nr to 0, without bounds checking.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

fn count_bit_zeros(&self) -> usize

Returns the number of zeros (cleared bits).

Source

fn count_bit_ones(&self) -> usize

Returns the number of ones (set bits).

Source

fn bit_ones(&self) -> BitOnesIterator<'_>

Returns iterator over indices of ones (set bits).

Source

fn bit_zeros(&self) -> BitZerosIterator<'_>

Returns iterator over indices of ones (set bits).

Source

fn bit_iter(&self) -> BitIterator<'_>

Returns iterator over all bits in self that yields true for each one and false for each zero.

Source

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.

Source

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.

Source

fn trailing_zero_bits(&self) -> usize

Returns the number of trailing 0 bits.

Source

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.

Source

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.

Source

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§

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

fn get_bits(&self, begin: usize, len: u8) -> u64

Gets bits [begin, begin+len). Panics if the range is out of bounds.

Source

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.

Source

unsafe fn get_bits_unchecked(&self, begin: usize, len: u8) -> u64

Gets bits [begin, begin+len) without bounds checking.

Source

fn get_successive_bits(&self, begin: &mut usize, len: u8) -> u64

Gets bits [begin, begin+len) and increase bit_nr by len.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Source

fn conditionally_change_bits<NewValue>( &mut self, new_value: NewValue, begin: usize, v_size: u8, ) -> u64
where NewValue: FnOnce(u64) -> Option<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).

Source

fn conditionally_change_fragment<NewValue>( &mut self, new_value: NewValue, index: usize, v_size: u8, ) -> u64
where NewValue: FnOnce(u64) -> Option<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).

Source

fn conditionally_copy_bits<Pred>( &mut self, src: &Self, predicate: Pred, begin: usize, v_size: u8, )
where Pred: FnOnce(u64, u64) -> bool,

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.

Source

fn conditionally_copy_fragment<Pred>( &mut self, src: &Self, predicate: Pred, index: usize, v_size: u8, )
where Pred: FnOnce(u64, u64) -> bool,

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.

Implementations on Foreign Types§

Source§

impl BitAccess for [u64]

Source§

fn get_bit(&self, bit_nr: usize) -> bool

Source§

fn set_bit_to(&mut self, bit_nr: usize, value: bool)

Source§

unsafe fn set_bit_to_unchecked(&mut self, bit_nr: usize, value: bool)

Source§

unsafe fn get_bit_unchecked(&self, bit_nr: usize) -> bool

Source§

fn try_get_bit(&self, bit_nr: usize) -> Option<bool>

Source§

fn init_bit(&mut self, bit_nr: usize, value: bool)

Source§

unsafe fn init_bit_unchecked(&mut self, bit_nr: usize, value: bool)

Source§

fn set_bit(&mut self, bit_nr: usize)

Source§

unsafe fn set_bit_unchecked(&mut self, bit_nr: usize)

Source§

fn clear_bit(&mut self, bit_nr: usize)

Source§

unsafe fn clear_bit_unchecked(&mut self, bit_nr: usize)

Source§

fn count_bit_zeros(&self) -> usize

Source§

fn count_bit_ones(&self) -> usize

Source§

fn bit_ones(&self) -> BitOnesIterator<'_>

Source§

fn bit_zeros(&self) -> BitZerosIterator<'_>

Source§

fn bit_iter(&self) -> BitIterator<'_>

Source§

fn bit_in_range_iter(&self, bit_range: Range<usize>) -> BitIterator<'_>

Source§

unsafe fn bit_in_unchecked_range_iter( &self, bit_range: Range<usize>, ) -> BitIterator<'_>

Source§

fn try_get_bits_unmasked(&self, begin: usize, len: u8) -> Option<u64>

Source§

unsafe fn get_bits_unmasked_unchecked(&self, begin: usize, len: u8) -> u64

Source§

fn init_bits(&mut self, begin: usize, v: u64, len: u8)

Source§

unsafe fn init_bits_unchecked(&mut self, begin: usize, v: u64, len: u8)

Source§

fn set_bits(&mut self, begin: usize, v: u64, len: u8)

Source§

unsafe fn set_bits_unchecked(&mut self, begin: usize, v: u64, len: u8)

Source§

fn xor_bits(&mut self, begin: usize, v: u64, len: u8)

Source§

fn conditionally_change_bits<NewValue>( &mut self, new_value: NewValue, begin: usize, v_size: u8, ) -> u64
where NewValue: FnOnce(u64) -> Option<u64>,

Source§

fn conditionally_copy_bits<Pred>( &mut self, src: &Self, predicate: Pred, begin: usize, v_size: u8, )
where Pred: FnOnce(u64, u64) -> bool,

Source§

fn trailing_zero_bits(&self) -> usize

Source§

fn find_bit_one(&self, start_index: usize) -> Option<usize>

Source§

unsafe fn find_bit_one_unchecked(&self, start_index: usize) -> usize

Source§

unsafe fn rfind_bit_one_unchecked(&self, start_index: usize) -> usize

Implementors§