aboutsummaryrefslogtreecommitdiff
path: root/src/numerics.cpp
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2024-07-26 17:00:59 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2024-07-26 17:00:59 +0100
commit8cbc60279937adcd8edfcb12866cd56ecd1f1376 (patch)
treeb231aa020a143215d919ccd74c6f209d50913567 /src/numerics.cpp
parentc96c4630d54ce4bff1e6786b4c882c50505fea21 (diff)
downloadcw_tree-8cbc60279937adcd8edfcb12866cd56ecd1f1376.tar.gz
cw_tree-8cbc60279937adcd8edfcb12866cd56ecd1f1376.tar.bz2
cw_tree-8cbc60279937adcd8edfcb12866cd56ecd1f1376.zip
Changed from int64_t to optional<word_t> for pointers in Node
Diffstat (limited to 'src/numerics.cpp')
-rw-r--r--src/numerics.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/numerics.cpp b/src/numerics.cpp
index f992873..608a724 100644
--- a/src/numerics.cpp
+++ b/src/numerics.cpp
@@ -43,7 +43,7 @@ bool Fraction::operator==(const Fraction &other)
return numerator == other.numerator && denominator == other.denominator;
}
-Node::Node(Fraction val, int64_t left, int64_t right)
+Node::Node(Fraction val, index_t left, index_t right)
: value{val}, left{left}, right{right}
{
}
@@ -107,10 +107,13 @@ void indent_depth(int depth, std::stringstream &ss)
ss << " ";
}
-std::string to_string(const NodeAllocator &allocator, const word_t n, int depth)
+std::string to_string(const NodeAllocator &allocator, const index_t n,
+ int depth)
{
+ if (!n.has_value())
+ return "NIL";
std::stringstream ss;
- Node x = allocator.vec[n];
+ Node x = allocator.getVal(n.value());
ss << "(" << to_string(x.value) << "\n";
indent_depth(depth, ss);
if (x.left == -1)