Commit Graph

21 Commits

Author SHA1 Message Date
Aryadev Chavali
4cc1af94f6 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.
2024-07-26 03:13:24 +01:00
Aryadev Chavali
84c07870e4 Rework MAX macro to use < operator
MAX now works with Fraction's
2024-07-26 03:13:14 +01:00
Aryadev Chavali
7f7a609d30 Introduce normalised value in fraction class
Bit of a cheat but it would allow us to do some interesting graphical
stuff later.
2024-07-26 03:11:58 +01:00
Aryadev Chavali
f58a7e80ef Add numerics to build system
Successfully compiles and runs!
2024-07-26 02:59:48 +01:00
Aryadev Chavali
6a6ed5a545 Change main to use new numerics module. 2024-07-26 02:59:38 +01:00
Aryadev Chavali
8207d49211 Implemented numerics in numerics.cpp
Simple implementation, few refactors from the main.cpp version based
on API changes.
2024-07-26 02:59:31 +01:00
Aryadev Chavali
139f2e9e5a Rework node constructor and general procedure API
Node constructor is now completely default constructed i.e. no
constructor arguments required.  The iterate function takes the queue
by reference, so it can update the caller's state.

Finally, to_string for a Node now uses the node allocator and an index
to print out trees.  Seems simpler and more in line with the current
implementation.
2024-07-26 02:55:58 +01:00
Aryadev Chavali
d73ecff38a Made header file for a separate numerics file
Separates the (basically) completed cw_tree implementation in a
separate module so we can spend time implementing graphics in main.

NOTE: nodes are now generated from a node allocator, which just wraps
around the vector.  We also take an allocator and queue by reference
in the iterate procedure now.
2024-07-26 02:54:02 +01:00
Aryadev Chavali
9ea4341a80 A simple test, iterating 10 times and printing out the generated tree
Seems to work!
2024-07-26 02:54:02 +01:00
Aryadev Chavali
93d3ce89cc Fix up indenting and empty children in to_string for node 2024-07-26 02:54:02 +01:00
Aryadev Chavali
6dfd820772 Added to_string for Nodes
Recursive implementation with proper indenting!
2024-07-26 02:54:02 +01:00
Aryadev Chavali
5cbdf7a045 Added to_string for fractions 2024-07-26 02:54:02 +01:00
Aryadev Chavali
aad22a1b20 Rework binary tree to use indexes in nodes vector
An index is a pointer, and they don't change if the vector decides to
reallocate internally unlike the bastardised pointers I was rolling up
before.  This simplifies design a bit.
2024-07-26 02:54:02 +01:00
Aryadev Chavali
cb0d4f5207 Added helper method to allocate nodes from the vector for me
The vector acts as an arena for the nodes to be allocated from, better
and faster than allocating each child on the heap individually.
2024-07-26 02:54:02 +01:00
Aryadev Chavali
ee1cc0816a Queue based iteration procedure
Pops an item off the queue and generate left and right children for it,
if those are empty.  Then push those children into the queue for the
next iteration.

NOTE: Because we're using a queue, this does a breadth first
generation of the tree, which is what we want.
2024-07-26 02:54:02 +01:00
Aryadev Chavali
9769337a92 Binary tree of fractions
Will be used in creating the cw tree.
2024-07-26 02:54:02 +01:00
Aryadev Chavali
cc51f78d10 Simplify at constructor in Fraction
Let's just deal with simplified stuff anyway?
2024-07-26 02:54:02 +01:00
Aryadev Chavali
6d64f5ebac Added comparators to Fraction struct 2024-07-26 02:54:02 +01:00
Aryadev Chavali
f64a82c538 Extracted gcd algorithm into its own function 2024-07-26 02:54:02 +01:00
Aryadev Chavali
0727126061 Simple fraction structure
Holds numerator and denominator.  Can self simplify, but not
automatically.
2024-07-26 02:54:02 +01:00
Aryadev Chavali
6f7be667e2 Hello, world! 2024-07-26 02:54:02 +01:00