use alloc::vec::Vec;
use core::ops::Index;
pub trait BitAccess {
fn get_bit(&self, index: u64) -> bool;
fn set_bit(&mut self, index: u64);
fn clear_bit(&mut self, index: u64);
#[inline]
fn assign_bit(&mut self, index: u64, bit: bool) {
if bit {
self.set_bit(index);
} else {
self.clear_bit(index);
}
}
#[inline]
fn flip_bit(&mut self, index: u64) {
if self.get_bit(index) {
self.clear_bit(index);
} else {
self.set_bit(index);
}
}
}
pub trait BitBlockAccess: Sized {
type Bits;
fn get_bits(&self, start: u64, end: u64) -> Self::Bits;
#[inline]
fn get_bits_owned(self, start: u64, end: u64) -> Self::Bits {
self.get_bits(start, end)
}
fn assign_bits(&mut self, start: u64, end: u64, bits: &Self::Bits);
}
pub trait BitConvertible {
fn to_bits_asc(&self) -> Vec<bool>;
fn to_bits_desc(&self) -> Vec<bool>;
fn from_bits_asc<I: Iterator<Item = bool>>(bits: I) -> Self;
fn from_bits_desc<I: Iterator<Item = bool>>(bits: I) -> Self;
}
pub trait BitIterable {
type BitIterator: DoubleEndedIterator<Item = bool> + Index<u64>;
fn bits(self) -> Self::BitIterator;
}
pub trait BitScan {
fn index_of_next_false_bit(self, start: u64) -> Option<u64>;
fn index_of_next_true_bit(self, start: u64) -> Option<u64>;
}
pub trait CountOnes {
fn count_ones(self) -> u64;
}
pub trait CountZeros {
fn count_zeros(self) -> u64;
}
pub trait HammingDistance<RHS = Self> {
fn hamming_distance(self, other: RHS) -> u64;
}
pub trait CheckedHammingDistance<RHS = Self> {
fn checked_hamming_distance(self, other: RHS) -> Option<u64>;
}
pub trait LeadingZeros {
fn leading_zeros(self) -> u64;
}
pub trait LowMask {
fn low_mask(bits: u64) -> Self;
}
pub trait NotAssign {
fn not_assign(&mut self);
}
pub trait SignificantBits {
fn significant_bits(self) -> u64;
}
pub trait TrailingZeros {
fn trailing_zeros(self) -> u64;
}