From 85e9f5745a13be812a4d94344ff7fdf2a1908bb5 Mon Sep 17 00:00:00 2001 From: SamuXarick <43006711+SamuXarick@users.noreply.github.com> Date: Tue, 19 Nov 2024 20:34:25 +0000 Subject: [PATCH] Codefix: Replace magic number in Kdtree (#13098) --- src/core/kdtree.hpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/core/kdtree.hpp b/src/core/kdtree.hpp index b810bfed9e..993c36a87c 100644 --- a/src/core/kdtree.hpp +++ b/src/core/kdtree.hpp @@ -42,7 +42,8 @@ class Kdtree { node(T element) : element(element), left(INVALID_NODE), right(INVALID_NODE) { } }; - static const size_t INVALID_NODE = SIZE_MAX; ///< Index value indicating no-such-node + static const size_t INVALID_NODE = SIZE_MAX; ///< Index value indicating no-such-node + static const size_t MIN_REBALANCE_THRESHOLD = 8; ///< Arbitrary value for "not worth rebalancing" std::vector nodes; ///< Pool of all nodes in the tree std::vector free_list; ///< List of dead indices in the nodes vector @@ -98,7 +99,7 @@ class Kdtree { bool Rebuild(const T *include_element, const T *exclude_element) { size_t initial_count = this->Count(); - if (initial_count < 8) return false; // arbitrary value for "not worth rebalancing" + if (initial_count < MIN_REBALANCE_THRESHOLD) return false; T root_element = this->nodes[this->root].element; std::vector elements = this->FreeSubtree(this->root); @@ -310,8 +311,8 @@ class Kdtree { bool IsUnbalanced() const { size_t count = this->Count(); - if (count < 8) return false; - return this->unbalanced > this->Count() / 4; + if (count < MIN_REBALANCE_THRESHOLD) return false; + return this->unbalanced > count / 4; } /** Verify that the invariant is true for a sub-tree, assert if not */