iterate now returns a tuple of the three fractions worked on
The left, currently processed (centre) and right fractions are returned by iterate. This allows us to see exactly what fractions have been generated/worked on in every iteration.
This commit is contained in:
@@ -86,7 +86,8 @@ word_t gcd(word_t a, word_t b)
|
|||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
Fraction iterate(std::queue<word_t> &queue, NodeAllocator &allocator)
|
std::tuple<Fraction, Fraction, Fraction> iterate(std::queue<word_t> &queue,
|
||||||
|
NodeAllocator &allocator)
|
||||||
{
|
{
|
||||||
if (queue.empty())
|
if (queue.empty())
|
||||||
return {};
|
return {};
|
||||||
@@ -105,10 +106,10 @@ Fraction iterate(std::queue<word_t> &queue, NodeAllocator &allocator)
|
|||||||
queue.pop();
|
queue.pop();
|
||||||
queue.push(allocator.getVal(index).left.value());
|
queue.push(allocator.getVal(index).left.value());
|
||||||
queue.push(allocator.getVal(index).right.value());
|
queue.push(allocator.getVal(index).right.value());
|
||||||
node = allocator.getVal(index);
|
node = allocator.getVal(index);
|
||||||
Fraction best = MAX(node.value, allocator.getVal(node.left.value()).value);
|
// NOTE: We can be assured that left and right DO have values
|
||||||
best = MAX(best, allocator.getVal(node.right.value()).value);
|
return std::tuple(allocator.getVal(node.left.value()).value, node.value,
|
||||||
return best;
|
allocator.getVal(node.right.value()).value);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string to_string(const Fraction &f)
|
std::string to_string(const Fraction &f)
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include <optional>
|
#include <optional>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <tuple>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#define MIN(A, B) ((A) < (B) ? (A) : (B))
|
#define MIN(A, B) ((A) < (B) ? (A) : (B))
|
||||||
@@ -59,7 +60,8 @@ struct NodeAllocator
|
|||||||
};
|
};
|
||||||
|
|
||||||
word_t gcd(word_t a, word_t b);
|
word_t gcd(word_t a, word_t b);
|
||||||
Fraction iterate(std::queue<word_t> &queue, NodeAllocator &allocator);
|
std::tuple<Fraction, Fraction, Fraction> iterate(std::queue<word_t> &queue,
|
||||||
|
NodeAllocator &allocator);
|
||||||
|
|
||||||
std::string to_string(const Fraction &);
|
std::string to_string(const Fraction &);
|
||||||
std::string to_string(const NodeAllocator &, const index_t, int depth = 1);
|
std::string to_string(const NodeAllocator &, const index_t, int depth = 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user