Skip to content

Commit

Permalink
chore: make input public
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Oct 1, 2024
1 parent aa3a1ff commit d07ba1d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
16 changes: 10 additions & 6 deletions src/hash_builder/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use core::fmt;
///
/// Stores [`HashBuilderInputRef`] efficiently by reusing resources.
#[derive(Clone)]
pub(crate) struct HashBuilderInput {
pub struct HashBuilderInput {
/// Stores the bytes of either the leaf node value or the hash of adjacent nodes.
buf: Vec<u8>,
/// The kind of the current hash builder input.
Expand All @@ -26,8 +26,9 @@ impl fmt::Debug for HashBuilderInput {
}

impl HashBuilderInput {
/// Returns the input as a reference.
#[inline]
pub(crate) fn as_ref(&self) -> HashBuilderInputRef<'_> {
pub fn as_ref(&self) -> HashBuilderInputRef<'_> {
match self.kind {
HashBuilderInputKind::Bytes => HashBuilderInputRef::Bytes(&self.buf),
HashBuilderInputKind::Hash => {
Expand All @@ -37,15 +38,17 @@ impl HashBuilderInput {
}
}

/// Sets the input from the given bytes.
#[inline]
pub(crate) fn set_from_ref(&mut self, input: HashBuilderInputRef<'_>) {
pub fn set_from_ref(&mut self, input: HashBuilderInputRef<'_>) {
self.buf.clear();
self.buf.extend_from_slice(input.as_slice());
self.kind = input.kind();
}

/// Clears the input.
#[inline]
pub(crate) fn clear(&mut self) {
pub fn clear(&mut self) {
self.buf.clear();
self.kind = HashBuilderInputKind::default();
}
Expand All @@ -62,15 +65,16 @@ enum HashBuilderInputKind {
}

/// The input of the hash builder.
pub(crate) enum HashBuilderInputRef<'a> {
pub enum HashBuilderInputRef<'a> {
/// Value of the leaf node.
Bytes(&'a [u8]),
/// Hash of adjacent nodes.
Hash(&'a B256),
}

impl<'a> HashBuilderInputRef<'a> {
pub(crate) const fn as_slice(&self) -> &'a [u8] {
/// Returns the input as a slice.
pub const fn as_slice(&self) -> &'a [u8] {
match *self {
HashBuilderInputRef::Bytes(bytes) => bytes,
HashBuilderInputRef::Hash(hash) => hash.as_slice(),
Expand Down
5 changes: 2 additions & 3 deletions src/hash_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use tracing::trace;
use alloc::vec::Vec;

mod input;
use input::{HashBuilderInput, HashBuilderInputRef};
pub use input::{HashBuilderInput, HashBuilderInputRef};

/// A component used to construct the root hash of the trie.
///
Expand Down Expand Up @@ -44,9 +44,8 @@ use input::{HashBuilderInput, HashBuilderInputRef};
#[derive(Debug, Default)]
#[allow(missing_docs)]
pub struct HashBuilder {
input: HashBuilderInput,

pub key: Nibbles,
pub input: HashBuilderInput,
pub stack: Vec<Vec<u8>>,

pub groups: Vec<TrieMask>,
Expand Down

0 comments on commit d07ba1d

Please sign in to comment.