Small nit fixes

This commit is contained in:
Sean Bowe 2016-04-29 10:05:06 -06:00
parent 6850b45e4d
commit 6f1b70300d
2 changed files with 8 additions and 11 deletions

View File

@ -53,12 +53,7 @@ void IncrementalMerkleTree<Depth, Hash>::wfcheck() const {
} }
// The last parent cannot be null. // The last parent cannot be null.
bool wasnull = false; if (!(parents.empty()) && !(parents.back())) {
BOOST_FOREACH(const boost::optional<Hash>& parent, parents) {
wasnull = !parent;
}
if (wasnull) {
throw std::ios_base::failure("tree has non-canonical representation of parent"); throw std::ios_base::failure("tree has non-canonical representation of parent");
} }
@ -89,7 +84,7 @@ void IncrementalMerkleTree<Depth, Hash>::append(Hash obj) {
// Combine the leaves and propagate it up the tree // Combine the leaves and propagate it up the tree
boost::optional<Hash> combined = Hash::combine(*left, *right); boost::optional<Hash> combined = Hash::combine(*left, *right);
// Set the left leaf to the object and make the right object none // Set the "left" leaf to the object and make the "right" leaf none
left = obj; left = obj;
right = boost::none; right = boost::none;
@ -261,7 +256,7 @@ MerklePath IncrementalMerkleTree<Depth, Hash>::path(std::deque<Hash> filler_hash
} }
template<size_t Depth, typename Hash> template<size_t Depth, typename Hash>
std::deque<Hash> IncrementalWitness<Depth, Hash>::uncle_train() const { std::deque<Hash> IncrementalWitness<Depth, Hash>::partial_path() const {
std::deque<Hash> uncles(filled.begin(), filled.end()); std::deque<Hash> uncles(filled.begin(), filled.end());
if (cursor) { if (cursor) {

View File

@ -68,6 +68,8 @@ public:
private: private:
boost::optional<Hash> left; boost::optional<Hash> left;
boost::optional<Hash> right; boost::optional<Hash> right;
// Collapsed "left" subtrees ordered toward the root of the tree.
std::vector<boost::optional<Hash>> parents; std::vector<boost::optional<Hash>> parents;
MerklePath path(std::deque<Hash> filler_hashes = std::deque<Hash>()) const; MerklePath path(std::deque<Hash> filler_hashes = std::deque<Hash>()) const;
Hash root(size_t depth, std::deque<Hash> filler_hashes = std::deque<Hash>()) const; Hash root(size_t depth, std::deque<Hash> filler_hashes = std::deque<Hash>()) const;
@ -82,11 +84,11 @@ friend class IncrementalMerkleTree<Depth, Hash>;
public: public:
MerklePath path() const { MerklePath path() const {
return tree.path(uncle_train()); return tree.path(partial_path());
} }
Hash root() const { Hash root() const {
return tree.root(Depth, uncle_train()); return tree.root(Depth, partial_path());
} }
void append(Hash obj); void append(Hash obj);
@ -107,7 +109,7 @@ private:
std::vector<Hash> filled; std::vector<Hash> filled;
boost::optional<IncrementalMerkleTree<Depth, Hash>> cursor; boost::optional<IncrementalMerkleTree<Depth, Hash>> cursor;
size_t cursor_depth; size_t cursor_depth;
std::deque<Hash> uncle_train() const; std::deque<Hash> partial_path() const;
IncrementalWitness(IncrementalMerkleTree<Depth, Hash> tree) : tree(tree) {} IncrementalWitness(IncrementalMerkleTree<Depth, Hash> tree) : tree(tree) {}
}; };