From 7bdb59e386b93c37cdc2c2b88fc2945ab0e64d57 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Wed, 25 Jun 2025 10:18:23 +0200 Subject: Increase tree's speed avoiding to store data in a vec --- src/node.rs | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'src/node.rs') diff --git a/src/node.rs b/src/node.rs index e7e6b0f..e784a69 100644 --- a/src/node.rs +++ b/src/node.rs @@ -43,8 +43,6 @@ pub struct Node { hash: String, /// Type of the node: leaf or internal. status: NodeStatus, - /// Data in bytes. - data: Vec, } impl Node { @@ -53,11 +51,9 @@ impl Node { /// # Arguments /// /// * `hasher` - A reference to a hashing strategy. - /// * `data` - The data to be hashed and stored as a leaf. - pub fn new_leaf(data: &[u8], hash: String) -> Self { + pub fn new_leaf(hash: String) -> Self { Self { hash, - data: data.to_vec(), status: NodeStatus::Leaf, } } @@ -66,17 +62,16 @@ impl Node { /// /// # Arguments /// - /// * `hasher` - A reference to a hashing strategy. + /// * `hash` - An hash value for the following node. /// * `left` - Left child node. /// * `right` - Right child node. /// /// # Behavior /// /// The internal node hash is computed as the hash of the concatenated children's hashes. - pub fn new_internal(data: &[u8], hash: String, left: Node, right: Node) -> Self { + pub fn new_internal(hash: String, left: Node, right: Node) -> Self { Self { hash, - data: data.to_vec(), status: NodeStatus::Internal(Box::new(left), Box::new(right)), } } @@ -86,11 +81,6 @@ impl Node { &self.hash } - /// Returns the data value in bytes format. - pub fn data(&self) -> &[u8] { - &self.data - } - /// Returns a reference to the node's type (leaf or internal). pub fn status(&self) -> &NodeStatus { &self.status -- cgit v1.2.3-71-g8e6c