Variable block size.
This commit is contained in:
31
src/block.rs
Normal file
31
src/block.rs
Normal 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)
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user