Move ethereum-specific H256FastMap type to own crate (#9307)

* Add a `fastmap` crate that provides the H256FastMap specialized HashMap

* Use `fastmap` instead of `plain_hasher`

* Update submodules for Reasons™

* Submodule update
This commit is contained in:
David 2018-08-09 09:51:48 +02:00 committed by Marek Kotewicz
parent 78a38e9825
commit e2095d4a5d
15 changed files with 72 additions and 14 deletions

14
Cargo.lock generated
View File

@ -597,6 +597,7 @@ dependencies = [
"ethcore-network 1.12.0",
"ethcore-transaction 0.1.0",
"ethereum-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"fastmap 0.1.0",
"futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
"hashdb 0.2.0 (git+https://github.com/paritytech/parity-common)",
"heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -612,7 +613,6 @@ dependencies = [
"parking_lot 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"patricia-trie 0.2.1 (git+https://github.com/paritytech/parity-common)",
"patricia-trie-ethereum 0.1.0",
"plain_hasher 0.1.0 (git+https://github.com/paritytech/parity-common)",
"rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rlp 0.2.1 (git+https://github.com/paritytech/parity-common)",
"rlp_derive 0.1.0",
@ -845,6 +845,7 @@ dependencies = [
"ethcore-transaction 0.1.0",
"ethereum-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"ethkey 0.3.0",
"fastmap 0.1.0",
"hashdb 0.2.0 (git+https://github.com/paritytech/parity-common)",
"heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"ipnetwork 0.12.7 (registry+https://github.com/rust-lang/crates.io-index)",
@ -856,7 +857,6 @@ dependencies = [
"macros 0.1.0",
"parity-bytes 0.1.0 (git+https://github.com/paritytech/parity-common)",
"parking_lot 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"plain_hasher 0.1.0 (git+https://github.com/paritytech/parity-common)",
"rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rlp 0.2.1 (git+https://github.com/paritytech/parity-common)",
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1044,6 +1044,14 @@ dependencies = [
"ethkey 0.3.0",
]
[[package]]
name = "fastmap"
version = "0.1.0"
dependencies = [
"ethereum-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"plain_hasher 0.1.0 (git+https://github.com/paritytech/parity-common)",
]
[[package]]
name = "fdlimit"
version = "0.1.1"
@ -1323,6 +1331,7 @@ version = "0.2.0"
dependencies = [
"ethcore-logger 1.12.0",
"ethereum-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"fastmap 0.1.0",
"hashdb 0.2.0 (git+https://github.com/paritytech/parity-common)",
"heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"keccak-hash 0.1.2 (git+https://github.com/paritytech/parity-common)",
@ -1333,7 +1342,6 @@ dependencies = [
"memorydb 0.2.1 (git+https://github.com/paritytech/parity-common)",
"parity-bytes 0.1.0 (git+https://github.com/paritytech/parity-common)",
"parking_lot 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"plain_hasher 0.1.0 (git+https://github.com/paritytech/parity-common)",
"rlp 0.2.1 (git+https://github.com/paritytech/parity-common)",
]

View File

@ -136,6 +136,7 @@ members = [
"util/triehash-ethereum",
"util/keccak-hasher",
"util/patricia-trie-ethereum",
"util/fastmap",
]
[patch.crates-io]

View File

@ -20,7 +20,7 @@ ethcore-io = { path = "../../util/io" }
hashdb = { git = "https://github.com/paritytech/parity-common" }
heapsize = "0.4"
vm = { path = "../vm" }
plain_hasher = { git = "https://github.com/paritytech/parity-common" }
fastmap = { path = "../../util/fastmap" }
rlp = { git = "https://github.com/paritytech/parity-common" }
rlp_derive = { path = "../../util/rlp_derive" }
smallvec = "0.4"

View File

@ -41,7 +41,7 @@ use ethereum_types::{H256, H264, U256};
use heapsize::HeapSizeOf;
use kvdb::{DBTransaction, KeyValueDB};
use parking_lot::{Mutex, RwLock};
use plain_hasher::H256FastMap;
use fastmap::H256FastMap;
use rlp::{Encodable, Decodable, DecoderError, RlpStream, Rlp};
use smallvec::SmallVec;

View File

@ -68,7 +68,7 @@ extern crate keccak_hasher;
extern crate memorydb;
extern crate patricia_trie as trie;
extern crate patricia_trie_ethereum as ethtrie;
extern crate plain_hasher;
extern crate fastmap;
extern crate rand;
extern crate rlp;
extern crate parking_lot;

View File

@ -29,7 +29,7 @@ use std::collections::hash_map::Entry;
use transaction::{self, Condition, PendingTransaction, SignedTransaction};
use ethereum_types::{H256, U256, Address};
use plain_hasher::H256FastMap;
use fastmap::H256FastMap;
// Knowledge of an account's current nonce.
#[derive(Debug, Clone, PartialEq, Eq)]

View File

@ -17,7 +17,7 @@ ethcore-transaction = { path = "../transaction" }
ethcore = { path = ".." }
ethereum-types = "0.3"
hashdb = { git = "https://github.com/paritytech/parity-common" }
plain_hasher = { git = "https://github.com/paritytech/parity-common" }
fastmap = { path = "../../util/fastmap" }
rlp = { git = "https://github.com/paritytech/parity-common" }
rustc-hex = "1.0"
keccak-hash = { git = "https://github.com/paritytech/parity-common" }

View File

@ -99,7 +99,7 @@ use std::time::{Duration, Instant};
use hash::keccak;
use heapsize::HeapSizeOf;
use ethereum_types::{H256, U256};
use plain_hasher::H256FastMap;
use fastmap::H256FastMap;
use parking_lot::RwLock;
use bytes::Bytes;
use rlp::{Rlp, RlpStream, DecoderError};

View File

@ -31,7 +31,7 @@ extern crate ethcore;
extern crate ethereum_types;
extern crate env_logger;
extern crate hashdb;
extern crate plain_hasher;
extern crate fastmap;
extern crate rand;
extern crate semver;
extern crate parking_lot;

View File

@ -17,7 +17,7 @@
use api::TransactionStats;
use std::collections::{HashSet, HashMap};
use ethereum_types::{H256, H512};
use plain_hasher::H256FastMap;
use fastmap::H256FastMap;
type NodeId = H512;
type BlockNumber = u64;

10
util/fastmap/Cargo.toml Normal file
View File

@ -0,0 +1,10 @@
[package]
name = "fastmap"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
description = "Specialized version of `HashMap` with H256 keys and fast hashing function."
license = "GPL-3.0"
[dependencies]
ethereum-types = "0.3"
plain_hasher = { git = "https://github.com/paritytech/parity-common" }

39
util/fastmap/src/lib.rs Normal file
View File

@ -0,0 +1,39 @@
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! Provides a `H256FastMap` type with H256 keys and fast hashing function.
extern crate ethereum_types;
extern crate plain_hasher;
use ethereum_types::H256;
use std::hash;
use std::collections::HashMap;
use plain_hasher::PlainHasher;
/// Specialized version of `HashMap` with H256 keys and fast hashing function.
pub type H256FastMap<T> = HashMap<H256, T, hash::BuildHasherDefault<PlainHasher>>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_works() {
let mut h = H256FastMap::default();
h.insert(H256::from(123), "abc");
}
}

View File

@ -15,7 +15,7 @@ kvdb = { git = "https://github.com/paritytech/parity-common" }
log = "0.3"
memorydb = { git = "https://github.com/paritytech/parity-common" }
parking_lot = "0.6"
plain_hasher = { git = "https://github.com/paritytech/parity-common" }
fastmap = { path = "../../util/fastmap" }
rlp = { git = "https://github.com/paritytech/parity-common" }
[dev-dependencies]

View File

@ -27,7 +27,7 @@ extern crate keccak_hasher;
extern crate kvdb;
extern crate memorydb;
extern crate parking_lot;
extern crate plain_hasher;
extern crate fastmap;
extern crate rlp;
#[cfg(test)]

View File

@ -29,7 +29,7 @@ use keccak_hasher::KeccakHasher;
use kvdb::{KeyValueDB, DBTransaction};
use memorydb::*;
use parking_lot::RwLock;
use plain_hasher::H256FastMap;
use fastmap::H256FastMap;
use rlp::{Rlp, RlpStream, encode, decode, DecoderError, Decodable, Encodable};
use super::{DB_PREFIX_LEN, LATEST_ERA_KEY, JournalDB, error_negatively_reference_hash};
use util::DatabaseKey;