Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow constant associated empty root value. #77

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions hash-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ pub trait Hasher: Sync + Send {
fn hash(x: &[u8]) -> Self::Out;
}

/// Technical trait to avoid calculating empty root.
/// This trait assumes, an empty node is `[0u8]`.
pub trait HasherNullEmptyRoot: Hasher {
/// Associated constant value.
const EMPTY_ROOT: &'static [u8];
}

/// Test to call for all new `HasherNullEmptyRoot` implementation.
pub fn test_associated_empty_root<H: HasherNullEmptyRoot>() -> bool {
let empty = <H as Hasher>::hash(&[0u8]);
H::EMPTY_ROOT == empty.as_ref()
}

/// Trait modelling a plain datastore whose key is a fixed type.
/// The caller should ensure that a key only corresponds to
/// one value.
Expand Down
Loading