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;
right = boost::none;
// Propagate up the tree as much as needed
BOOST_FOREACH(boost::optional<Hash>& parent, parents) {
if (parent) {
combined = Hash::combine(*parent, *combined);
parent = boost::none;
for (size_t i = 0; i < Depth; i++) {
if (i < parents.size()) {
if (parents[i]) {
combined = Hash::combine(*parents[i], *combined);
parents[i] = boost::none;
} else {
parents[i] = *combined;
break;
}
} else {
parent = *combined;
combined = boost::none;
parents.push_back(combined);
break;
}
}
if (combined) {
// Create a new parent
parents.push_back(combined);
}
}
}