mirror of
https://github.com/vacp2p/pmtree.git
synced 2025-02-20 11:08:17 +00:00
test: implement batch_insert for memory_keccak
This commit is contained in:
parent
9055b14f07
commit
0d3f2e0657
@ -21,5 +21,5 @@ pub trait Database {
|
||||
fn put(&mut self, key: DBKey, value: Value) -> Result<()>;
|
||||
|
||||
/// Batc
|
||||
fn put_batch(&mut self, subtree: &HashMap<DBKey, Value>) -> Result<()>;
|
||||
fn put_batch(&mut self, subtree: HashMap<DBKey, Value>) -> Result<()>;
|
||||
}
|
||||
|
@ -221,7 +221,12 @@ where
|
||||
|
||||
let subtree = RwLock::into_inner(Arc::try_unwrap(subtree).unwrap()).unwrap();
|
||||
|
||||
self.db.put_batch(&subtree.into_iter().)?;
|
||||
self.db.put_batch(
|
||||
subtree
|
||||
.into_iter()
|
||||
.map(|(key, value)| (key.into(), H::serialize(value)))
|
||||
.collect(),
|
||||
)?;
|
||||
|
||||
// Update root value and next_index in memory
|
||||
self.root = root_val;
|
||||
|
@ -25,7 +25,9 @@ impl Database for MemoryDB {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn put_batch(&mut self, subtree: &HashMap<DBKey, Value>) -> Result<()> {
|
||||
fn put_batch(&mut self, subtree: HashMap<DBKey, Value>) -> Result<()> {
|
||||
self.0.extend(subtree.into_iter());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@ -101,3 +103,19 @@ fn insert_delete() -> Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn batch_insertions() -> Result<()> {
|
||||
let mut mt = MerkleTree::<MemoryDB, MyKeccak>::new(2, "abacaba")?;
|
||||
|
||||
let leaves = [
|
||||
hex!("0000000000000000000000000000000000000000000000000000000000000001"),
|
||||
hex!("0000000000000000000000000000000000000000000000000000000000000002"),
|
||||
hex!("0000000000000000000000000000000000000000000000000000000000000003"),
|
||||
hex!("0000000000000000000000000000000000000000000000000000000000000004"),
|
||||
];
|
||||
|
||||
mt.batch_insert(&leaves)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -62,7 +62,9 @@ impl Database for MemoryDB {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn put_batch(&mut self, subtree: &HashMap<DBKey, Value>) -> Result<()> {
|
||||
fn put_batch(&mut self, subtree: HashMap<DBKey, Value>) -> Result<()> {
|
||||
self.0.extend(subtree.into_iter());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@ -100,7 +102,7 @@ impl Database for MySled {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn put_batch(&mut self, subtree: &HashMap<DBKey, Value>) -> Result<()> {
|
||||
fn put_batch(&mut self, subtree: HashMap<DBKey, Value>) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ impl Database for MySled {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn put_batch(&mut self, subtree: &HashMap<DBKey, Value>) -> Result<()> {
|
||||
fn put_batch(&mut self, subtree: HashMap<DBKey, Value>) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user