K-d tree: Difference between revisions

Content added Content deleted
m (→‎{{header|Perl 6}}: Use named params to make custom "new" method obsolete.)
(Updated both D entries)
Line 374:
typeof(return) result;
foreach (immutable i; 0 .. k)
result[i] = uniform(cast(F)(0), cast(F)(1));
return result;
}
Line 418:
 
writefln("Visited an average of %0.2f nodes on %d searches " ~
"in %d ms.", visited / cast(double)(M), M, sw.peek.msecs);
}</lang>
{{out|Output, using the ldc2 compiler}}
Line 444:
template Iota(int stop) {
static if (stop <= 0)
alias Iota = TypeTuple!() Iota;
else
alias Iota = TypeTuple!(Iota!(stop - 1), stop - 1) Iota;
}
 
Line 548:
void randPt(size_t dim=3)(ref KdNode v, ref Xorshift rng) nothrow {
foreach (i; Iota!dim) {
v.x[i] = rng.front() / castdouble(double)Xorshift.max);
rng.popFront();
}
}
Line 593:
 
size_t sum = 0;
foreach (immutable _; 0 .. testRuns) {
found = null;
nVisited = 0;
Line 602:
writefln("\nBig tree:\n Visited %d nodes for %d random "~
"searches (%.2f per lookup).",
sum, testRuns, sum / cast(double)(testRuns));
}