Talk:K-d tree: Difference between revisions

(Reply to comment)
 
(One intermediate revision by one other user not shown)
Line 135:
 
: Hi Rdm. Thanks; I'm attempting to sign this post properly, we'll see what happens. :-> Even if de-dup'ing the points were a good idea (which would depend on the application in which one is using the k-d tree; it definitely would not be a good idea for my particular application), it wouldn't be a fix for this bug, because here the bug occurs even if two points share just a single coordinate; they don't have to share all of their coordinates. In other words, for 2-D data, the bug could be triggered by having points at (10,17) and (5, 17). You can't de-dup those. :-> --[[User:Bhaller|Bhaller]] ([[User talk:Bhaller|talk]]) 18:19, 15 August 2017 (UTC)
 
== C++ Bug? ==
 
Shouldn't the line:
 
root_ = make_tree(0, nodes_.size(), 0);
 
in the kdtree constructor be:
 
root_ = make_tree(0, nodes_.size()-1, 0);
 
As it is the following line in make_tree() reads off the end of the nodes array:
 
std::nth_element(&nodes_[begin], &nodes_[n], &nodes_[end], node_cmp(index));
 
: The correct fix is to replace &nodes_[end] by &nodes[0] + end, which is fine provided that nodes_ is not empty (the end pointer is not dereferenced). I'll fix the code soon. [[User:Simonjsaunders|Simonjsaunders]] ([[User talk:Simonjsaunders|talk]]) 12:44, 24 April 2020 (UTC)
1,777

edits