Rework node constructor and general procedure API

Node constructor is now completely default constructed i.e. no
constructor arguments required.  The iterate function takes the queue
by reference, so it can update the caller's state.

Finally, to_string for a Node now uses the node allocator and an index
to print out trees.  Seems simpler and more in line with the current
implementation.
This commit is contained in:
2024-07-26 02:55:58 +01:00
parent d73ecff38a
commit 139f2e9e5a

View File

@@ -41,7 +41,7 @@ struct Node
Fraction value;
int64_t left, right;
Node(Fraction val, int64_t left = -1, int64_t right = -1);
Node(Fraction val = {}, int64_t left = -1, int64_t right = -1);
};
struct NodeAllocator
@@ -53,9 +53,9 @@ struct NodeAllocator
};
word_t gcd(word_t a, word_t b);
void iterate(std::queue<word_t> queue, NodeAllocator &allocator);
void iterate(std::queue<word_t> &queue, NodeAllocator &allocator);
std::string to_string(const Fraction &);
std::string to_string(const Node &, int depth = 1);
std::string to_string(const NodeAllocator &, const word_t, int depth = 1);
#endif