template<typename SORTCLASS, BASESORTFLAGS FLAGS = BASESORTFLAGS::NONE, Int PARALLELIZATION_THRESHOLD = 10000>
class maxon::ParallelSort< SORTCLASS, FLAGS, PARALLELIZATION_THRESHOLD >
Template for sorting arrays and searching in sorted arrays
To use this template derive a class from it and define the member 'LessThan' that implements an element comparison. If you do searching the member 'IsEqual' needs to be implemented that does an element comparison with the search key as the first argument. If the search key is different from the element type a second LessThan routine is needed (comparing SEARCHKEY to an element).
- Template Parameters
-
SORTCLASS | The class itself. This has to be a derived class of BaseSort. |
FLAGS | See BASESORTFLAGS. |
PARALLELIZATION_THRESHOLD | The minimum number of elements to start parallel sorting. if less elements are sorted a regular BaseSort will be used. |
- Note
- Note that the classes that will be sorted have special requirements regarding copy and move constructors .
Example for traditional C-style arrays:
class Sort1 : public ParallelSort<Sort1>
{
public:
{
return a < b;
}
};
...
Int array1[100];
...
Sort1 sort1;
sort1.Sort(&array1[0], &array1[100]);
sort1.Sort(array1, 100);
maxon::Bool Bool
Definition: ge_sys_math.h:55
maxon::Int Int
Definition: ge_sys_math.h:64
Bool LessThan(UInt a1, UInt a2, UInt b1, UInt b2)
Definition: integer.h:151
- Note
- LessThan can be a member of the sort class itself (not static), but needs to be const in that case.
Example for arrays:
class Sort2 : public ParallelSort<Sort2>
{
public:
{
return a < b;
}
};
...
...
Sort2 sort2;
sort2.Sort(array2.Begin(), array2.End());
sort2.Sort(array2);
Example for arbitrary structures with multiple sort criteria:
class MyStruct
{
public:
};
class Sort3 : public ParallelSort<Sort3>
{
public:
static inline Bool LessThan(
const MyStruct& a,
const MyStruct& b)
{
if (a._weight < b._weight) return true;
if (a._weight > b._weight) return false;
return a._index < b._index;
}
};
...
BlockArray<MyStruct> array3;
...
Sort3 sort3;
sort3.Sort(array3);
Definition: c4d_string.h:39
maxon::Float Float
Definition: ge_sys_math.h:66
Searching Example:
class MyStruct
{
public:
};
class MySearch : public ParallelSort<MySearch>
{
public:
static inline Bool LessThan(
const MyStruct& a,
const MyStruct& b)
{
if (a._weight < b._weight) return true;
if (a._weight > b._weight) return false;
return a._index < b._index;
}
{
return weight < b._weight;
}
{
return weight == b._weight;
}
};
...
BlockArray<MyStruct> array4;
...
MySearch search;
search.Sort(array4);
...
MyStruct*
result = search.Find(5.0, array4);
PyObject PyObject * result
Definition: abstract.h:43
MAXON_ATTRIBUTE_FORCE_INLINE Bool IsEqual(PREDICATE &&predicate, const T1 &a, const T2 &b)
Definition: collection.h:102
|
template<typename ITERATOR > |
void | Sort (ITERATOR start, ITERATOR end, JobQueueInterface *queue=JOBQUEUE_CURRENT) const |
|
template<typename ITERATOR > |
void | Sort (ITERATOR start, Int count, JobQueueInterface *queue=JOBQUEUE_CURRENT) const |
|
template<typename ARRAY > |
void | Sort (ARRAY &arr, JobQueueInterface *queue=JOBQUEUE_CURRENT) const |
|
void | Sort (ITERATOR start, ITERATOR end) const |
|
void | Sort (ITERATOR start, Int count) const |
|
void | Sort (ARRAY &arr) const |
|
Int | FindIndex (const SEARCHTYPE &key, ITERATOR arr, Int count) const |
|
ITERATOR | Find (const SEARCHTYPE &key, ITERATOR arr, Int count) const |
|
ARRAY::ValueType * | Find (const SEARCHTYPE &key, const ARRAY &arr) const |
|
ITERATOR | FindInsertionIndex (const SEARCHTYPE &key, ITERATOR arr, Int count, Int &insertionIndex) const |
|
ARRAY::ValueType * | FindInsertionIndex (const SEARCHTYPE &key, const ARRAY &arr, Int &insertionIndex) const |
|
|
template<typename ITERATOR , typename CONTENT > |
void | ISort (ITERATOR start, Int count, const CONTENT &valType, JobQueueInterface *queue) const |
|
template<typename CONTENT > |
void | ISort (CONTENT *start, Int count, const CONTENT &valType, JobQueueInterface *queue) const |
|
template<typename ITERATOR , typename CONTENT , typename MOVEHELPERFORWARD , typename MOVEHELPERBACKWARD > |
void | ParallelSortAlgorithm (ITERATOR start, Int count, const CONTENT &valType, JobQueueInterface *queue, const MOVEHELPERFORWARD &moveHelperForward, const MOVEHELPERBACKWARD &moveHelperBackward) const |
|
template<typename ITERATOR > |
void | ReduceRedundantBlocks (Int chunksize, Int &cnt, ITERATOR &arr) const |
|
Int | PowerOfTwo (Int count) const |
|