have NodeCodec using Vec
This commit is contained in:
parent
a45d28d391
commit
49b896e99c
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "patricia-trie"
|
||||
version = "0.2.2"
|
||||
version = "0.3.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
description = "Merkle-Patricia Trie generic over key hasher and node encoding"
|
||||
repository = "https://github.com/paritytech/parity-common"
|
||||
|
|
|
@ -21,7 +21,7 @@ use hashdb::Hasher;
|
|||
use node::Node;
|
||||
use ChildReference;
|
||||
|
||||
use elastic_array::{ElasticArray1024, ElasticArray128};
|
||||
use elastic_array::{ElasticArray128};
|
||||
|
||||
/// Trait for trie node encoding/decoding
|
||||
pub trait NodeCodec<H: Hasher>: Sized {
|
||||
|
@ -41,15 +41,15 @@ pub trait NodeCodec<H: Hasher>: Sized {
|
|||
fn is_empty_node(data: &[u8]) -> bool;
|
||||
|
||||
/// Returns an empty node
|
||||
fn empty_node() -> ElasticArray1024<u8>;
|
||||
fn empty_node() -> Vec<u8>;
|
||||
|
||||
/// Returns an encoded leaft node
|
||||
fn leaf_node(partial: &[u8], value: &[u8]) -> ElasticArray1024<u8>;
|
||||
fn leaf_node(partial: &[u8], value: &[u8]) -> Vec<u8>;
|
||||
|
||||
/// Returns an encoded extension node
|
||||
fn ext_node(partial: &[u8], child_ref: ChildReference<H::Out>) -> ElasticArray1024<u8>;
|
||||
fn ext_node(partial: &[u8], child_ref: ChildReference<H::Out>) -> Vec<u8>;
|
||||
|
||||
/// Returns an encoded branch node. Takes an iterator yielding `ChildReference<H::Out>` and an optional value
|
||||
fn branch_node<I>(children: I, value: Option<ElasticArray128<u8>>) -> ElasticArray1024<u8>
|
||||
fn branch_node<I>(children: I, value: Option<ElasticArray128<u8>>) -> Vec<u8>
|
||||
where I: IntoIterator<Item=Option<ChildReference<H::Out>>>;
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ use bytes::ToPretty;
|
|||
use hashdb::{HashDB, Hasher, DBValue};
|
||||
use nibbleslice::NibbleSlice;
|
||||
|
||||
use elastic_array::ElasticArray1024;
|
||||
use std::collections::{HashSet, VecDeque};
|
||||
use std::marker::PhantomData;
|
||||
use std::mem;
|
||||
|
@ -128,7 +127,7 @@ impl<O> Node<O> where O: AsRef<[u8]> + AsMut<[u8]> + Default + Debug + PartialEq
|
|||
}
|
||||
|
||||
// TODO: parallelize
|
||||
fn into_encoded<F, C, H>(self, mut child_cb: F) -> ElasticArray1024<u8>
|
||||
fn into_encoded<F, C, H>(self, mut child_cb: F) -> Vec<u8>
|
||||
where
|
||||
C: NodeCodec<H>,
|
||||
F: FnMut(NodeHandle<H::Out>) -> ChildReference<H::Out>,
|
||||
|
|
|
@ -6,7 +6,7 @@ description = "Merkle-Patricia Trie (Ethereum Style)"
|
|||
license = "GPL-3.0"
|
||||
|
||||
[dependencies]
|
||||
patricia-trie = { version = "0.2", path = "../../patricia_trie" }
|
||||
patricia-trie = { version = "0.3", path = "../../patricia_trie" }
|
||||
keccak-hasher = { version = "0.1", path = "../keccak-hasher" }
|
||||
hashdb = { version = "0.2", path = "../../hashdb" }
|
||||
rlp = { version = "0.3.0", path = "../../rlp" }
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
//! `NodeCodec` implementation for Rlp
|
||||
|
||||
use elastic_array::{ElasticArray1024, ElasticArray128};
|
||||
use elastic_array::ElasticArray128;
|
||||
use ethereum_types::H256;
|
||||
use hashdb::Hasher;
|
||||
use keccak_hasher::KeccakHasher;
|
||||
|
@ -72,20 +72,20 @@ impl NodeCodec<KeccakHasher> for RlpNodeCodec<KeccakHasher> {
|
|||
fn is_empty_node(data: &[u8]) -> bool {
|
||||
Rlp::new(data).is_empty()
|
||||
}
|
||||
fn empty_node() -> ElasticArray1024<u8> {
|
||||
fn empty_node() -> Vec<u8> {
|
||||
let mut stream = RlpStream::new();
|
||||
stream.append_empty_data();
|
||||
ElasticArray1024::from_vec(stream.drain())
|
||||
stream.drain()
|
||||
}
|
||||
|
||||
fn leaf_node(partial: &[u8], value: &[u8]) -> ElasticArray1024<u8> {
|
||||
fn leaf_node(partial: &[u8], value: &[u8]) -> Vec<u8> {
|
||||
let mut stream = RlpStream::new_list(2);
|
||||
stream.append(&partial);
|
||||
stream.append(&value);
|
||||
ElasticArray1024::from_vec(stream.drain())
|
||||
stream.drain()
|
||||
}
|
||||
|
||||
fn ext_node(partial: &[u8], child_ref: ChildReference<<KeccakHasher as Hasher>::Out>) -> ElasticArray1024<u8> {
|
||||
fn ext_node(partial: &[u8], child_ref: ChildReference<<KeccakHasher as Hasher>::Out>) -> Vec<u8> {
|
||||
let mut stream = RlpStream::new_list(2);
|
||||
stream.append(&partial);
|
||||
match child_ref {
|
||||
|
@ -95,10 +95,10 @@ impl NodeCodec<KeccakHasher> for RlpNodeCodec<KeccakHasher> {
|
|||
stream.append_raw(bytes, 1)
|
||||
},
|
||||
};
|
||||
ElasticArray1024::from_vec(stream.drain())
|
||||
stream.drain()
|
||||
}
|
||||
|
||||
fn branch_node<I>(children: I, value: Option<ElasticArray128<u8>>) -> ElasticArray1024<u8>
|
||||
fn branch_node<I>(children: I, value: Option<ElasticArray128<u8>>) -> Vec<u8>
|
||||
where I: IntoIterator<Item=Option<ChildReference<<KeccakHasher as Hasher>::Out>>>
|
||||
{
|
||||
let mut stream = RlpStream::new_list(17);
|
||||
|
@ -119,6 +119,6 @@ impl NodeCodec<KeccakHasher> for RlpNodeCodec<KeccakHasher> {
|
|||
} else {
|
||||
stream.append_empty_data();
|
||||
}
|
||||
ElasticArray1024::from_vec(stream.drain())
|
||||
stream.drain()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue