Files
bit-set/src/block.rs
2018-01-06 22:05:08 +01:00

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