diff --git a/src/bloom.rs b/src/bloom.rs deleted file mode 100644 index fe619fae6..000000000 --- a/src/bloom.rs +++ /dev/null @@ -1,7 +0,0 @@ -use bytes::BytesConvertable; -// use hash::FixedHash; - -pub trait Bloomable { - fn shift_bloom(&mut self, bytes: &T) where T: BytesConvertable; - fn contains_bloom(&self, bytes: &T) -> bool where T: BytesConvertable; -} diff --git a/src/hash.rs b/src/hash.rs index 98a76ad87..310a11dbb 100644 --- a/src/hash.rs +++ b/src/hash.rs @@ -9,10 +9,13 @@ use rand::os::OsRng; use bytes::BytesConvertable; /// types implementing FixedHash must be also BytesConvertable -pub trait FixedHash: BytesConvertable { +pub trait FixedHash: Sized + BytesConvertable { + fn new() -> Self; fn random() -> Self; fn randomize(&mut self); fn mut_bytes(&mut self) -> &mut [u8]; + fn shift_bloom<'a, T>(&'a mut self, b: &T) -> &'a mut Self where T: FixedHash; + fn bloom_part(&self) -> T where T: FixedHash; } macro_rules! impl_hash { @@ -20,13 +23,6 @@ macro_rules! impl_hash { #[derive(Eq)] pub struct $from (pub [u8; $size]); - - impl $from { - fn new() -> $from { - $from([0; $size]) - } - } - impl BytesConvertable for $from { fn bytes(&self) -> &[u8] { &self.0 @@ -34,6 +30,10 @@ macro_rules! impl_hash { } impl FixedHash for $from { + fn new() -> $from { + $from([0; $size]) + } + fn random() -> $from { let mut hash = $from::new(); hash.randomize(); @@ -48,6 +48,24 @@ macro_rules! impl_hash { fn mut_bytes(&mut self) -> &mut [u8] { &mut self.0 } + + fn shift_bloom<'a, T>(&'a mut self, b: &T) -> &'a mut Self where T: FixedHash { + let bp: Self = b.bloom_part(); + let new_self = &bp | self; + + // impl |= instead + + unsafe { + use std::{mem, ptr}; + ptr::copy(new_self.0.as_ptr(), self.0.as_mut_ptr(), mem::size_of::()); + } + + self + } + + fn bloom_part(&self) -> T where T: FixedHash { + panic!() + } } impl FromStr for $from { diff --git a/src/lib.rs b/src/lib.rs index a52e35925..7c480c02b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,7 +16,6 @@ pub mod rlp; pub mod vector; pub mod db; pub mod sha3; -pub mod bloom; //pub mod network; diff --git a/src/sha3.rs b/src/sha3.rs index b7eec2a5f..ee328913c 100644 --- a/src/sha3.rs +++ b/src/sha3.rs @@ -3,7 +3,7 @@ use tiny_keccak::keccak_256; use bytes::BytesConvertable; use hash::{FixedHash, H256}; -trait Hashable { +pub trait Hashable { fn sha3(&self) -> H256; }