K-d tree: Difference between revisions
Content deleted Content added
Updated first D entry |
Updated D entry |
||
Line 222: | Line 222: | ||
struct Point(size_t k, F) if (isFloatingPoint!F) { |
struct Point(size_t k, F) if (isFloatingPoint!F) { |
||
F[k] data; |
F[k] data; |
||
⚫ | |||
// Define opIndexAssign and opIndex for dmd. |
|||
⚫ | |||
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; |
enum size_t length = k; |
||
Line 428: | Line 422: | ||
{{out|Output, using the ldc2 compiler}} |
{{out|Output, using the ldc2 compiler}} |
||
<pre>Wikipedia example data: |
<pre>Wikipedia example data: |
||
Point: |
Point: [9, 2] |
||
Nearest neighbor: |
Nearest neighbor: [8, 1] |
||
Distance: 1.41421 |
Distance: 1.41421 |
||
Nodes visited: 3 |
Nodes visited: 3 |
||
k-d tree with 400000 random 3D float points (construction time: 250 ms): |
k-d tree with 400000 random 3D float points (construction time: 250 ms): |
||
Point: |
Point: [0.22012, 0.984514, 0.698782] |
||
Nearest neighbor: |
Nearest neighbor: [0.225766, 0.978981, 0.69885] |
||
Distance: 0.00790531 |
Distance: 0.00790531 |
||
Nodes visited: 54 |
Nodes visited: 54 |