From 8b3844363783cdcaf9d56ace9fcadfbeb232cd1a Mon Sep 17 00:00:00 2001 From: rymnc <43716372+rymnc@users.noreply.github.com> Date: Wed, 10 May 2023 04:39:04 +0530 Subject: [PATCH] fix: public getter --- src/tree.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/tree.rs b/src/tree.rs index 5bfe23e..2103b1b 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -136,7 +136,7 @@ where } // Recalculates `Merkle Tree` from the specified key - fn recalculate_from(&mut self, key: usize) -> PmtreeResult<()> { + pub fn recalculate_from(&mut self, key: usize) -> PmtreeResult<()> { let mut depth = self.depth; let mut i = key; @@ -174,6 +174,15 @@ where Ok(res) } + // Returns the leaf by the key + pub fn get(&self, key: usize) -> PmtreeResult { + if key >= self.capacity() { + return Err(PmtreeErrorKind::TreeError(TreeErrorKind::IndexOutOfBounds)); + } + + self.get_elem(Key(self.depth, key)) + } + /// Deletes a leaf at the `key` by setting it to its default value pub fn delete(&mut self, key: usize) -> PmtreeResult<()> { if key >= self.next_index {