Variable block size.

This commit is contained in:
2018-01-06 22:05:08 +01:00
parent 9dd8d400b3
commit d56f05c680
2 changed files with 32 additions and 0 deletions

31
src/block.rs Normal file
View File

@@ -0,0 +1,31 @@
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)
}

View File

@@ -12,6 +12,7 @@ use serde::ser::SerializeSeq;
use serde::de::{SeqAccess, Visitor}; use serde::de::{SeqAccess, Visitor};
mod hasher; mod hasher;
mod block;
use hasher::BitBuildHasher; use hasher::BitBuildHasher;