Go to the source code of this file.
◆ selecti()
Definition at line 35 of file kdtree.h.
35 {
36 MInt i, ia, ir, j, l, mid;
38
39 l = 0;
40 ir = n - 1;
41 for(;;) {
42 if(ir <= l + 1) {
43 if(ir == l + 1 && arr[indx[ir]] < arr[indx[l]])
SWAP(indx[l], indx[ir]);
44 return indx[k];
45 } else {
46 mid = (l + ir) >> 1;
47 SWAP(indx[mid], indx[l + 1]);
48 if(arr[indx[l]] > arr[indx[ir]])
SWAP(indx[l], indx[ir]);
49 if(arr[indx[l + 1]] > arr[indx[ir]])
SWAP(indx[l + 1], indx[ir]);
50 if(arr[indx[l]] > arr[indx[l + 1]])
SWAP(indx[l], indx[l + 1]);
51 i = l + 1;
52 j = ir;
53 ia = indx[l + 1];
55 for(;;) {
56 do
57 i++;
58 while(arr[indx[i]] <
a);
59 do
60 j--;
61 while(arr[indx[j]] >
a);
62 if(j < i) break;
63 SWAP(indx[i], indx[j]);
64 }
65 indx[l + 1] = indx[j];
66 indx[j] = ia;
67 if(j >= k) ir = j - 1;
68 if(j <= k) l = i;
69 }
70 }
71}
◆ SWAP()
template<class T >
void SWAP |
( |
T & |
a, |
|
|
T & |
b |
|
) |
| |
|
inline |
Building a K-D-tree Numercial Recipies in C: The Art of Scientific Computing Thrid Edition Authors:
Definition at line 21 of file kdtree.h.