fix indentations
This commit is contained in:
parent
0272f6384d
commit
41a5501309
|
@ -88,14 +88,20 @@ pub struct MemoryDB<H: KeyHasher, T> {
|
|||
null_node_data: T,
|
||||
}
|
||||
|
||||
impl<'a, H, T> Default for MemoryDB<H, T> where H: KeyHasher, H::Out: HeapSizeOf, T: From<&'a [u8]> {
|
||||
impl<'a, H, T> Default for MemoryDB<H, T>
|
||||
where
|
||||
H: KeyHasher,
|
||||
H::Out: HeapSizeOf,
|
||||
T: From<&'a [u8]>
|
||||
{
|
||||
fn default() -> Self { Self::new() }
|
||||
}
|
||||
|
||||
impl<'a, H, T> MemoryDB<H, T>
|
||||
where H: KeyHasher,
|
||||
H::Out: HeapSizeOf,
|
||||
T: From<&'a [u8]>,
|
||||
where
|
||||
H: KeyHasher,
|
||||
H::Out: HeapSizeOf,
|
||||
T: From<&'a [u8]>,
|
||||
{
|
||||
/// Create a new instance of the memory DB.
|
||||
pub fn new() -> Self {
|
||||
|
@ -104,9 +110,10 @@ impl<'a, H, T> MemoryDB<H, T>
|
|||
}
|
||||
|
||||
impl<H, T> MemoryDB<H, T>
|
||||
where H: KeyHasher,
|
||||
H::Out: HeapSizeOf,
|
||||
T: Default,
|
||||
where
|
||||
H: KeyHasher,
|
||||
H::Out: HeapSizeOf,
|
||||
T: Default,
|
||||
{
|
||||
/// Remove an element and delete it from storage if reference count reaches zero.
|
||||
/// If the value was purged, return the old value.
|
||||
|
@ -208,9 +215,10 @@ impl<H: KeyHasher, T> MemoryDB<H, T> {
|
|||
}
|
||||
|
||||
impl<H, T> MemoryDB<H, T>
|
||||
where H: KeyHasher,
|
||||
H::Out: HeapSizeOf,
|
||||
T: HeapSizeOf,
|
||||
where
|
||||
H: KeyHasher,
|
||||
H::Out: HeapSizeOf,
|
||||
T: HeapSizeOf,
|
||||
{
|
||||
/// Returns the size of allocated heap memory
|
||||
pub fn mem_used(&self) -> usize {
|
||||
|
@ -219,8 +227,9 @@ impl<H, T> MemoryDB<H, T>
|
|||
}
|
||||
|
||||
impl<H, T> HashDB<H, T> for MemoryDB<H, T>
|
||||
where H: KeyHasher,
|
||||
T: Default + PartialEq<T> + for<'a> From<&'a [u8]> + Send + Sync,
|
||||
where
|
||||
H: KeyHasher,
|
||||
T: Default + PartialEq<T> + for<'a> From<&'a [u8]> + Send + Sync,
|
||||
{
|
||||
fn keys(&self) -> HashMap<H::Out, i32> {
|
||||
self.data.iter()
|
||||
|
@ -312,8 +321,9 @@ impl<H, T> HashDB<H, T> for MemoryDB<H, T>
|
|||
}
|
||||
|
||||
impl<H, T> AsHashDB<H, T> for MemoryDB<H, T>
|
||||
where H: KeyHasher,
|
||||
T: Default + PartialEq<T> + for<'a> From<&'a[u8]> + Send + Sync,
|
||||
where
|
||||
H: KeyHasher,
|
||||
T: Default + PartialEq<T> + for<'a> From<&'a[u8]> + Send + Sync,
|
||||
{
|
||||
fn as_hashdb(&self) -> &HashDB<H, T> { self }
|
||||
fn as_hashdb_mut(&mut self) -> &mut HashDB<H, T> { self }
|
||||
|
|
|
@ -77,11 +77,19 @@ enum Node<H> {
|
|||
Branch(Box<[Option<NodeHandle<H>>; 16]>, Option<DBValue>)
|
||||
}
|
||||
|
||||
impl<O> Node<O> where O: AsRef<[u8]> + AsMut<[u8]> + Default + Debug + PartialEq + Eq + Hash + Send + Sync + Clone + Copy {
|
||||
impl<O> Node<O>
|
||||
where
|
||||
O: AsRef<[u8]> + AsMut<[u8]> + Default + Debug + PartialEq + Eq + Hash + Send + Sync + Clone + Copy
|
||||
{
|
||||
// load an inline node into memory or get the hash to do the lookup later.
|
||||
fn inline_or_hash<C, H>(node: &[u8], db: &HashDB<H, DBValue>, storage: &mut NodeStorage<H::Out>) -> NodeHandle<H::Out>
|
||||
where C: NodeCodec<H>,
|
||||
H: Hasher<Out = O>,
|
||||
fn inline_or_hash<C, H>(
|
||||
node: &[u8],
|
||||
db: &HashDB<H, DBValue>,
|
||||
storage: &mut NodeStorage<H::Out>
|
||||
) -> NodeHandle<H::Out>
|
||||
where
|
||||
C: NodeCodec<H>,
|
||||
H: Hasher<Out = O>,
|
||||
{
|
||||
C::try_decode_hash(&node)
|
||||
.map(NodeHandle::Hash)
|
||||
|
@ -976,8 +984,15 @@ mod tests {
|
|||
use ethereum_types::H256;
|
||||
use DBValue;
|
||||
|
||||
fn populate_trie<'db, H, C>(db: &'db mut HashDB<KeccakHasher, DBValue>, root: &'db mut H256, v: &[(Vec<u8>, Vec<u8>)]) -> TrieDBMut<'db>
|
||||
where H: Hasher, H::Out: Decodable + Encodable, C: NodeCodec<H>
|
||||
fn populate_trie<'db, H, C>(
|
||||
db: &'db mut HashDB<KeccakHasher, DBValue>,
|
||||
root: &'db mut H256,
|
||||
v: &[(Vec<u8>, Vec<u8>)]
|
||||
) -> TrieDBMut<'db>
|
||||
where
|
||||
H: Hasher,
|
||||
H::Out: Decodable + Encodable,
|
||||
C: NodeCodec<H>,
|
||||
{
|
||||
let mut t = TrieDBMut::new(db, root);
|
||||
for i in 0..v.len() {
|
||||
|
|
|
@ -64,10 +64,10 @@ impl RlpStream {
|
|||
/// use rlp::*;
|
||||
///
|
||||
/// fn main () {
|
||||
/// let mut stream = RlpStream::new_list(2);
|
||||
/// stream.append_empty_data().append_empty_data();
|
||||
/// let out = stream.out();
|
||||
/// assert_eq!(out, vec![0xc2, 0x80, 0x80]);
|
||||
/// let mut stream = RlpStream::new_list(2);
|
||||
/// stream.append_empty_data().append_empty_data();
|
||||
/// let out = stream.out();
|
||||
/// assert_eq!(out, vec![0xc2, 0x80, 0x80]);
|
||||
/// }
|
||||
/// ```
|
||||
pub fn append_empty_data(&mut self) -> &mut Self {
|
||||
|
@ -105,10 +105,10 @@ impl RlpStream {
|
|||
/// use rlp::*;
|
||||
///
|
||||
/// fn main () {
|
||||
/// let mut stream = RlpStream::new_list(2);
|
||||
/// stream.append(&"cat").append(&"dog");
|
||||
/// let out = stream.out();
|
||||
/// assert_eq!(out, vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g']);
|
||||
/// let mut stream = RlpStream::new_list(2);
|
||||
/// stream.append(&"cat").append(&"dog");
|
||||
/// let out = stream.out();
|
||||
/// assert_eq!(out, vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g']);
|
||||
/// }
|
||||
/// ```
|
||||
pub fn append<'a, E>(&'a mut self, value: &E) -> &'a mut Self where E: Encodable {
|
||||
|
@ -143,11 +143,11 @@ impl RlpStream {
|
|||
/// use rlp::*;
|
||||
///
|
||||
/// fn main () {
|
||||
/// let mut stream = RlpStream::new_list(2);
|
||||
/// stream.begin_list(2).append(&"cat").append(&"dog");
|
||||
/// stream.append(&"");
|
||||
/// let out = stream.out();
|
||||
/// assert_eq!(out, vec![0xca, 0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g', 0x80]);
|
||||
/// let mut stream = RlpStream::new_list(2);
|
||||
/// stream.begin_list(2).append(&"cat").append(&"dog");
|
||||
/// stream.append(&"");
|
||||
/// let out = stream.out();
|
||||
/// assert_eq!(out, vec![0xca, 0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g', 0x80]);
|
||||
/// }
|
||||
/// ```
|
||||
pub fn begin_list(&mut self, len: usize) -> &mut RlpStream {
|
||||
|
@ -221,12 +221,12 @@ impl RlpStream {
|
|||
/// use rlp::*;
|
||||
///
|
||||
/// fn main () {
|
||||
/// let mut stream = RlpStream::new_list(3);
|
||||
/// stream.append(&"cat");
|
||||
/// stream.clear();
|
||||
/// stream.append(&"dog");
|
||||
/// let out = stream.out();
|
||||
/// assert_eq!(out, vec![0x83, b'd', b'o', b'g']);
|
||||
/// let mut stream = RlpStream::new_list(3);
|
||||
/// stream.append(&"cat");
|
||||
/// stream.clear();
|
||||
/// stream.append(&"dog");
|
||||
/// let out = stream.out();
|
||||
/// assert_eq!(out, vec![0x83, b'd', b'o', b'g']);
|
||||
/// }
|
||||
pub fn clear(&mut self) {
|
||||
// clear bytes
|
||||
|
@ -243,13 +243,13 @@ impl RlpStream {
|
|||
/// use rlp::*;
|
||||
///
|
||||
/// fn main () {
|
||||
/// let mut stream = RlpStream::new_list(2);
|
||||
/// stream.append(&"cat");
|
||||
/// assert_eq!(stream.is_finished(), false);
|
||||
/// stream.append(&"dog");
|
||||
/// assert_eq!(stream.is_finished(), true);
|
||||
/// let out = stream.out();
|
||||
/// assert_eq!(out, vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g']);
|
||||
/// let mut stream = RlpStream::new_list(2);
|
||||
/// stream.append(&"cat");
|
||||
/// assert_eq!(stream.is_finished(), false);
|
||||
/// stream.append(&"dog");
|
||||
/// assert_eq!(stream.is_finished(), true);
|
||||
/// let out = stream.out();
|
||||
/// assert_eq!(out, vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g']);
|
||||
/// }
|
||||
pub fn is_finished(&self) -> bool {
|
||||
self.unfinished_lists.len() == 0
|
||||
|
@ -266,7 +266,6 @@ impl RlpStream {
|
|||
/// panic! if stream is not finished.
|
||||
pub fn out(self) -> Vec<u8> {
|
||||
match self.is_finished() {
|
||||
//true => self.encoder.out().into_vec(),
|
||||
true => self.buffer,
|
||||
false => panic!()
|
||||
}
|
||||
|
|
|
@ -49,10 +49,11 @@ fn shared_prefix_len<T: Eq>(first: &[T], second: &[T]) -> usize {
|
|||
/// }
|
||||
/// ```
|
||||
pub fn ordered_trie_root<H, I, A>(input: I) -> H::Out
|
||||
where I: IntoIterator<Item = A>,
|
||||
A: AsRef<[u8]>,
|
||||
H: Hasher,
|
||||
<H as hashdb::Hasher>::Out: cmp::Ord + rlp::Encodable,
|
||||
where
|
||||
I: IntoIterator<Item = A>,
|
||||
A: AsRef<[u8]>,
|
||||
H: Hasher,
|
||||
<H as hashdb::Hasher>::Out: cmp::Ord + rlp::Encodable,
|
||||
{
|
||||
let gen_input: Vec<_> = input
|
||||
// first put elements into btree to sort them by nibbles (key'd by index)
|
||||
|
@ -89,11 +90,12 @@ pub fn ordered_trie_root<H, I, A>(input: I) -> H::Out
|
|||
/// }
|
||||
/// ```
|
||||
pub fn trie_root<H, I, A, B>(input: I) -> H::Out
|
||||
where I: IntoIterator<Item = (A, B)>,
|
||||
A: AsRef<[u8]> + Ord,
|
||||
B: AsRef<[u8]>,
|
||||
H: Hasher,
|
||||
<H as hashdb::Hasher>::Out: cmp::Ord + rlp::Encodable,
|
||||
where
|
||||
I: IntoIterator<Item = (A, B)>,
|
||||
A: AsRef<[u8]> + Ord,
|
||||
B: AsRef<[u8]>,
|
||||
H: Hasher,
|
||||
<H as hashdb::Hasher>::Out: cmp::Ord + rlp::Encodable,
|
||||
{
|
||||
let gen_input: Vec<_> = input
|
||||
// first put elements into btree to sort them and to remove duplicates
|
||||
|
@ -127,11 +129,12 @@ pub fn trie_root<H, I, A, B>(input: I) -> H::Out
|
|||
/// }
|
||||
/// ```
|
||||
pub fn sec_trie_root<H, I, A, B>(input: I) -> H::Out
|
||||
where I: IntoIterator<Item = (A, B)>,
|
||||
A: AsRef<[u8]>,
|
||||
B: AsRef<[u8]>,
|
||||
H: Hasher,
|
||||
<H as hashdb::Hasher>::Out: cmp::Ord + rlp::Encodable,
|
||||
where
|
||||
I: IntoIterator<Item = (A, B)>,
|
||||
A: AsRef<[u8]>,
|
||||
B: AsRef<[u8]>,
|
||||
H: Hasher,
|
||||
<H as hashdb::Hasher>::Out: cmp::Ord + rlp::Encodable,
|
||||
{
|
||||
let gen_input: Vec<_> = input
|
||||
// first put elements into btree to sort them and to remove duplicates
|
||||
|
@ -147,11 +150,11 @@ pub fn sec_trie_root<H, I, A, B>(input: I) -> H::Out
|
|||
}
|
||||
|
||||
fn gen_trie_root<H, A, B>(input: &[(A, B)]) -> H::Out
|
||||
where
|
||||
A: AsRef<[u8]>,
|
||||
B: AsRef<[u8]>,
|
||||
H: Hasher,
|
||||
<H as hashdb::Hasher>::Out: cmp::Ord + rlp::Encodable,
|
||||
where
|
||||
A: AsRef<[u8]>,
|
||||
B: AsRef<[u8]>,
|
||||
H: Hasher,
|
||||
<H as hashdb::Hasher>::Out: cmp::Ord + rlp::Encodable,
|
||||
{
|
||||
let mut stream = RlpStream::new();
|
||||
hash256rlp::<H, _, _>(input, 0, &mut stream);
|
||||
|
@ -214,11 +217,11 @@ fn as_nibbles(bytes: &[u8]) -> ElasticArray8<u8> {
|
|||
}
|
||||
|
||||
fn hash256rlp<H, A, B>(input: &[(A, B)], pre_len: usize, stream: &mut RlpStream)
|
||||
where
|
||||
A: AsRef<[u8]>,
|
||||
B: AsRef<[u8]>,
|
||||
H: Hasher,
|
||||
<H as hashdb::Hasher>::Out: rlp::Encodable,
|
||||
where
|
||||
A: AsRef<[u8]>,
|
||||
B: AsRef<[u8]>,
|
||||
H: Hasher,
|
||||
<H as hashdb::Hasher>::Out: rlp::Encodable,
|
||||
{
|
||||
let inlen = input.len();
|
||||
|
||||
|
@ -297,11 +300,11 @@ fn hash256rlp<H, A, B>(input: &[(A, B)], pre_len: usize, stream: &mut RlpStream)
|
|||
}
|
||||
|
||||
fn hash256aux<H, A, B>(input: &[(A, B)], pre_len: usize, stream: &mut RlpStream)
|
||||
where
|
||||
A: AsRef<[u8]>,
|
||||
B: AsRef<[u8]>,
|
||||
H: Hasher,
|
||||
<H as hashdb::Hasher>::Out: rlp::Encodable,
|
||||
where
|
||||
A: AsRef<[u8]>,
|
||||
B: AsRef<[u8]>,
|
||||
H: Hasher,
|
||||
<H as hashdb::Hasher>::Out: rlp::Encodable,
|
||||
{
|
||||
let mut s = RlpStream::new();
|
||||
hash256rlp::<H, _, _>(input, pre_len, &mut s);
|
||||
|
|
Loading…
Reference in New Issue