mirror of https://github.com/OpenTTD/OpenTTD
Codefix: Replace magic number in Kdtree (#13098)
parent
6c09dcdd66
commit
85e9f5745a
|
@ -42,7 +42,8 @@ class Kdtree {
|
||||||
node(T element) : element(element), left(INVALID_NODE), right(INVALID_NODE) { }
|
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<node> nodes; ///< Pool of all nodes in the tree
|
std::vector<node> nodes; ///< Pool of all nodes in the tree
|
||||||
std::vector<size_t> free_list; ///< List of dead indices in the nodes vector
|
std::vector<size_t> 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)
|
bool Rebuild(const T *include_element, const T *exclude_element)
|
||||||
{
|
{
|
||||||
size_t initial_count = this->Count();
|
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;
|
T root_element = this->nodes[this->root].element;
|
||||||
std::vector<T> elements = this->FreeSubtree(this->root);
|
std::vector<T> elements = this->FreeSubtree(this->root);
|
||||||
|
@ -310,8 +311,8 @@ class Kdtree {
|
||||||
bool IsUnbalanced() const
|
bool IsUnbalanced() const
|
||||||
{
|
{
|
||||||
size_t count = this->Count();
|
size_t count = this->Count();
|
||||||
if (count < 8) return false;
|
if (count < MIN_REBALANCE_THRESHOLD) return false;
|
||||||
return this->unbalanced > this->Count() / 4;
|
return this->unbalanced > count / 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Verify that the invariant is true for a sub-tree, assert if not */
|
/** Verify that the invariant is true for a sub-tree, assert if not */
|
||||||
|
|
Loading…
Reference in New Issue