aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/numerics.cpp11
-rw-r--r--src/numerics.hpp4
2 files changed, 9 insertions, 6 deletions
diff --git a/src/numerics.cpp b/src/numerics.cpp
index 33ee5ab..db8003c 100644
--- a/src/numerics.cpp
+++ b/src/numerics.cpp
@@ -86,7 +86,8 @@ word_t gcd(word_t a, word_t b)
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())
return {};
@@ -105,10 +106,10 @@ Fraction iterate(std::queue<word_t> &queue, NodeAllocator &allocator)
queue.pop();
queue.push(allocator.getVal(index).left.value());
queue.push(allocator.getVal(index).right.value());
- node = allocator.getVal(index);
- Fraction best = MAX(node.value, allocator.getVal(node.left.value()).value);
- best = MAX(best, allocator.getVal(node.right.value()).value);
- return best;
+ node = allocator.getVal(index);
+ // NOTE: We can be assured that left and right DO have values
+ return std::tuple(allocator.getVal(node.left.value()).value, node.value,
+ allocator.getVal(node.right.value()).value);
}
std::string to_string(const Fraction &f)
diff --git a/src/numerics.hpp b/src/numerics.hpp
index d437cab..6d6004c 100644
--- a/src/numerics.hpp
+++ b/src/numerics.hpp
@@ -22,6 +22,7 @@
#include <optional>
#include <queue>
#include <string>
+#include <tuple>
#include <vector>
#define MIN(A, B) ((A) < (B) ? (A) : (B))
@@ -59,7 +60,8 @@ struct NodeAllocator
};
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 NodeAllocator &, const index_t, int depth = 1);