From ce5bc7cb1306a4321fa76b03c325899862b6788f Mon Sep 17 00:00:00 2001 From: Ihor Chovpan <67230858+chopikus@users.noreply.github.com> Date: Thu, 20 Jun 2024 19:13:20 -0400 Subject: [PATCH] Update index.html --- game-of-life-explanation/index.html | 76 ++++++++++++++--------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/game-of-life-explanation/index.html b/game-of-life-explanation/index.html index 689aed5..bb9b6f0 100644 --- a/game-of-life-explanation/index.html +++ b/game-of-life-explanation/index.html @@ -100,22 +100,22 @@
This Node class structure works well enough:
- struct Node {
- /* ____
- / \
- |A B|
- |C D|
- \___/
- */
- uint8_t kn; // first bit n, rest bits -- k
- std::shared_ptr<Node> a,b,c,d;
- uint64_t hash; // precomputed
-
- auto operator<=>(const Node&) const = default;
-
- uint8_t k() const;
- bool n() const;
- };
+ struct Node {
+ /* ____
+ / \
+ |A B|
+ |C D|
+ \___/
+ */
+ uint8_t kn; // first bit n, rest bits -- k
+ std::shared_ptr<Node> a,b,c,d;
+ uint64_t hash; // precomputed
+
+ auto operator<=>(const Node&) const = default;
+
+ uint8_t k() const;
+ bool n() const;
+ };
To prevent memory leaks and easily track Node's reference count, std::shared_ptr
is used.
@@ -127,28 +127,28 @@
In code it looks roughly like this:
- /*Following function pushes coordinates of ON cells in node up with (2^level):1 precision.*/
- void Hashlife::_append_alive_cells(const NodePtr& node, std::vector<Cell>& output,
- uint8_t level,
- int64_t x, int64_t y,
- int64_t min_x, int64_t min_y,
- int64_t max_x, int64_t max_y) {
- /* if current node doesn't have any ON cells, pass*/
- if (!node->n()) {
- return;
- }
-
- if (node->k() == level) {
- output.push_back({x, y});
- return;
- }
-
- int64_t offset = size >> 1;
- _append_alive_cells(node->a, output, level, x, y, min_x, min_y, max_x, max_y);
- _append_alive_cells(node->b, output, level, x + offset, y, min_x, min_y, max_x, max_y);
- _append_alive_cells(node->c, output, level, x, y + offset, min_x, min_y, max_x, max_y);
- _append_alive_cells(node->d, output, level, x + offset, y + offset, min_x, min_y, max_x, max_y);
- }
+ /*Following function pushes coordinates of ON cells in node up with (2^level):1 precision.*/
+ void Hashlife::_append_alive_cells(const NodePtr& node, std::vector<Cell>& output,
+ uint8_t level,
+ int64_t x, int64_t y,
+ int64_t min_x, int64_t min_y,
+ int64_t max_x, int64_t max_y) {
+ /* if current node doesn't have any ON cells, pass*/
+ if (!node->n()) {
+ return;
+ }
+
+ if (node->k() == level) {
+ output.push_back({x, y});
+ return;
+ }
+
+ int64_t offset = size >> 1;
+ _append_alive_cells(node->a, output, level, x, y, min_x, min_y, max_x, max_y);
+ _append_alive_cells(node->b, output, level, x + offset, y, min_x, min_y, max_x, max_y);
+ _append_alive_cells(node->c, output, level, x, y + offset, min_x, min_y, max_x, max_y);
+ _append_alive_cells(node->d, output, level, x + offset, y + offset, min_x, min_y, max_x, max_y);
+ }