mirror of
https://github.com/jlblancoc/nanoflann.git
synced 2026-01-16 21:01:17 +01:00
nanoflann: faster check in searchLevel
Instead of separately confirming if both children are nullptr, compare the child pointers' values directly. This technique is valid because, in a properly structured search tree, the two child pointers will only be equal if both are nullptr. This change reduces the operation from three comparisons to just one. Signed-off-by: Luca Bartoli <lucabartoli97@gmail.com>
This commit is contained in:
@@ -1887,8 +1887,9 @@ class KDTreeSingleIndexAdaptor
|
||||
DistanceType mindist, distance_vector_t& dists,
|
||||
const float epsError) const
|
||||
{
|
||||
/* If this is a leaf node, then do check and return. */
|
||||
if ((node->child1 == nullptr) && (node->child2 == nullptr))
|
||||
// If this is a leaf node, then do check and return.
|
||||
// If they are equal, both pointers are nullptr.
|
||||
if (node->child1 == node->child2)
|
||||
{
|
||||
DistanceType worst_dist = result_set.worstDist();
|
||||
for (Offset i = node->node_type.lr.left;
|
||||
@@ -2314,8 +2315,9 @@ class KDTreeSingleIndexDynamicAdaptor_
|
||||
DistanceType mindist, distance_vector_t& dists,
|
||||
const float epsError) const
|
||||
{
|
||||
/* If this is a leaf node, then do check and return. */
|
||||
if ((node->child1 == nullptr) && (node->child2 == nullptr))
|
||||
// If this is a leaf node, then do check and return.
|
||||
// If they are equal, both pointers are nullptr.
|
||||
if (node->child1 == node->child2)
|
||||
{
|
||||
DistanceType worst_dist = result_set.worstDist();
|
||||
for (Offset i = node->node_type.lr.left;
|
||||
|
||||
Reference in New Issue
Block a user