2025-11-17 01:22:45 +00:00
2025-11-17 01:22:45 +00:00
2024-07-26 02:54:02 +01:00
2024-07-26 03:15:09 +01:00
2024-07-26 02:54:02 +01:00
2024-07-26 03:17:09 +01:00
2025-11-17 01:22:45 +00:00

Calkin-Wilf trees

A graphical visualisation of Calkin-Wilf trees.

Currently visualises it using a self adjusting number line, from the smallest fraction to the largest fraction generated. Both are always positive.

The bound fractions are drawn in white, while all other fractions are in red. On any one iteration (taking any one fraction and generating its two children fractions), the generated fractions are in blue while the generator fraction is in green.

This was done just for fun really, but it's quite fun to see it generate a dense number line over many iterations.

TODOs

TODO Multithreading

SCHEDULED: <2025-11-18 Tue> Currently single threaded. A multithreaded implementation could have multiple nodes generated at once, which would speed up the implementation.

Might need to study my current implementation to see if it could be 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

It's a big blob of code currently in the graphics portion. Not very pretty but it gets the job done. Try modularisation.

TODO Tree visualisation

Instead of a number line, how about visualising the actual tree at work as a graph of nodes? Maybe colouring nodes based on where it is on the number line.

Description
No description provided
Readme MIT 1.2 MiB
Languages
C 96.1%
C++ 3.8%
Shell 0.1%