Jump to content

K-d tree: Difference between revisions

201 bytes removed ,  10 years ago
Updated D entry
(Updated first D entry)
(Updated D entry)
Line 222:
struct Point(size_t k, F) if (isFloatingPoint!F) {
F[k] data;
// alias data this; // killsKills DMD std.algorithm.swap inlining.
 
// Define opIndexAssign and opIndex for dmd.
// alias data this; // kills DMD std.algorithm.swap inlining
F opIndex(in size_t i) const pure nothrow { return data[i]; }
 
void opIndexAssign(in F x, in size_t i) pure nothrow {
data[i] = x;
}
 
enum size_t length = k;
 
Line 428 ⟶ 422:
{{out|Output, using the ldc2 compiler}}
<pre>Wikipedia example data:
Point: const(Point!(2, double))([9, 2])
Nearest neighbor: immutable(Point!(2, double))([8, 1])
Distance: 1.41421
Nodes visited: 3
 
k-d tree with 400000 random 3D float points (construction time: 250 ms):
Point: const(Point!(3, float))([0.22012, 0.984514, 0.698782])
Nearest neighbor: immutable(Point!(3, float))([0.225766, 0.978981, 0.69885])
Distance: 0.00790531
Nodes visited: 54
Cookies help us deliver our services. By using our services, you agree to our use of cookies.