Add some notes
This commit is contained in:
19
README.org
19
README.org
@@ -1,6 +1,7 @@
|
|||||||
#+title: Calkin-Wilf trees
|
#+title: Calkin-Wilf trees
|
||||||
#+author: Aryadev Chavali
|
#+author: Aryadev Chavali
|
||||||
#+date: 2024-07-27
|
#+date: 2024-07-27
|
||||||
|
#+filetags: cpp cw_tree
|
||||||
|
|
||||||
A graphical visualisation of
|
A graphical visualisation of
|
||||||
[[https://en.wikipedia.org/wiki/Calkin%E2%80%93Wilf_tree][Calkin-Wilf
|
[[https://en.wikipedia.org/wiki/Calkin%E2%80%93Wilf_tree][Calkin-Wilf
|
||||||
@@ -19,12 +20,30 @@ This was done just for fun really, but it's quite fun to see it
|
|||||||
generate a dense number line over many iterations.
|
generate a dense number line over many iterations.
|
||||||
* TODOs
|
* TODOs
|
||||||
** TODO Multithreading
|
** TODO Multithreading
|
||||||
|
SCHEDULED: <2025-11-18 Tue>
|
||||||
Currently single threaded. A multithreaded implementation could have
|
Currently single threaded. A multithreaded implementation could have
|
||||||
multiple nodes generated at once, which would speed up the
|
multiple nodes generated at once, which would speed up the
|
||||||
implementation.
|
implementation.
|
||||||
|
|
||||||
Might need to study my current implementation to see if it could be
|
Might need to study my current implementation to see if it could be
|
||||||
done better.
|
done better.
|
||||||
|
|
||||||
|
2025-11-17: Notes:
|
||||||
|
- Mutex on the queue [[file:src/main.cpp::std::queue<word_t>
|
||||||
|
iteration_queue;][the queue]] and the allocator will be necessary.
|
||||||
|
- Perhaps we could do two mutexes, one per structure?
|
||||||
|
- We'd need to lock for [[file:src/numerics.cpp::std::tuple<Fraction,
|
||||||
|
Fraction, Fraction> iterate(std::queue<word_t> &queue,][iterate]]
|
||||||
|
- Locking scheme could be:
|
||||||
|
- Lock queue when popping a value as root, then unlock.
|
||||||
|
- Leave queue and allocator unlocked while getting root/left/right
|
||||||
|
values (readonly) and computing (but not setting/allocating) the
|
||||||
|
left and right node values
|
||||||
|
- Allocator Lock when allocating the left/right values, setting the
|
||||||
|
root's left and right, then unlock.
|
||||||
|
- Queue lock when pushing the left and right fractions for further
|
||||||
|
processing, then unlock
|
||||||
|
- Unlock all when returning relevant values
|
||||||
** TODO Prettify code base
|
** TODO Prettify code base
|
||||||
It's a big blob of code currently in the graphics portion. Not very
|
It's a big blob of code currently in the graphics portion. Not very
|
||||||
pretty but it gets the job done. Try modularisation.
|
pretty but it gets the job done. Try modularisation.
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
#define LINE_TOP (7 * HEIGHT / 16)
|
#define LINE_TOP (7 * HEIGHT / 16)
|
||||||
#define LINE_BOTTOM (9 * HEIGHT / 16)
|
#define LINE_BOTTOM (9 * HEIGHT / 16)
|
||||||
|
|
||||||
std::pair<std::string, int> get_fraction_drawable(Fraction f)
|
std::pair<std::string, int> fraction_to_string(Fraction f)
|
||||||
{
|
{
|
||||||
std::string s{to_string(f)};
|
std::string s{to_string(f)};
|
||||||
int width = MeasureText(s.c_str(), FONT_SIZE);
|
int width = MeasureText(s.c_str(), FONT_SIZE);
|
||||||
@@ -44,7 +44,7 @@ void draw_fraction(Fraction f, word_t x, word_t y)
|
|||||||
{
|
{
|
||||||
std::string s;
|
std::string s;
|
||||||
int width;
|
int width;
|
||||||
std::tie(s, width) = get_fraction_drawable(f);
|
std::tie(s, width) = fraction_to_string(f);
|
||||||
// Centered at (x, y)
|
// Centered at (x, y)
|
||||||
DrawText(s.c_str(), x - width / 2, y - FONT_SIZE, FONT_SIZE, WHITE);
|
DrawText(s.c_str(), x - width / 2, y - FONT_SIZE, FONT_SIZE, WHITE);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user