aboutsummaryrefslogtreecommitdiff
path: root/src/numerics.cpp
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2024-07-27 01:23:31 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2024-07-27 01:23:31 +0100
commit1c06a4b61303bf18d4ff72ff959074e17e1dd25a (patch)
tree80ad9e82453c10e9f48cd0a7aa9f4a391bb2d71d /src/numerics.cpp
parent32314708d564c5e7373f6f5f543c4768f856931c (diff)
downloadcw_tree-1c06a4b61303bf18d4ff72ff959074e17e1dd25a.tar.gz
cw_tree-1c06a4b61303bf18d4ff72ff959074e17e1dd25a.tar.bz2
cw_tree-1c06a4b61303bf18d4ff72ff959074e17e1dd25a.zip
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.
Diffstat (limited to 'src/numerics.cpp')
-rw-r--r--src/numerics.cpp11
1 files changed, 6 insertions, 5 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)