Chombo + EB + MF  3.2
Classes | Functions
Sort Namespace Reference

Some support for sorting small arrays. More...

Classes

class  CmpGreaterIndex
 Compares m_a[i] > m_a[j]. More...
 
class  Move1Array
 Mover for use with 'rearrangeToIndex'. More...
 
class  Move2Array
 Mover for use with 'rearrangeToIndex'. More...
 

Functions

template<typename T , typename Cmp , typename M >
void insertion (const int n, T *array, const Cmp &cmp, const M *const mask)
 Insertion sort. More...
 
template<typename T , typename Cmp >
void insertion (const int n, T *array, const Cmp &cmp)
 
template<typename T >
void insertion (const int n, T *array)
 
template<typename Mv >
void rearrangeToIndex (const int n, int *const index, Mv &mv)
 Rearrange arrays to a sorted index. More...
 

Detailed Description

Some support for sorting small arrays.

Function Documentation

◆ insertion() [1/3]

template<typename T , typename Cmp , typename M >
void Sort::insertion ( const int  n,
T *  array,
const Cmp &  cmp,
const M *const  mask 
)

Insertion sort.

Sorts using Cmp which defaults to std::less<T>(). Use only for small ~(n < 20) arrays.

Template Parameters
TType of element
CmpComparison functor. Requires operator()(T&, T&).
MType of mask
Parameters
[in]nNumber of elements to sort
[in]arrayArray to sort
[in]cmpComparison bool operator()(i, j) to determine if element array[i] belongs before array[j]
[in]maskOnly sort elements were mask = true. Unused if set to null

◆ insertion() [2/3]

template<typename T , typename Cmp >
void Sort::insertion ( const int  n,
T *  array,
const Cmp &  cmp 
)

◆ insertion() [3/3]

template<typename T >
void Sort::insertion ( const int  n,
T *  array 
)

◆ rearrangeToIndex()

template<typename Mv >
void Sort::rearrangeToIndex ( const int  n,
int *const  index,
Mv &  mv 
)

Rearrange arrays to a sorted index.

If an index to an array has been sorted instead of the actual array, this allows for rearranging other arrays in the exact same manner that the index was rearranged during sorting. Note that the index array is reverted to a sequential order during this process

Template Parameters
MvClass for moving elements and saving/restoring elements. Needs members 'copy', 'save', and 'restore'. See Move1Array for example.
Parameters
[in]nNumber of elements to rearrange
[in]indexArray of indices describing where elements are to be moved.
[out]indexindex[0] < index[...] < index[n]
[in]mvClass for moving elements and saving/restoring elements.