Did something.

This commit is contained in:
2018-09-10 21:02:03 +02:00
parent 27eb6b2a2c
commit acbd977941
2 changed files with 13 additions and 15 deletions

View File

@@ -39,8 +39,8 @@ pub trait Block
+ Not<Output = Self> { + Not<Output = Self> {
const ZERO: Self; const ZERO: Self;
const ONE: Self; const ONE: Self;
const BITS: usize;
fn bits() -> usize;
fn count_ones(self) -> usize; fn count_ones(self) -> usize;
fn block<B>(value: Self) -> Self fn block<B>(value: Self) -> Self
@@ -56,33 +56,31 @@ pub trait Block
} }
macro_rules! block_impl { macro_rules! block_impl {
($(($t: ty, $size: expr)),*) => ($( ($($t: ty),*) => ($(
impl Block for $t { impl Block for $t {
const ZERO: Self = 0; const ZERO: Self = 0;
const ONE: Self = 1; const ONE: Self = 1;
const BITS: usize = mem::size_of::<$t>() * 8;
#[inline]
fn bits() -> usize { $size }
#[inline] #[inline]
fn count_ones(self) -> usize { self.count_ones() as usize } fn count_ones(self) -> usize { self.count_ones() as usize }
#[inline] #[inline]
fn block<B>(value: Self) -> Self where B: Block { value / B::bits() as Self } fn block<B>(value: Self) -> Self where B: Block { value / B::BITS as Self }
#[inline] #[inline]
fn bit<B>(value: B) -> Self where B: Block { Self::from(B::biter::<Self>(value)) } fn bit<B>(value: B) -> Self where B: Block { Self::from(B::biter::<Self>(value)) }
#[inline] #[inline]
fn biter<B>(value: Self) -> u8 where B: Block { (value % B::bits() as Self) as u8 } fn biter<B>(value: Self) -> u8 where B: Block { (value % B::BITS as Self) as u8 }
} }
)*) )*)
} }
block_impl!{ block_impl!{
(u8, 8), u8,
(u16, 16), u16,
(u32, 32), u32,
(u64, 64), u64,
(usize, mem::size_of::<usize>() * 8) usize
} }

View File

@@ -51,7 +51,7 @@ where
pub fn with_capacity(capacity: usize) -> BitSet<B> { pub fn with_capacity(capacity: usize) -> BitSet<B> {
BitSet { BitSet {
blocks: HashMap::with_capacity_and_hasher( blocks: HashMap::with_capacity_and_hasher(
capacity / B::bits() as usize, capacity / B::BITS as usize,
Default::default(), Default::default(),
), ),
nbits: 0, nbits: 0,
@@ -60,11 +60,11 @@ where
#[inline] #[inline]
pub fn capacity(&self) -> usize { 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) { 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) { pub fn shrink_to_fit(&mut self) {