Make appending algorithm more succinct.
This commit is contained in:
parent
d0c4b0e850
commit
9b92a9d5fb
|
@ -93,21 +93,19 @@ 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 {
|
} else {
|
||||||
parent = *combined;
|
parents[i] = *combined;
|
||||||
combined = boost::none;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
|
||||||
if (combined) {
|
|
||||||
// Create a new parent
|
|
||||||
parents.push_back(combined);
|
parents.push_back(combined);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue