Avoid a few usize-u8 comparisons.
This commit is contained in:
parent
ea1686e8f8
commit
667c57a835
|
@ -477,9 +477,9 @@ impl<H: Hashable + Clone, const DEPTH: u8> CommitmentTree<H, DEPTH> {
|
||||||
.iter()
|
.iter()
|
||||||
.chain(repeat(&None))
|
.chain(repeat(&None))
|
||||||
.take((depth - 1).into())
|
.take((depth - 1).into())
|
||||||
.enumerate()
|
.zip(0u8..)
|
||||||
.fold(leaf_root, |root, (i, p)| {
|
.fold(leaf_root, |root, (p, i)| {
|
||||||
let level = Level::from(i as u8 + 1);
|
let level = Level::from(i + 1);
|
||||||
match p {
|
match p {
|
||||||
Some(node) => H::combine(level, node, &root),
|
Some(node) => H::combine(level, node, &root),
|
||||||
None => H::combine(level, &root, &filler.next(level)),
|
None => H::combine(level, &root, &filler.next(level)),
|
||||||
|
|
|
@ -499,13 +499,12 @@ impl<H: Hashable, const DEPTH: u8> MerklePath<H, DEPTH> {
|
||||||
pub fn root(&self, leaf: H) -> H {
|
pub fn root(&self, leaf: H) -> H {
|
||||||
self.path_elems
|
self.path_elems
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.zip(0u8..)
|
||||||
.fold(leaf, |root, (i, h)| {
|
.fold(leaf, |root, (h, i)| {
|
||||||
let level = Level(i as u8);
|
|
||||||
if (self.position.0 >> i) & 0x1 == 0 {
|
if (self.position.0 >> i) & 0x1 == 0 {
|
||||||
H::combine(level, &root, h)
|
H::combine(i.into(), &root, h)
|
||||||
} else {
|
} else {
|
||||||
H::combine(level, h, &root)
|
H::combine(i.into(), h, &root)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -195,17 +195,17 @@ impl<H: Hashable + Clone, const DEPTH: u8> IncrementalWitness<H, DEPTH> {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i, p) in self
|
for (p, i) in self
|
||||||
.tree
|
.tree
|
||||||
.parents
|
.parents
|
||||||
.iter()
|
.iter()
|
||||||
.chain(repeat(&None))
|
.chain(repeat(&None))
|
||||||
.take((depth - 1).into())
|
.take((depth - 1).into())
|
||||||
.enumerate()
|
.zip(0u8..)
|
||||||
{
|
{
|
||||||
auth_path.push(match p {
|
auth_path.push(match p {
|
||||||
Some(node) => node.clone(),
|
Some(node) => node.clone(),
|
||||||
None => filler.next(Level::from((i + 1) as u8)),
|
None => filler.next(Level::from(i + 1)),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue