Avoid a few usize-u8 comparisons.

This commit is contained in:
Kris Nuttycombe 2023-05-04 12:49:16 -06:00
parent ea1686e8f8
commit 667c57a835
3 changed files with 10 additions and 11 deletions

View File

@ -477,9 +477,9 @@ impl<H: Hashable + Clone, const DEPTH: u8> CommitmentTree<H, DEPTH> {
.iter()
.chain(repeat(&None))
.take((depth - 1).into())
.enumerate()
.fold(leaf_root, |root, (i, p)| {
let level = Level::from(i as u8 + 1);
.zip(0u8..)
.fold(leaf_root, |root, (p, i)| {
let level = Level::from(i + 1);
match p {
Some(node) => H::combine(level, node, &root),
None => H::combine(level, &root, &filler.next(level)),

View File

@ -499,13 +499,12 @@ impl<H: Hashable, const DEPTH: u8> MerklePath<H, DEPTH> {
pub fn root(&self, leaf: H) -> H {
self.path_elems
.iter()
.enumerate()
.fold(leaf, |root, (i, h)| {
let level = Level(i as u8);
.zip(0u8..)
.fold(leaf, |root, (h, i)| {
if (self.position.0 >> i) & 0x1 == 0 {
H::combine(level, &root, h)
H::combine(i.into(), &root, h)
} else {
H::combine(level, h, &root)
H::combine(i.into(), h, &root)
}
})
}

View File

@ -195,17 +195,17 @@ impl<H: Hashable + Clone, const DEPTH: u8> IncrementalWitness<H, DEPTH> {
return None;
}
for (i, p) in self
for (p, i) in self
.tree
.parents
.iter()
.chain(repeat(&None))
.take((depth - 1).into())
.enumerate()
.zip(0u8..)
{
auth_path.push(match p {
Some(node) => node.clone(),
None => filler.next(Level::from((i + 1) as u8)),
None => filler.next(Level::from(i + 1)),
});
}