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> {
const ZERO: Self;
const ONE: Self;
const BITS: usize;
fn bits() -> usize;
fn count_ones(self) -> usize;
fn block<B>(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<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]
fn bit<B>(value: B) -> Self where B: Block { Self::from(B::biter::<Self>(value)) }
#[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!{
(u8, 8),
(u16, 16),
(u32, 32),
(u64, 64),
(usize, mem::size_of::<usize>() * 8)
u8,
u16,
u32,
u64,
usize
}

View File

@@ -51,7 +51,7 @@ where
pub fn with_capacity(capacity: usize) -> BitSet<B> {
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) {