About
maxon::BaseSort is a class template that allows to sort data in arrays and to search in sorted arrays. For a default implementation handling simple data types see maxon::SimpleSort.
- Note
- See also SortedArray.
Create
A new sorting class is created by implementing a custom class based on maxon::BaseSort. This custom class may implement:
LessThan
(): For sorting elements in an array.
IsEqual
(): For finding elements in an array.
Further flags that can be set are:
Sorting
An instance of the custom sorting class can be used to sort the elements stored in a maxon::BaseArray.
class IntegerSort :
public maxon::BaseSort<IntegerSort, maxon::BASESORTFLAGS::MOVEANDCOPYOBJECTS>
{
public:
{
return a < b;
}
};
FillWithRandomNumbers(numbers);
IntegerSort sort;
sort.Sort(numbers);
Py_ssize_t count
Definition: abstract.h:640
Definition: basearray.h:412
ResultMem Resize(Int newCnt, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::DEFAULT)
Definition: basearray.h:1369
maxon::Bool Bool
Definition: ge_sys_math.h:55
Int64 Int
signed 32/64 bit int, size depends on the platform
Definition: apibase.h:188
Bool LessThan(UInt a1, UInt a2, UInt b1, UInt b2)
Definition: integer.h:151
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:176
#define iferr_return
Definition: resultbase.h:1465
Searching
To find elements in the given array, the array must be sorted. The custom sorting class must implement both LessThan
() and IsEqual
().
{
public:
{
return false;
return true;
return false;
return true;
return false;
return true;
}
{
return false;
return false;
return false;
return true;
}
{
}
{
}
};
FillWithRandomDates(dates);
DateSort sort;
sort.Sort(dates);
const CustomDate* const date = sort.Find(2000, dates);
if (date)
CustomDate newDate;
newDate.year = 1970;
newDate.month = 1;
newDate.day = 1;
sort.FindInsertionIndex(newDate, dates, insertionIndex);
PyObject * key
Definition: abstract.h:289
MAXON_ATTRIBUTE_FORCE_INLINE ResultRef< T > Insert(Int position, ARG &&x)
Definition: basearray.h:950
MAXON_ATTRIBUTE_FORCE_INLINE ConstIterator Begin() const
Definition: basearray.h:1637
MAXON_ATTRIBUTE_FORCE_INLINE Int GetCount() const
Definition: basearray.h:573
Py_ssize_t * index
Definition: abstract.h:374
MAXON_ATTRIBUTE_FORCE_INLINE Bool IsEqual(PREDICATE &&predicate, const T1 &a, const T2 &b)
Definition: collection.h:102
PyObject * element
Definition: unicodeobject.h:1016
Further Reading