From acbd9779416e3a72e86de6ecb80dada6b3897050 Mon Sep 17 00:00:00 2001 From: Anders Olsson Date: Mon, 10 Sep 2018 21:02:03 +0200 Subject: [PATCH] Did something. --- src/block.rs | 22 ++++++++++------------ src/lib.rs | 6 +++--- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/block.rs b/src/block.rs index 3101cf8..ac3548e 100644 --- a/src/block.rs +++ b/src/block.rs @@ -39,8 +39,8 @@ pub trait Block + Not { const ZERO: Self; const ONE: Self; + const BITS: usize; - fn bits() -> usize; fn count_ones(self) -> usize; fn block(value: Self) -> Self @@ -56,33 +56,31 @@ pub trait Block } macro_rules! block_impl { - ($(($t: ty, $size: expr)),*) => ($( + ($($t: ty),*) => ($( impl Block for $t { const ZERO: Self = 0; const ONE: Self = 1; - - #[inline] - fn bits() -> usize { $size } + const BITS: usize = mem::size_of::<$t>() * 8; #[inline] fn count_ones(self) -> usize { self.count_ones() as usize } #[inline] - fn block(value: Self) -> Self where B: Block { value / B::bits() as Self } + fn block(value: Self) -> Self where B: Block { value / B::BITS as Self } #[inline] fn bit(value: B) -> Self where B: Block { Self::from(B::biter::(value)) } #[inline] - fn biter(value: Self) -> u8 where B: Block { (value % B::bits() as Self) as u8 } + fn biter(value: Self) -> u8 where B: Block { (value % B::BITS as Self) as u8 } } )*) } block_impl!{ - (u8, 8), - (u16, 16), - (u32, 32), - (u64, 64), - (usize, mem::size_of::() * 8) + u8, + u16, + u32, + u64, + usize } diff --git a/src/lib.rs b/src/lib.rs index 0b1d2fd..aa93f09 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -51,7 +51,7 @@ where pub fn with_capacity(capacity: usize) -> BitSet { BitSet { blocks: HashMap::with_capacity_and_hasher( - capacity / B::bits() as usize, + capacity / B::BITS as usize, Default::default(), ), nbits: 0, @@ -60,11 +60,11 @@ where #[inline] pub fn capacity(&self) -> usize { - self.blocks.capacity() * B::bits() as usize + self.blocks.capacity() * B::BITS as usize } pub fn reserve(&mut self, additional: usize) { - self.blocks.reserve(additional / B::bits() as usize) + self.blocks.reserve(additional / B::BITS as usize) } pub fn shrink_to_fit(&mut self) {