Merge pull request #96 from nuttycom/frontier_size

incrementalmerkletree: Add `Frontier::tree_size`
This commit is contained in:
Kris Nuttycombe 2024-03-09 17:08:33 -07:00 committed by GitHub
commit 643e4ee5c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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> {