aboutsummaryrefslogtreecommitdiff
path: root/reference_impl/reference_impl.rs
diff options
context:
space:
mode:
authorJack O'Connor <[email protected]>2019-12-22 16:27:27 -0500
committerJack O'Connor <[email protected]>2019-12-22 16:31:47 -0500
commite800e0659fa953cbd1d2d10716dace4498c8f94a (patch)
tree14fc9c81f5a178de2793ad72bfae3f055d856ee5 /reference_impl/reference_impl.rs
parent5fb359023cf0001d1dd568d8d3ba79556d44c1c2 (diff)
rework push_chunk_chaining_value in terms of trailing 0's
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);
}