32 lines
606 B
Rust
32 lines
606 B
Rust
use std::mem;
|
|
|
|
pub trait BitBlock {
|
|
const ONE: Self;
|
|
const ZERO: Self;
|
|
|
|
fn bits() -> usize;
|
|
fn count_ones(self) -> usize;
|
|
}
|
|
|
|
macro_rules! bit_block_impl {
|
|
($(($t: ty, $size: expr)),*) => ($(
|
|
impl BitBlock for $t {
|
|
const ONE: Self = 1;
|
|
const ZERO: Self = 1;
|
|
|
|
#[inline]
|
|
fn bits() -> usize { $size }
|
|
#[inline]
|
|
fn count_ones(self) -> usize { self.count_ones() as usize }
|
|
}
|
|
)*)
|
|
}
|
|
|
|
bit_block_impl!{
|
|
(u8, 8),
|
|
(u16, 16),
|
|
(u32, 32),
|
|
(u64, 64),
|
|
(usize, mem::size_of::<usize>() * 8)
|
|
}
|