Trait bitm::BitAccess

source ·
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§

source

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

Gets bit with given index bit_nr.

source

fn set_bit(&mut self, bit_nr: usize)

Sets bit with given index bit_nr to 1.

source

fn clear_bit(&mut self, bit_nr: usize)

Sets bit with given index bit_nr to 0.

source

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

Gets bits [begin, begin+len).

source

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

Sets bits [begin, begin+len) to the content of v.

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.

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

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

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.

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.

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.

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_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

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.

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.

source

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

source

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.

source

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.

source

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.

source

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.

source

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.

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.

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.

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.

Object Safety§

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(&mut self, bit_nr: usize)

source§

fn clear_bit(&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 get_bits(&self, begin: usize, len: u8) -> u64

source§

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

source§

fn set_bits(&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§