incrementalmerkletree: Add `Frontier::tree_size`

This commit is contained in:
Kris Nuttycombe 2024-03-09 11:22:50 -07:00
parent 4d797cce13
commit 353db2efa2
2 changed files with 10 additions and 0 deletions

View File

@ -7,6 +7,9 @@ and this project adheres to Rust's notion of
## Unreleased
### Added
- `incrementalmerkletree::Frontier::tree_size`
## [0.5.0] - 2023-09-08
### Added

View File

@ -225,6 +225,13 @@ impl<H, const DEPTH: u8> Frontier<H, DEPTH> {
size_of::<usize>() + (f.ommers.capacity() + 1) * size_of::<H>()
})
}
/// Returns the size of the Merkle tree that this frontier corresponds to.
pub fn tree_size(&self) -> u64 {
self.frontier
.as_ref()
.map_or(0, |f| u64::from(f.position()) + 1)
}
}
impl<H: Hashable + Clone, const DEPTH: u8> Frontier<H, DEPTH> {