diff --git a/plain_hasher/Cargo.toml b/plain_hasher/Cargo.toml index adc03bb..53b8801 100644 --- a/plain_hasher/Cargo.toml +++ b/plain_hasher/Cargo.toml @@ -1,13 +1,16 @@ [package] name = "plain_hasher" description = "Hasher for 32-bit keys." -version = "0.1.0" +version = "0.2.0" authors = ["Parity Technologies "] license = "MIT" keywords = ["hash", "hasher"] -homepage = "https://github.com/paritytech/plain_hasher" +homepage = "https://github.com/paritytech/parity-common" +categories = [ "no-std"] [dependencies] crunchy = "0.1.6" -ethereum-types = "0.3" -hashdb = { path = "../hashdb" } \ No newline at end of file + +[features] +default = ["std"] +std = [] \ No newline at end of file diff --git a/plain_hasher/README.md b/plain_hasher/README.md new file mode 100644 index 0000000..2787796 --- /dev/null +++ b/plain_hasher/README.md @@ -0,0 +1,5 @@ +# Specialized Hasher for 32-bit keys + +Provides `PlainHasher`, a specialized `core::hash::Hasher` that takes just 8 bytes of the provided value and may only be used for keys which are 32 bytes. + +The crate is `no_std`-compatible. \ No newline at end of file diff --git a/plain_hasher/src/lib.rs b/plain_hasher/src/lib.rs index 4a8a104..3250cd6 100644 --- a/plain_hasher/src/lib.rs +++ b/plain_hasher/src/lib.rs @@ -14,20 +14,15 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +#![cfg_attr(not(feature = "std"), no_std)] + #[macro_use] extern crate crunchy; -extern crate ethereum_types; -extern crate hashdb; -use ethereum_types::H256; -// use hashdb::Hasher; -use std::hash; -use std::collections::{HashMap, HashSet}; -/// Specialized version of `HashMap` with H256 keys and fast hashing function. -pub type H256FastMap = HashMap>; -/// Specialized version of `HashSet` with H256 keys and fast hashing function. -pub type H256FastSet = HashSet>; +#[cfg(feature = "std")] +extern crate core; +use core::hash; /// Hasher that just takes 8 bytes of the provided value. /// May only be used for keys which are 32 bytes. #[derive(Default)] @@ -50,7 +45,7 @@ impl hash::Hasher for PlainHasher { unroll! { for _i in 0..8 { - unsafe { + unsafe { *prefix_ptr ^= (*bytes_ptr ^ *bytes_ptr.offset(8)) ^ (*bytes_ptr.offset(16) ^ *bytes_ptr.offset(24)); bytes_ptr = bytes_ptr.offset(1); prefix_ptr = prefix_ptr.offset(1); diff --git a/test-support/keccak-hasher/Cargo.toml b/test-support/keccak-hasher/Cargo.toml index 7c82f17..363d5d7 100644 --- a/test-support/keccak-hasher/Cargo.toml +++ b/test-support/keccak-hasher/Cargo.toml @@ -10,4 +10,4 @@ license = "GPL-3.0" ethereum-types = "0.3" tiny-keccak = "1.4.2" hashdb = { version = "0.2.0", path = "../../hashdb" } -plain_hasher = { version = "0.1.0", path = "../../plain_hasher" } \ No newline at end of file +plain_hasher = { path = "../../plain_hasher" } \ No newline at end of file