aboutsummaryrefslogtreecommitdiff
path: root/reference_impl/reference_impl.rs
diff options
context:
space:
mode:
Diffstat (limited to 'reference_impl/reference_impl.rs')
-rw-r--r--reference_impl/reference_impl.rs9
1 files changed, 5 insertions, 4 deletions
diff --git a/reference_impl/reference_impl.rs b/reference_impl/reference_impl.rs
index 1ecf71e..486a1e2 100644
--- a/reference_impl/reference_impl.rs
+++ b/reference_impl/reference_impl.rs
@@ -283,12 +283,13 @@ impl Hasher {
// right edge of the growing tree. For each completed subtree, pop its
// left child CV off the stack and compress a new parent CV. After as
// many parent compressions as possible, push the new CV onto the
- // stack. The final length of the stack will be the count of 1 bits in
- // the total number of chunks so far.
- let final_stack_len = total_chunks.count_ones() as u8;
- while self.cv_stack_len >= final_stack_len {
+ // stack. The number of completed subtrees is the same as the number of
+ // trailing 0 bits in the total number of chunks so far.
+ let mut trailing_bit_mask = 1;
+ while total_chunks & trailing_bit_mask == 0 {
cv = parent_output(&self.pop_stack(), &cv, &self.key, self.chunk_state.flags)
.chaining_value();
+ trailing_bit_mask <<= 1;
}
self.push_stack(&cv);
}