Files Classes Functions Hierarchy
#include <snakesort.h>
Static Public Member Functions | |
| template<typename T , typename CMP > | |
| static void | d1 (T *vi, uintc N, uintc width, CMP compare, uintc parity=0) |
| Sort in blocks of width. | |
| template<typename T , typename CMP > | |
| static void | d2 (T *vi, uintc N, CMP compare) |
| Sort on x-axis and in blocks on y-axis. | |
| template<typename T , typename CMP > | |
| static void | d3 (T *vi, uintc N, CMP compare) |
| Sort in x-axis, and in blocks on y-axis, and inside these blocks sort in smaller blocks on the z-axis. | |
Such orderings are important in incremental algorithms with a state where ording the points to be near each other gets an algorithmic speed up (constant access time).
There is an inherent instability in this sort as for large data sets the jump or change in a coordinate can be extremely large for a finite number of points. Contrast/compare this with a Hilbert curve.
Definition at line 25 of file snakesort.h.
| void snakesort::d1 | ( | T * | vi, | |
| uintc | N, | |||
| uintc | width, | |||
| CMP | compare, | |||
| uintc | parity = 0 | |||
| ) | [inline, static] |
Sort in blocks of width.
Definition at line 70 of file snakesort.h.
References mynot2().
Referenced by snakesorttest::test01().
00077 { 00078 uint k=parity; 00079 for (uint i=0; i<N; i+=width, ++k) 00080 { 00081 if (i+width<=N) 00082 { 00083 if (k%2) 00084 sort(vi+i,vi+i+width,mynot2(compare)); 00085 else 00086 sort(vi+i,vi+i+width,compare); 00087 } 00088 else 00089 { 00090 if (k%2) 00091 sort(vi+i,vi+N,mynot2(compare)); 00092 else 00093 sort(vi+i,vi+N,compare); 00094 } 00095 } 00096 }
| void snakesort::d2 | ( | T * | vi, | |
| uintc | N, | |||
| CMP | compare | |||
| ) | [inline, static] |
Sort on x-axis and in blocks on y-axis.
Definition at line 100 of file snakesort.h.
Referenced by snakesorttest::test02().
00105 { 00106 uint width=(int)sqrt(N); 00107 sort(vi,vi+N,mycomparexobject<CMP>()); 00108 d1(vi,N,width,mycompareyobject<CMP>()); 00109 }
| void snakesort::d3 | ( | T * | vi, | |
| uintc | N, | |||
| CMP | compare | |||
| ) | [inline, static] |
Sort in x-axis, and in blocks on y-axis, and inside these blocks sort in smaller blocks on the z-axis.
Definition at line 113 of file snakesort.h.
Referenced by snakesorttest::test03().
00118 { 00119 uint width=(int)pow(N,2.0/3.0); 00120 uint width2=(int)pow(N,1.0/3.0); 00121 sort(vi,vi+N,mycomparexobject<CMP>()); 00122 d1(vi,N,width,mycompareyobject<CMP>()); 00123 uint parity=0; 00124 mycomparezobject<CMP> compare2; 00125 for (uint i=0; i<N; i+=width) 00126 { 00127 if (i+width<N) 00128 d1(vi+i,width,width2,compare2,parity); 00129 else 00130 d1(vi+i,N-i,width2,compare2,parity); 00131 ++parity; 00132 } 00133 }
1.5.8