parent
d322bcebd2
commit
f1ab6239d9
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "memorydb"
|
name = "memorydb"
|
||||||
version = "0.2.0"
|
version = "0.2.1"
|
||||||
authors = ["Parity Technologies <admin@parity.io>"]
|
authors = ["Parity Technologies <admin@parity.io>"]
|
||||||
description = "in-memory implementation of hashdb"
|
description = "in-memory implementation of hashdb"
|
||||||
license = "GPL-3.0"
|
license = "GPL-3.0"
|
||||||
|
|
|
@ -46,7 +46,7 @@ type FastMap<H, T> = HashMap<<H as KeyHasher>::Out, T, hash::BuildHasherDefault<
|
||||||
/// extern crate hashdb;
|
/// extern crate hashdb;
|
||||||
/// extern crate keccak_hasher;
|
/// extern crate keccak_hasher;
|
||||||
/// extern crate memorydb;
|
/// extern crate memorydb;
|
||||||
///
|
///
|
||||||
/// use hashdb::*;
|
/// use hashdb::*;
|
||||||
/// use keccak_hasher::KeccakHasher;
|
/// use keccak_hasher::KeccakHasher;
|
||||||
/// use memorydb::*;
|
/// use memorydb::*;
|
||||||
|
@ -81,12 +81,16 @@ type FastMap<H, T> = HashMap<<H as KeyHasher>::Out, T, hash::BuildHasherDefault<
|
||||||
/// assert!(!m.contains(&k));
|
/// assert!(!m.contains(&k));
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Default, Clone, PartialEq)]
|
#[derive(Clone, PartialEq)]
|
||||||
pub struct MemoryDB<H: KeyHasher> {
|
pub struct MemoryDB<H: KeyHasher> {
|
||||||
data: FastMap<H, (DBValue, i32)>,
|
data: FastMap<H, (DBValue, i32)>,
|
||||||
hashed_null_node: H::Out,
|
hashed_null_node: H::Out,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<H: KeyHasher> Default for MemoryDB<H> {
|
||||||
|
fn default() -> Self { Self::new() }
|
||||||
|
}
|
||||||
|
|
||||||
impl<H: KeyHasher> MemoryDB<H> {
|
impl<H: KeyHasher> MemoryDB<H> {
|
||||||
/// Create a new instance of the memory DB.
|
/// Create a new instance of the memory DB.
|
||||||
pub fn new() -> MemoryDB<H> {
|
pub fn new() -> MemoryDB<H> {
|
||||||
|
@ -103,11 +107,11 @@ impl<H: KeyHasher> MemoryDB<H> {
|
||||||
/// extern crate hashdb;
|
/// extern crate hashdb;
|
||||||
/// extern crate keccak_hasher;
|
/// extern crate keccak_hasher;
|
||||||
/// extern crate memorydb;
|
/// extern crate memorydb;
|
||||||
///
|
///
|
||||||
/// use hashdb::*;
|
/// use hashdb::*;
|
||||||
/// use keccak_hasher::KeccakHasher;
|
/// use keccak_hasher::KeccakHasher;
|
||||||
/// use memorydb::*;
|
/// use memorydb::*;
|
||||||
///
|
///
|
||||||
/// fn main() {
|
/// fn main() {
|
||||||
/// let mut m = MemoryDB::<KeccakHasher>::new();
|
/// let mut m = MemoryDB::<KeccakHasher>::new();
|
||||||
/// let hello_bytes = "Hello world!".as_bytes();
|
/// let hello_bytes = "Hello world!".as_bytes();
|
||||||
|
@ -341,4 +345,11 @@ mod tests {
|
||||||
assert_eq!(overlay.get(&insert_key).unwrap(), &(DBValue::from_slice(b"arf"), 2));
|
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));
|
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