Skip to content

Commit fb6bb69

Browse files
feat!: MerkleTree-specific Type Aliases (#251)
This PR introduces type aliases: - `MerkleTreeNodeIndex` for `usize` - `MerkleTreeLeafIndex` for `usize` - `MerkleTreeHeight` for `u32` with the objective of documenting the conventions for arithmetic with these index types. Also: - Public function `nodes()` dropped in favor of `node(i)`. - Public function `leafs()` now returns an iterator instead of a slice. - Private function `authentication_structure_node_indices` is marked `pub` as it is needed downstream. Displaces #250. --------- Co-authored-by: Jan Ferdinand Sauer <ferdinand@neptune.cash>
1 parent 8c942b4 commit fb6bb69

File tree

5 files changed

+178
-110
lines changed

5 files changed

+178
-110
lines changed

twenty-first/benches/merkle_tree_authenticate.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ impl Default for MerkleTreeSampler {
5656
}
5757

5858
impl MerkleTreeSampler {
59-
fn num_leafs(&self) -> usize {
60-
1 << self.tree_height
59+
fn num_leafs(&self) -> MerkleTreeLeafIndex {
60+
(1 << self.tree_height) as MerkleTreeLeafIndex
6161
}
6262

6363
fn leaf_digests(&mut self) -> Vec<Digest> {
@@ -72,7 +72,7 @@ impl MerkleTreeSampler {
7272
MerkleTree::par_new(&leaf_digests).unwrap()
7373
}
7474

75-
fn indices_to_open(&mut self) -> Vec<usize> {
75+
fn indices_to_open(&mut self) -> Vec<MerkleTreeLeafIndex> {
7676
(0..self.num_opened_indices)
7777
.map(|_| self.rng.random_range(0..self.num_leafs()))
7878
.collect()

0 commit comments

Comments
 (0)