Did stuff, stuff that doens't work.
This commit is contained in:
31
src/block.rs
31
src/block.rs
@@ -1,21 +1,40 @@
|
||||
use std::mem;
|
||||
use std::ops::*;
|
||||
use std::hash::Hash;
|
||||
use std::convert::From;
|
||||
|
||||
pub trait BitBlock {
|
||||
const ONE: Self;
|
||||
pub trait BitBlock
|
||||
: Copy
|
||||
+ Add<Self, Output = Self>
|
||||
+ Div<Self, Output = Self>
|
||||
+ From<u8>
|
||||
+ Sub<Self, Output = Self>
|
||||
+ Shl<usize, Output = Self>
|
||||
+ Shr<usize, Output = Self>
|
||||
+ Not<Output = Self>
|
||||
+ BitAnd<Self, Output = Self>
|
||||
+ BitOr<Self, Output = Self>
|
||||
+ BitXor<Self, Output = Self>
|
||||
+ Rem<Self, Output = Self>
|
||||
+ Eq
|
||||
+ Ord
|
||||
+ Hash {
|
||||
const ZERO: Self;
|
||||
const ONE: Self;
|
||||
|
||||
fn bits() -> usize;
|
||||
fn bits() -> u8;
|
||||
fn count_ones(self) -> usize;
|
||||
}
|
||||
|
||||
macro_rules! bit_block_impl {
|
||||
($(($t: ty, $size: expr)),*) => ($(
|
||||
impl BitBlock for $t {
|
||||
const ZERO: Self = 0;
|
||||
const ONE: Self = 1;
|
||||
const ZERO: Self = 1;
|
||||
|
||||
#[inline]
|
||||
fn bits() -> usize { $size }
|
||||
fn bits() -> u8 { $size }
|
||||
|
||||
#[inline]
|
||||
fn count_ones(self) -> usize { self.count_ones() as usize }
|
||||
}
|
||||
@@ -27,5 +46,5 @@ bit_block_impl!{
|
||||
(u16, 16),
|
||||
(u32, 32),
|
||||
(u64, 64),
|
||||
(usize, mem::size_of::<usize>() * 8)
|
||||
(usize, (mem::size_of::<usize>() * 8) as u8)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user