parent
d322bcebd2
commit
f1ab6239d9
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "memorydb"
|
||||
version = "0.2.0"
|
||||
version = "0.2.1"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
description = "in-memory implementation of hashdb"
|
||||
license = "GPL-3.0"
|
||||
|
|
|
@ -81,12 +81,16 @@ type FastMap<H, T> = HashMap<<H as KeyHasher>::Out, T, hash::BuildHasherDefault<
|
|||
/// assert!(!m.contains(&k));
|
||||
/// }
|
||||
/// ```
|
||||
#[derive(Default, Clone, PartialEq)]
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct MemoryDB<H: KeyHasher> {
|
||||
data: FastMap<H, (DBValue, i32)>,
|
||||
hashed_null_node: H::Out,
|
||||
}
|
||||
|
||||
impl<H: KeyHasher> Default for MemoryDB<H> {
|
||||
fn default() -> Self { Self::new() }
|
||||
}
|
||||
|
||||
impl<H: KeyHasher> MemoryDB<H> {
|
||||
/// Create a new instance of the memory DB.
|
||||
pub fn new() -> MemoryDB<H> {
|
||||
|
@ -341,4 +345,11 @@ mod tests {
|
|||
assert_eq!(overlay.get(&insert_key).unwrap(), &(DBValue::from_slice(b"arf"), 2));
|
||||
assert_eq!(overlay.get(&negative_remove_key).unwrap(), &(DBValue::from_slice(b"negative"), -2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn default_works() {
|
||||
let mut db = MemoryDB::<KeccakHasher>::default();
|
||||
let hashed_null_node = KeccakHasher::hash(&NULL_RLP);
|
||||
assert_eq!(db.insert(&NULL_RLP), hashed_null_node);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue