For operations on a large portion of the table’s data,
it can be useful to first sort the rows.
This sorting can either be done according to a single field,
or according to the values in the entire row.
To sort by a field, we use the Field<T>::sort
method.
This method accepts a function as an argument.
This function should take two references to the type T
and return a bool
.
This return value should be true
if the references are in the correct order, and false
otherwise.
You can make your own function, but dopc.hpp
contains the SortAscending<T>
function as a convenient example.
dopc::Table table;
dopc::Field<int> a(&table);
/*
do whatever
*/
a.sort(dopc::SortAscending<int>);
When sorting this way, other fields are also affected.
Some sorting rules depend on multiple fields. So we can make a function which takes two indices and returns a `bool``.
bool rule(size_t a, size_t b)
{
/*
encode the rule here
*/
}
void foo()
{
Data::table.indexSort(rule);
}
The rule can of course use the indices whichever way it chooses. It is expected however, that these indices will be used to refer to table elements.