From 459915ff9a9c929743054523d2c19b48feec20ed Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Fri, 22 Dec 2023 15:31:15 +0800 Subject: [PATCH] fix and improve hashmap --- Cargo.toml | 4 ++-- src/hash_builder/mod.rs | 8 +++----- src/lib.rs | 2 ++ src/nodes/leaf.rs | 1 + 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 648bddf..424a399 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ derive_more = "0.99" nybbles = { version = "0.1", default-features = false } smallvec = "1.11" tracing = { version = "0.1", default-features = false } -hashbrown = { version = "0.14" } +hashbrown = { version = "0.14", features = ["serde", "ahash", "inline-more"] } # serde serde = { version = "1.0", default-features = false, features = ["derive"], optional = true } @@ -33,7 +33,7 @@ proptest = { version = "1.4", optional = true } proptest-derive = { version = "0.4", optional = true } [dev-dependencies] -hash-db = "0.16" +hash-db = "0.15" plain_hasher = "0.2" triehash = "0.8.4" diff --git a/src/hash_builder/mod.rs b/src/hash_builder/mod.rs index 2fb764c..f4a3330 100644 --- a/src/hash_builder/mod.rs +++ b/src/hash_builder/mod.rs @@ -6,10 +6,7 @@ use super::{ }; use alloy_primitives::{keccak256, Bytes, B256}; use core::cmp; -#[cfg(not(feature = "std"))] use hashbrown::HashMap; -#[cfg(feature = "std")] -use std::collections::HashMap; use std::{collections::BTreeMap, fmt::Debug, format, vec, vec::Vec}; use tracing::trace; @@ -422,7 +419,8 @@ mod tests { use super::*; use alloy_primitives::{b256, hex, keccak256, B256, U256}; use alloy_rlp::Encodable; - use std::collections::{BTreeMap, HashMap}; + use hashbrown::HashMap; + use std::collections::BTreeMap; fn triehash_trie_root(iter: I) -> B256 where @@ -577,7 +575,7 @@ mod tests { #[test] fn test_root_rlp_hashed_data() { - let data = HashMap::from([ + let data: HashMap<_, _, _> = HashMap::from([ (B256::with_last_byte(1), U256::from(2)), (B256::with_last_byte(3), U256::from(4)), ]); diff --git a/src/lib.rs b/src/lib.rs index 1f698a4..48a0fc7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,6 +28,8 @@ pub use hash_builder::HashBuilder; mod mask; pub use mask::TrieMask; +pub use hashbrown::HashMap; + #[doc(no_inline)] pub use nybbles::{self, Nibbles}; diff --git a/src/nodes/leaf.rs b/src/nodes/leaf.rs index 90a2b36..b289af1 100644 --- a/src/nodes/leaf.rs +++ b/src/nodes/leaf.rs @@ -59,6 +59,7 @@ impl fmt::Debug for LeafNode<'_> { mod tests { use super::*; use alloy_primitives::hex; + use std::vec; // From manual regression test #[test]