From a2a0abdcef0b3d2656606e2579f8c2f0f9ca47bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Mon, 2 Dec 2019 14:21:01 +0100 Subject: [PATCH] [poincare/TreeNode] Fix hasNode --- poincare/include/poincare/integer.h | 5 ++--- poincare/include/poincare/tree_handle.h | 2 +- poincare/include/poincare/tree_node.h | 3 ++- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/poincare/include/poincare/integer.h b/poincare/include/poincare/integer.h index a9a07e19b..294a5ed78 100644 --- a/poincare/include/poincare/integer.h +++ b/poincare/include/poincare/integer.h @@ -58,7 +58,7 @@ public: Integer(double_native_int_t i); Integer(const char * digits, size_t length, bool negative); Integer(const char * digits) : Integer(digits, strlen(digits), false) {} - static Integer Overflow(bool negative) { return Integer(OverflowIdentifier, negative); } + static Integer Overflow(bool negative) { return Integer(TreeNode::OverflowIdentifier, negative); } #if POINCARE_TREE_LOG void logInteger(std::ostream & stream) const { @@ -108,7 +108,7 @@ public: /* An integer can have (k_maxNumberOfDigits + 1) digits: either when it is an * overflow, or when we want to have one more digit than usual to compute a * big division. */ - bool isOverflow() const { return m_identifier == OverflowIdentifier; } + bool isOverflow() const { return m_identifier == TreeNode::OverflowIdentifier; } static int NumberOfBase10DigitsWithoutSign(const Integer & i); bool isOne() const { return (numberOfDigits() == 1 && digit(0) == 1 && !m_negative); }; bool isTwo() const { return (numberOfDigits() == 1 && digit(0) == 2 && !m_negative); }; @@ -140,7 +140,6 @@ public: constexpr static int k_maxNumberOfDigits = 32; private: constexpr static int k_maxNumberOfDigitsBase10 = 308; // (2^32)^k_maxNumberOfDigits ~ 1E308 - static constexpr int OverflowIdentifier = TreeNode::NoNodeIdentifier - 1; // Constructors Integer(native_uint_t * digits, uint16_t numberOfDigits, bool negative); diff --git a/poincare/include/poincare/tree_handle.h b/poincare/include/poincare/tree_handle.h index 341cc9818..44690899c 100644 --- a/poincare/include/poincare/tree_handle.h +++ b/poincare/include/poincare/tree_handle.h @@ -127,7 +127,7 @@ protected: void setIdentifierAndRetain(uint16_t newId); void setTo(const TreeHandle & tr); - static bool hasNode(uint16_t identifier) { return identifier > TreeNode::NoNodeIdentifier; } + static bool hasNode(uint16_t identifier) { return identifier < TreeNode::NoNodeIdentifier; } /* Hierarchy operations */ // Add diff --git a/poincare/include/poincare/tree_node.h b/poincare/include/poincare/tree_node.h index 74714770b..f46d6ff9a 100644 --- a/poincare/include/poincare/tree_node.h +++ b/poincare/include/poincare/tree_node.h @@ -39,7 +39,8 @@ constexpr static int ByteAlignment = sizeof(AlignedNodeBuffer); class TreeNode { friend class TreePool; public: - static constexpr uint16_t NoNodeIdentifier = -1; + static constexpr uint16_t NoNodeIdentifier = -2; + static constexpr uint16_t OverflowIdentifier = TreeNode::NoNodeIdentifier + 1; // Used for Integer // Constructor and destructor virtual ~TreeNode() {}