Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions test-support/reference-trie/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ use std::borrow::Borrow;
use keccak_hasher::KeccakHasher;

pub use trie_db::{
Trie, TrieError, TrieMut, TrieIterator, TrieDBNodeIterator, NibbleSlice, NibbleVec, Recorder,
NodeCodec,
Trie, TrieMut, TrieDB, TrieDBMut, TrieError, TrieIterator, TrieDBNodeIterator,
NibbleSlice, NibbleVec, NodeCodec, Recorder,
encode_compact, decode_compact,
};
pub use trie_db::{Record, TrieLayout, TrieConfiguration, nibble_ops};
pub use trie_root::TrieStream;
Expand Down
2 changes: 2 additions & 0 deletions trie-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ mod iterator;
mod lookup;
mod nibble;
mod node_codec;
mod trie_codec;

pub use hash_db::{HashDB, HashDBRef, Hasher};
pub use self::triedb::{TrieDB, TrieDBIterator};
Expand All @@ -100,6 +101,7 @@ pub use node_codec::{NodeCodec, Partial};
pub use iter_build::{trie_visit, ProcessEncodedNode,
TrieBuilder, TrieRoot, TrieRootUnhashed};
pub use iterator::TrieDBNodeIterator;
pub use trie_codec::{decode_compact, encode_compact};

#[cfg(feature = "std")]
pub use iter_build::TrieRootPrint;
Expand Down
18 changes: 18 additions & 0 deletions trie-db/src/nibble/nibblevec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,24 @@ impl NibbleVec {
}
}

/// Do we start with the same nibbles as the whole of `them`?
pub fn starts_with(&self, other: &Self) -> bool {
if self.len() < other.len() {
return false;
}
let byte_len = other.len() / nibble_ops::NIBBLE_PER_BYTE;
if &self.inner[..byte_len] != &other.inner[..byte_len] {
return false;
}
for pad in 0..(other.len() - byte_len * nibble_ops::NIBBLE_PER_BYTE) {
let self_nibble = nibble_ops::at_left(pad as u8, self.inner[byte_len]);
let other_nibble = nibble_ops::at_left(pad as u8, other.inner[byte_len]);
if self_nibble != other_nibble {
return false;
}
}
true
}
}

impl<'a> From<NibbleSlice<'a>> for NibbleVec {
Expand Down
Loading