Skip to content

Commit

Permalink
Merge pull request #96 from nuttycom/frontier_size
Browse files Browse the repository at this point in the history
incrementalmerkletree: Add `Frontier::tree_size`
  • Loading branch information
nuttycom authored Mar 10, 2024
2 parents 4d797cc + 353db2e commit 643e4ee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions incrementalmerkletree/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions incrementalmerkletree/src/frontier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down

0 comments on commit 643e4ee

Please sign in to comment.