Did stuff, stuff that doens't work.

This commit is contained in:
2018-01-06 23:42:36 +01:00
parent d56f05c680
commit f475629595
2 changed files with 80 additions and 50 deletions

View File

@@ -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)
}