iterate now computes highest value fraction it generated.
Not very useful, but isn't a massive performance waster (I think) and it will be useful when thinking about colour schemes in graphics.
This commit is contained in:
@@ -69,10 +69,10 @@ word_t gcd(word_t a, word_t b)
|
|||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
void iterate(std::queue<word_t> &queue, NodeAllocator &allocator)
|
Fraction iterate(std::queue<word_t> &queue, NodeAllocator &allocator)
|
||||||
{
|
{
|
||||||
if (queue.empty())
|
if (queue.empty())
|
||||||
return;
|
return {};
|
||||||
word_t index = queue.front();
|
word_t index = queue.front();
|
||||||
Node node = allocator.vec[index];
|
Node node = allocator.vec[index];
|
||||||
if (node.left == -1)
|
if (node.left == -1)
|
||||||
@@ -88,6 +88,10 @@ void iterate(std::queue<word_t> &queue, NodeAllocator &allocator)
|
|||||||
queue.pop();
|
queue.pop();
|
||||||
queue.push(allocator.vec[index].left);
|
queue.push(allocator.vec[index].left);
|
||||||
queue.push(allocator.vec[index].right);
|
queue.push(allocator.vec[index].right);
|
||||||
|
node = allocator.vec[index];
|
||||||
|
Fraction best = MAX(node.value, allocator.vec[node.left].value);
|
||||||
|
best = MAX(best, allocator.vec[node.right].value);
|
||||||
|
return best;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string to_string(const Fraction &f)
|
std::string to_string(const Fraction &f)
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ struct NodeAllocator
|
|||||||
};
|
};
|
||||||
|
|
||||||
word_t gcd(word_t a, word_t b);
|
word_t gcd(word_t a, word_t b);
|
||||||
void iterate(std::queue<word_t> &queue, NodeAllocator &allocator);
|
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 word_t, int depth = 1);
|
std::string to_string(const NodeAllocator &, const word_t, int depth = 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user