K-d tree: Difference between revisions

m
Made the code compilable on gcc and g++ versions 4.8, code looks better now hopefully
m (Made the code compilable on gcc and g++ versions 4.8, the thisn is a bit ugly though.)
m (Made the code compilable on gcc and g++ versions 4.8, code looks better now hopefully)
Line 55:
return d;
}
inline void swap(struct kd_node_t *x, struct kd_node_t *y) {
double tmp[MAX_DIM];
memcpy(tmp, x->x, sizeof(tmp));
memcpy(x->x, y->x, sizeof(tmp));
memcpy(y->x, tmp, sizeof(tmp));
}
}
 
 
Line 149:
{{2, 3}}, {{5, 4}}, {{9, 6}}, {{4, 7}}, {{8, 1}}, {{7, 2}}
};
struct kd_node_t thisntestNode = {{9, 2}};
struct kd_node_t *root, *found, *million;
double best_dist;
Line 157:
visited = 0;
found = 0;
nearest(root, &thisntestNode, 0, 2, &found, &best_dist);
 
printf(">> WP tree\nsearching for (%g, %g)\n"
"found (%g, %g) dist %g\nseen %d nodes\n\n",
thisntestNode.x[0], thisntestNode.x[1],
found->x[0], found->x[1], sqrt(best_dist), visited);
 
Line 169:
 
root = make_tree(million, N, 0, 3);
rand_pt(thisntestNode);
 
visited = 0;
found = 0;
nearest(root, &thisntestNode, 0, 3, &found, &best_dist);
 
printf(">> Million tree\nsearching for (%g, %g, %g)\n"
"found (%g, %g, %g) dist %g\nseen %d nodes\n",
thisntestNode.x[0], thisntestNode.x[1], thisntestNode.x[2],
found->x[0], found->x[1], found->x[2],
sqrt(best_dist), visited);
Line 194:
found = 0;
visited = 0;
rand_pt(thisntestNode);
nearest(root, &thisntestNode, 0, 3, &found, &best_dist);
sum += visited;
}
Line 206:
return 0;
}
 
</lang>
{{out}}
Anonymous user