bitstring/utils/bigendian/traits.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
/// Generic helper methods to treat unsigned integer and slices of them as big endian bit strings.
#[allow(dead_code)]
pub trait BigEndianBitString {
/// maximum number of bits in storage
fn bits(&self) -> usize;
/// increment from right; don't touch first `prefix` bits; returns
/// true on overflow
///
/// # Panics
///
/// Panics if `prefix > self.bits()`.
fn bits_inc(&mut self, prefix: usize) -> bool;
/// Get the `ndx`th bit.
///
/// # Panics
///
/// Panics if `ndx >= Self::ELEMENT_BITS() * slice.len()`.
fn bit_get(&self, ndx: usize) -> bool;
/// Set the `ndx`th bit to `bit`.
///
/// # Panics
///
/// Panics if `ndx >= Self::ELEMENT_BITS() * slice.len()`.
fn bit_set(&mut self, ndx: usize, bit: bool);
/// Flips the `ndx`th bit.
///
/// # Panics
///
/// Panics if `ndx >= Self::ELEMENT_BITS() * slice.len()`.
fn bit_flip(&mut self, ndx: usize);
/// Length of the longest shared prefix of two bit strings.
fn shared_prefix_len(&self, other: &Self, max_len: usize) -> usize;
/// Set all bits from [ndx..] to `false` (`0`).
///
/// Doesn't do anything if `ndx >= Self::ELEMENT_BITS() * slice.len()`.
fn set_false_from(&mut self, ndx: usize);
/// Whether all bits from [ndx..] are `false` (`0`).
///
/// Returns `true` if `ndx >= Self::ELEMENT_BITS() * slice.len()`.
fn is_false_from(&self, ndx: usize) -> bool;
/// Set all bits from [ndx..] to `true` (`1`).
///
/// Doesn't do anything if `ndx >= Self::ELEMENT_BITS() * slice.len()`.
fn set_true_from(&mut self, ndx: usize);
/// Whether all bits from [ndx..] are `true` (`1`).
///
/// Returns `true` if `ndx >= Self::ELEMENT_BITS() * slice.len()`.
fn is_true_from(&self, ndx: usize) -> bool;
/// check whether another bit string `value` shares the first
/// `prefix_len` bits with `self`
fn bits_prefix_of(&self, prefix_len: usize, value: &Self) -> bool;
}