From 8e594963d2068df33ac321e3c5a9cf8b34c6128c Mon Sep 17 00:00:00 2001 From: Qyriad Date: Tue, 22 Oct 2024 17:16:38 -0600 Subject: [PATCH] merkle: add parent() helper function on NodeIndex --- src/merkle/index.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/merkle/index.rs b/src/merkle/index.rs index 104ceb4..24b3808 100644 --- a/src/merkle/index.rs +++ b/src/merkle/index.rs @@ -97,6 +97,14 @@ impl NodeIndex { self } + /// Returns the parent of the current node. This is the same as [`Self::move_up()`], but returns + /// a new value instead of mutating `self`. + pub const fn parent(mut self) -> Self { + self.depth = self.depth.saturating_sub(1); + self.value >>= 1; + self + } + // PROVIDERS // --------------------------------------------------------------------------------------------