Make appending algorithm more succinct.

This commit is contained in:
Sean Bowe 2016-04-21 12:02:43 -06:00
parent d0c4b0e850
commit 9b92a9d5fb
1 changed files with 10 additions and 12 deletions

View File

@ -93,22 +93,20 @@ void IncrementalMerkleTree<Depth, Hash>::append(Hash obj) {
left = obj; left = obj;
right = boost::none; right = boost::none;
// Propagate up the tree as much as needed for (size_t i = 0; i < Depth; i++) {
BOOST_FOREACH(boost::optional<Hash>& parent, parents) { if (i < parents.size()) {
if (parent) { if (parents[i]) {
combined = Hash::combine(*parent, *combined); combined = Hash::combine(*parents[i], *combined);
parent = boost::none; parents[i] = boost::none;
} else {
parents[i] = *combined;
break;
}
} else { } else {
parent = *combined; parents.push_back(combined);
combined = boost::none;
break; break;
} }
} }
if (combined) {
// Create a new parent
parents.push_back(combined);
}
} }
} }