Talk:K-d tree: Difference between revisions

+ notes on C entry
(+ notes on C entry)
Line 9:
 
== The REXX code: wrong? ==
 
I'm tempted to slap a second incorrect tag on it, for it seems fundamentally wrong: as far as I can see, it constructs no tree, just bipartitions points once about the average of ''something''. As a consequence, searches visit about half of the points, which isn't better than a straight exhaustive search by much. Someone better check the code, the pink tag is forthcoming. --[[User:Ledrug|Ledrug]] 07:15, 26 April 2012 (UTC)
==C Entry==
Three suggestions for the C entry:
 
1) To make it easy to change the coordinate type (float, double, etc) and avoid this to cause bugs in the swap function, I suggest to replace:
 
<lang c>#define MAX_DIM 3</lang>
 
With:
<lang c>typedef double point_t[3];</lang>
 
And then use it in kd_node_t and swap.
 
 
2) To generally use NULL instead of 0 to denote the null pointer, to increase readability. Because 0 is a literal for both the null and integral zeros, while NULL denotes only a null pointer. Using more specific literals is generally good.
 
 
3) Regarding this:
<lang c>typedef struct kd_node_t *kd_node, kd_node_t;
struct kd_node_t {...}</lang>
 
See the "Chapter 5: Typedefs" here:
http://www.kernel.org/doc/Documentation/CodingStyle
 
I think a better solution is an intermediate way between your code and that coding standard. So using typedef to mask the "struct" is acceptable, but to use it to mask a pointer is not so good. This means I suggest to use something like this in the C entry (untested):
 
<lang c>typedef double point_t[3];
typedef struct kd_node_t kd_node_t;
 
struct kd_node_t {
point_t x;
kd_node_t *left;
kd_node_t *right;
};</lang>