Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow skipping value for compact proof #126

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
649693d
Expose decode with an iterator.
cheme Jan 18, 2021
a323431
reexport
cheme Jan 18, 2021
b5c1e9d
Update trie-db/src/trie_codec.rs
cheme Jan 18, 2021
094a1dd
Apply suggestion : IntoIter usage.
cheme Jan 18, 2021
25e9166
Merge branch 'iter_decode' of github.com:cheme/trie into iter_decode
cheme Jan 18, 2021
70c0d38
encode compact without specific values.
cheme Jan 21, 2021
c0763e4
insert on decode
cheme Jan 21, 2021
ca296d8
Allow lazy value fetch.
cheme Jan 22, 2021
c64e6c3
usable api
cheme Jan 22, 2021
6b58a32
Use cow from alloc for no_std
cheme Jan 27, 2021
5322f0c
expose LazyValue
cheme Jan 28, 2021
6322313
Merge branch 'master' into skip_compact_values_alt
cheme Jan 28, 2021
f7b772c
add alternative enum
cheme Jan 28, 2021
0203860
resolve ineserted_value immediatly
cheme Jan 28, 2021
88a6776
escaping code
cheme Jan 28, 2021
75c29b9
factor
cheme Jan 28, 2021
932f76f
do not allow non skip value to be replaced.
cheme Jan 28, 2021
e9f63a7
factor a bit
cheme Jan 28, 2021
afc2fd5
Todo write test and others variant
cheme Jan 28, 2021
5cc77bd
test and fix
cheme Jan 29, 2021
c2e0327
None enum.
cheme Jan 29, 2021
56453ce
conditional instead of iterator would be better.
cheme Jan 29, 2021
75b85e7
fix for branch usage
cheme Jan 29, 2021
258f5bf
use enum instead of pair of bool
cheme Jan 29, 2021
c377a1c
replace test on skip key by conditional implementation
cheme Jan 29, 2021
e6c2fa9
first step in removing enum
cheme Jan 29, 2021
ccb9368
remove useless mut ptremove useless mut ptrr
cheme Jan 29, 2021
0bd7f1e
missing one
cheme Jan 29, 2021
9f9cfd5
remove TODO
cheme Jan 29, 2021
074fc04
Allows to decode without escaping
cheme Jan 29, 2021
ccb001e
Api to allow escape decoding with known keys.
cheme Feb 1, 2021
d7b29e5
fix
cheme Feb 1, 2021
8b8c648
fix iter
cheme Feb 1, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions trie-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ extern crate alloc;
mod rstd {
pub use std::{borrow, boxed, cmp, convert, fmt, hash, iter, marker, mem, ops, rc, result, vec};
pub use std::collections::VecDeque;
pub use std::collections::BTreeMap;
pub use std::error::Error;
}

#[cfg(not(feature = "std"))]
mod rstd {
pub use core::{borrow, convert, cmp, iter, fmt, hash, marker, mem, ops, result};
pub use alloc::{boxed, rc, vec};
pub use core::{convert, cmp, iter, fmt, hash, marker, mem, ops, result};
pub use alloc::{borrow, boxed, rc, vec};
pub use alloc::collections::VecDeque;
pub use alloc::collections::btree_map::BTreeMap;
pub trait Error {}
impl<T> Error for T {}
}
Expand Down Expand Up @@ -71,7 +73,11 @@ pub use crate::node_codec::{NodeCodec, Partial};
pub use crate::iter_build::{trie_visit, ProcessEncodedNode,
TrieBuilder, TrieRoot, TrieRootUnhashed};
pub use crate::iterator::TrieDBNodeIterator;
pub use crate::trie_codec::{decode_compact, decode_compact_from_iter, encode_compact};
pub use crate::trie_codec::{encode_compact,
decode_compact, decode_compact_from_iter, decode_compact_with_known_values,
decode_compact_for_encoded_skipped_values, encode_compact_skip_all_values,
LazyFetcher, compact_conditions, encode_compact_skip_conditional,
encode_compact_skip_conditional_with_key};

#[cfg(feature = "std")]
pub use crate::iter_build::TrieRootPrint;
Expand Down
11 changes: 10 additions & 1 deletion trie-db/src/nibble/leftnibbleslice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ impl<'a> LeftNibbleSlice<'a> {
// If common nibble prefix is the same, finally compare lengths.
self.len().cmp(&other.len())
}

/// If nibble are aligned (true for any value), return slice to the key.
pub fn as_slice(&self) -> Option<&'a [u8]> {
if self.len % NIBBLE_PER_BYTE == 0 {
Some(&self.bytes[..self.len / NIBBLE_PER_BYTE])
} else {
None
}
}
}

impl<'a> PartialEq for LeftNibbleSlice<'a> {
Expand Down Expand Up @@ -226,4 +235,4 @@ mod tests {
Ordering::Equal
);
}
}
}
8 changes: 8 additions & 0 deletions trie-db/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ impl NibbleSlicePlan {
}
}

/// A empty nibbleslice.
pub fn empty() -> Self {
NibbleSlicePlan {
bytes: 0..0,
offset: 0,
}
}

/// Returns the nibble length of the slice.
pub fn len(&self) -> usize {
(self.bytes.end - self.bytes.start) * nibble_ops::NIBBLE_PER_BYTE - self.offset
Expand Down
Loading