MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
kdtree.h File Reference

Go to the source code of this file.

Classes

struct  Boxnode< DIM >
 
struct  KDtree< DIM >
 

Functions

template<class T >
void SWAP (T &a, T &b)
 
template<MInt DIM>
MInt selecti (const MInt k, MInt *indx, MInt n, MFloat *arr)
 

Function Documentation

◆ selecti()

template<MInt DIM>
MInt selecti ( const MInt  k,
MInt indx,
MInt  n,
MFloat arr 
)

Definition at line 35 of file kdtree.h.

35 {
36 MInt i, ia, ir, j, l, mid;
37 MFloat a;
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];
54 a = arr[ia];
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}
void SWAP(T &a, T &b)
Definition: kdtree.h:21
int32_t MInt
Definition: maiatypes.h:62
double MFloat
Definition: maiatypes.h:52
Definition: contexttypes.h:19

◆ 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.

21 {
22 T dum = a;
23 a = b;
24 b = dum;
25}