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: | Line 374: | ||
typeof(return) result; |
typeof(return) result; |
||
foreach (immutable i; 0 .. k) |
foreach (immutable i; 0 .. k) |
||
result[i] = uniform |
result[i] = uniform(F(0), F(1)); |
||
return result; |
return result; |
||
} |
} |
||
Line 418: | Line 418: | ||
writefln("Visited an average of %0.2f nodes on %d searches " ~ |
writefln("Visited an average of %0.2f nodes on %d searches " ~ |
||
"in %d ms.", visited / |
"in %d ms.", visited / double(M), M, sw.peek.msecs); |
||
}</lang> |
}</lang> |
||
{{out|Output, using the ldc2 compiler}} |
{{out|Output, using the ldc2 compiler}} |
||
Line 444: | Line 444: | ||
template Iota(int stop) { |
template Iota(int stop) { |
||
static if (stop <= 0) |
static if (stop <= 0) |
||
alias TypeTuple!() |
alias Iota = TypeTuple!(); |
||
else |
else |
||
alias TypeTuple!(Iota!(stop - 1), stop - 1) |
alias Iota = TypeTuple!(Iota!(stop - 1), stop - 1); |
||
} |
} |
||
Line 548: | Line 548: | ||
void randPt(size_t dim=3)(ref KdNode v, ref Xorshift rng) nothrow { |
void randPt(size_t dim=3)(ref KdNode v, ref Xorshift rng) nothrow { |
||
foreach (i; Iota!dim) { |
foreach (i; Iota!dim) { |
||
v.x[i] = rng.front |
v.x[i] = rng.front / double(Xorshift.max); |
||
rng.popFront |
rng.popFront; |
||
} |
} |
||
} |
} |
||
Line 593: | Line 593: | ||
size_t sum = 0; |
size_t sum = 0; |
||
foreach (_; 0 .. testRuns) { |
foreach (immutable _; 0 .. testRuns) { |
||
found = null; |
found = null; |
||
nVisited = 0; |
nVisited = 0; |
||
Line 602: | Line 602: | ||
writefln("\nBig tree:\n Visited %d nodes for %d random "~ |
writefln("\nBig tree:\n Visited %d nodes for %d random "~ |
||
"searches (%.2f per lookup).", |
"searches (%.2f per lookup).", |
||
sum, testRuns, sum / |
sum, testRuns, sum / double(testRuns)); |
||
} |
} |
||