11 #ifndef _INSERTIONSORT_H_ 12 #define _INSERTIONSORT_H_ 26 #include "NamespaceHeader.H" 72 template <
typename T,
typename Cmp,
typename M>
80 for (
int j = 1 ; j != n ; ++j)
84 while (i-- && cmp(tmp, array[i]))
86 array[i+1] = array[i];
94 while (s > n && !mask[s]) ++s;
95 for (
int j = s+1 ; j != n ; ++j)
102 while ((i-- > s) && (!mask[i] || cmp(tmp, array[i])))
106 array[ip] = array[i];
115 template <
typename T,
typename Cmp>
118 insertion<T, Cmp, bool>(n, array, cmp, NULL);
120 template <
typename T>
123 insertion<T, std::less<T>,
bool>(n, array, std::less<T>(), NULL);
131 template <
typename T>
138 void copy(
const int i,
const int j)
140 m_array[i] = m_array[j];
160 template <
typename T1,
typename T2>
165 : m_array0(array0), m_array1(array1)
167 void copy(
const int i,
const int j)
169 m_array0[i] = m_array0[j];
170 m_array1[i] = m_array1[j];
174 m_tmp0 = m_array0[i];
175 m_tmp1 = m_array1[i];
179 m_array0[i] = m_tmp0;
180 m_array1[i] = m_tmp1;
207 template <
typename Mv>
210 for (
int i = 0; i != n; ++i)
216 for (
int j = index[i]; j != i; j = index[j])
229 #include "NamespaceFooter.H" const T *const m_a
Definition: InsertionSort.H:54
Some support for sorting small arrays.
T1 m_tmp0
Definition: InsertionSort.H:183
void restore(const int i)
Definition: InsertionSort.H:146
void save(const int i)
Definition: InsertionSort.H:142
T1 *const m_array0
Definition: InsertionSort.H:185
Move2Array(T1 *const array0, T2 *const array1)
Definition: InsertionSort.H:164
T2 m_tmp1
Definition: InsertionSort.H:184
Mover for use with 'rearrangeToIndex'.
Definition: InsertionSort.H:132
void insertion(const int n, T *array, const Cmp &cmp, const M *const mask)
Insertion sort.
Definition: InsertionSort.H:73
Compares m_a[i] > m_a[j].
Definition: InsertionSort.H:42
T m_tmp
Definition: InsertionSort.H:151
bool operator()(const int i, const int j) const
Definition: InsertionSort.H:49
void rearrangeToIndex(const int n, int *const index, Mv &mv)
Rearrange arrays to a sorted index.
Definition: InsertionSort.H:208
void save(const int i)
Definition: InsertionSort.H:172
void restore(const int i)
Definition: InsertionSort.H:177
T2 *const m_array1
Definition: InsertionSort.H:186
Mover for use with 'rearrangeToIndex'.
Definition: InsertionSort.H:161
void const char const int * M
Definition: Lapack.H:83
CmpGreaterIndex(const T *const a)
Definition: InsertionSort.H:45
T *const m_array
Definition: InsertionSort.H:152
void copy(const int i, const int j)
Definition: InsertionSort.H:138
Move1Array(T *const array)
Definition: InsertionSort.H:135
void copy(const int i, const int j)
Definition: InsertionSort.H:167