Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hash-db/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hash-db"
version = "0.11.0"
version = "0.12.0"
authors = ["Parity Technologies <[email protected]>"]
description = "Trait for hash-keyed databases."
license = "Apache-2.0"
Expand Down
24 changes: 11 additions & 13 deletions hash-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
#[cfg(feature = "std")]
use std::fmt::Debug;
#[cfg(feature = "std")]
use std::collections::HashMap;
#[cfg(feature = "std")]
use std::hash;
#[cfg(feature = "std")]
pub trait DebugIfStd: Debug {}
Expand Down Expand Up @@ -102,45 +100,45 @@ impl<'a, K, V> PlainDBRef<K, V> for &'a mut PlainDB<K, V> {
pub trait HashDB<H: Hasher, T>: Send + Sync + AsHashDB<H, T> {
/// Look up a given hash into the bytes that hash to it, returning None if the
/// hash is not known.
fn get(&self, key: &H::Out) -> Option<T>;
fn get(&self, key: &H::Out, prefix: &[u8]) -> Option<T>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PlainDB could probably use that too (fwiu plaindb is for varlen key), @sorpaas would know better than I.


/// Check for the existance of a hash-key.
fn contains(&self, key: &H::Out) -> bool;
fn contains(&self, key: &H::Out, prefix: &[u8]) -> bool;

/// Insert a datum item into the DB and return the datum's hash for a later lookup. Insertions
/// are counted and the equivalent number of `remove()`s must be performed before the data
/// is considered dead.
fn insert(&mut self, value: &[u8]) -> H::Out;
fn insert(&mut self, prefix: &[u8], value: &[u8]) -> H::Out;

/// Like `insert()`, except you provide the key and the data is all moved.
fn emplace(&mut self, key: H::Out, value: T);
fn emplace(&mut self, key: H::Out, prefix: &[u8], value: T);

/// Remove a datum previously inserted. Insertions can be "owed" such that the same number of `insert()`s may
/// happen without the data being eventually being inserted into the DB. It can be "owed" more than once.
fn remove(&mut self, key: &H::Out);
fn remove(&mut self, key: &H::Out, prefix: &[u8]);
}

/// Trait for immutable reference of HashDB.
#[cfg(feature = "std")]
pub trait HashDBRef<H: Hasher, T> {
/// Look up a given hash into the bytes that hash to it, returning None if the
/// hash is not known.
fn get(&self, key: &H::Out) -> Option<T>;
fn get(&self, key: &H::Out, prefix: &[u8]) -> Option<T>;

/// Check for the existance of a hash-key.
fn contains(&self, key: &H::Out) -> bool;
fn contains(&self, key: &H::Out, prefix: &[u8]) -> bool;
}

#[cfg(feature = "std")]
impl<'a, H: Hasher, T> HashDBRef<H, T> for &'a HashDB<H, T> {
fn get(&self, key: &H::Out) -> Option<T> { HashDB::get(*self, key) }
fn contains(&self, key: &H::Out) -> bool { HashDB::contains(*self, key) }
fn get(&self, key: &H::Out, prefix: &[u8]) -> Option<T> { HashDB::get(*self, key, prefix) }
fn contains(&self, key: &H::Out, prefix: &[u8]) -> bool { HashDB::contains(*self, key, prefix) }
}

#[cfg(feature = "std")]
impl<'a, H: Hasher, T> HashDBRef<H, T> for &'a mut HashDB<H, T> {
fn get(&self, key: &H::Out) -> Option<T> { HashDB::get(*self, key) }
fn contains(&self, key: &H::Out) -> bool { HashDB::contains(*self, key) }
fn get(&self, key: &H::Out, prefix: &[u8]) -> Option<T> { HashDB::get(*self, key, prefix) }
fn contains(&self, key: &H::Out, prefix: &[u8]) -> bool { HashDB::contains(*self, key, prefix) }
}

/// Upcast trait for HashDB.
Expand Down
2 changes: 1 addition & 1 deletion hash256-std-hasher/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "hash256-std-hasher"
description = "Standard library hasher for 256-bit prehashed keys."
version = "0.11.0"
version = "0.12.0"
authors = ["Parity Technologies <[email protected]>"]
license = "Apache-2.0"
homepage = "https://github.com/paritytech/trie"
Expand Down
6 changes: 3 additions & 3 deletions memory-db/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[package]
name = "memory-db"
version = "0.11.0"
version = "0.12.0"
authors = ["Parity Technologies <[email protected]>"]
description = "In-memory implementation of hash-db, useful for tests"
repository = "https://github.com/paritytech/parity-common"
license = "Apache-2.0"

[dependencies]
heapsize = "0.4"
hash-db = { path = "../hash-db", version = "0.11.0"}
hash-db = { path = "../hash-db", version = "0.12.0"}

[dev-dependencies]
keccak-hasher = { path = "../test-support/keccak-hasher", version = "0.11.0"}
keccak-hasher = { path = "../test-support/keccak-hasher", version = "0.12.0"}
criterion = "0.2.8"

[[bench]]
Expand Down
Loading