Merge pull request #17 from paritytech/refactor/remove-heapsize-bound-from-hashdb

Remove HeapSizeOf-bound for Hasher::Out and add it only where needed
This commit is contained in:
David 2018-08-08 15:41:45 +02:00 committed by GitHub
commit e7aaf3c691
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 7 additions and 13 deletions

View File

@ -7,4 +7,3 @@ license = "GPL-3.0"
[dependencies]
elastic-array = "0.10"
heapsize = "0.4"

View File

@ -16,10 +16,8 @@
//! Database of byte-slices keyed to their hash.
extern crate elastic_array;
extern crate heapsize;
use elastic_array::ElasticArray128;
use heapsize::HeapSizeOf;
use std::collections::HashMap;
use std::{fmt::Debug, hash::Hash};
@ -28,7 +26,7 @@ use std::{fmt::Debug, hash::Hash};
/// `Out` associated type with the necessary bounds.
pub trait Hasher: Sync + Send {
/// The output type of the `Hasher`
type Out: AsRef<[u8]> + AsMut<[u8]> + Default + HeapSizeOf + Debug + PartialEq + Eq + Hash + Send + Sync + Clone + Copy;
type Out: AsRef<[u8]> + AsMut<[u8]> + Default + Debug + PartialEq + Eq + Hash + Send + Sync + Clone + Copy;
/// What to use to build `HashMap`s with this `Hasher`
type StdHasher: Sync + Send + Default + std::hash::Hasher;
/// The length in bytes of the `Hasher` output

View File

@ -87,11 +87,11 @@ pub struct MemoryDB<H: KeyHasher> {
hashed_null_node: H::Out,
}
impl<H: KeyHasher> Default for MemoryDB<H> {
impl<H> Default for MemoryDB<H> where H: KeyHasher, H::Out: HeapSizeOf {
fn default() -> Self { Self::new() }
}
impl<H: KeyHasher> MemoryDB<H> {
impl<H> MemoryDB<H> where H: KeyHasher, H::Out: HeapSizeOf {
/// Create a new instance of the memory DB.
pub fn new() -> MemoryDB<H> {
MemoryDB {

View File

@ -7,11 +7,10 @@ license = "GPL-3.0"
[dependencies]
elastic-array = "0.10"
heapsize = "0.4"
log = "0.3"
rand = "0.4"
hashdb = { version = "0.2.0", path = "../hashdb" }
parity-bytes = { version = "0.1.0", path = "../parity-bytes" }
hashdb = { version = "0.2", path = "../hashdb" }
parity-bytes = { version = "0.1", path = "../parity-bytes" }
[dev-dependencies]
env_logger = "0.5"

View File

@ -18,7 +18,6 @@
extern crate elastic_array;
extern crate parity_bytes as bytes; // TODO: name changed; update upstream when `parity-common` is available
extern crate hashdb;
extern crate heapsize;
extern crate rand;
#[macro_use]
extern crate log;

View File

@ -31,7 +31,6 @@ use std::collections::{HashSet, VecDeque};
use std::marker::PhantomData;
use std::mem;
use std::ops::Index;
use heapsize::HeapSizeOf;
use std::{fmt::Debug, hash::Hash};
// For lookups into the Node storage buffer.
@ -79,7 +78,7 @@ enum Node<H> {
Branch(Box<[Option<NodeHandle<H>>; 16]>, Option<DBValue>)
}
impl<O> Node<O> where O: AsRef<[u8]> + AsMut<[u8]> + Default + HeapSizeOf + Debug + PartialEq + Eq + Hash + Send + Sync + Clone + Copy {
impl<O> Node<O> where O: AsRef<[u8]> + AsMut<[u8]> + Default + Debug + PartialEq + Eq + Hash + Send + Sync + Clone + Copy {
// load an inline node into memory or get the hash to do the lookup later.
fn inline_or_hash<C, H>(node: &[u8], db: &HashDB<H>, storage: &mut NodeStorage<H::Out>) -> NodeHandle<H::Out>
where C: NodeCodec<H>,