Skip to content

Commit

Permalink
Revert "Add Nibblepath to API"
Browse files Browse the repository at this point in the history
This reverts commit 1255c6b.
  • Loading branch information
preston-evans98 committed Nov 22, 2023
1 parent 1255c6b commit 0c93cb9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ pub mod storage {
pub use node_type::{LeafNode, Node, NodeKey};
pub use reader::HasPreimage;
pub use reader::TreeReader;
pub use types::nibble::nibble_path::NibblePath;
pub use writer::{
NodeBatch, NodeStats, StaleNodeIndex, StaleNodeIndexBatch, TreeUpdateBatch, TreeWriter,
};
Expand Down
4 changes: 2 additions & 2 deletions src/node_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub struct NodeKey {

impl NodeKey {
/// Creates a new `NodeKey`.
pub fn new(version: Version, nibble_path: NibblePath) -> Self {
pub(crate) fn new(version: Version, nibble_path: NibblePath) -> Self {
Self {
version,
nibble_path,
Expand All @@ -75,7 +75,7 @@ impl NodeKey {
}

/// Gets the nibble path.
pub fn nibble_path(&self) -> &NibblePath {
pub(crate) fn nibble_path(&self) -> &NibblePath {
&self.nibble_path
}

Expand Down
13 changes: 5 additions & 8 deletions src/types/nibble/nibble_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,14 @@ prop_compose! {

impl NibblePath {
/// Creates a new `NibblePath` from a vector of bytes assuming each byte has 2 nibbles.
pub(crate) fn new(bytes: Vec<u8>) -> Self {
pub fn new(bytes: Vec<u8>) -> Self {
checked_precondition!(bytes.len() <= ROOT_NIBBLE_HEIGHT / 2);
let num_nibbles = bytes.len() * 2;
NibblePath { num_nibbles, bytes }
}

/// Similar to `new()` but assumes that the bytes have one less nibble.
// This function is currently only used in tests and fuzzing. Allow unused
// to avoid an awkward one-off #[cfg(feature...)], since it's conceptually similar to `new`
#[allow(unused)]
pub(crate) fn new_odd(bytes: Vec<u8>) -> Self {
pub fn new_odd(bytes: Vec<u8>) -> Self {
checked_precondition!(bytes.len() <= ROOT_NIBBLE_HEIGHT / 2);
assert_eq!(
bytes.last().expect("Should have odd number of nibbles.") & 0x0f,
Expand All @@ -120,7 +117,7 @@ impl NibblePath {
}

/// Adds a nibble to the end of the nibble path.
pub(crate) fn push(&mut self, nibble: Nibble) {
pub fn push(&mut self, nibble: Nibble) {
assert!(ROOT_NIBBLE_HEIGHT > self.num_nibbles);
if self.num_nibbles % 2 == 0 {
self.bytes.push(u8::from(nibble) << 4);
Expand All @@ -131,7 +128,7 @@ impl NibblePath {
}

/// Pops a nibble from the end of the nibble path.
pub(crate) fn pop(&mut self) -> Option<Nibble> {
pub fn pop(&mut self) -> Option<Nibble> {
let poped_nibble = if self.num_nibbles % 2 == 0 {
self.bytes.last_mut().map(|last_byte| {
let nibble = *last_byte & 0x0f;
Expand Down Expand Up @@ -198,7 +195,7 @@ impl NibblePath {
}

/// Get the underlying bytes storing nibbles.
pub(crate) fn bytes(&self) -> &[u8] {
pub fn bytes(&self) -> &[u8] {
&self.bytes
}
}
Expand Down

0 comments on commit 0c93cb9

Please sign in to comment.