latest version v1.9 - last update 10 Apr 2010 |
Sort vectors. More...
#include <ltiSort.h>
Classes | |
class | parameters |
The parameters for the class sort. More... | |
Public Member Functions | |
sort (const bool &descendingOrder=false) | |
sort (const parameters &par) | |
sort (const sort< T > &other) | |
virtual | ~sort () |
virtual const char * | getTypeName () const |
virtual bool | apply (matrix< T > &srcdest) const |
virtual bool | apply (vector< T > &srcdest) const |
virtual bool | apply (const matrix< T > &src, matrix< T > &dest) const |
virtual bool | apply (const vector< T > &src, vector< T > &dest) const |
sort & | copy (const sort &other) |
virtual functor * | clone () const |
const parameters & | getParameters () const |
bool | updateParameters () |
Protected Attributes | |
Shadows of the parameters to avoid a function access | |
int | thresholdForBubble |
parameters::eOrder | order |
Sort vectors.
This class is used to sort the elements of a given vector or matrix.
The sort::parameters::order specify if the elements should be sorted in ascending or descending order.
This functor requires that the type T accept the operator<.
The functor uses the well-known quick-sort algorithm to sort the elements of the vector. Since the overhead of the recursion makes at some point the quick-sort more innefficient than simpler algorithms, you can specify in the parameters for which size the vectors should be sorted with the bubble-sort algorithm.
The quick-sort is not "stable", this means that elements with the same key value can change their positions in the vector.
You should also revise the STL algorithms std::sort() if you are using containers of the STL.
Default constructor.
lti::sort< T >::sort | ( | const parameters & | par | ) |
Construct with given parameters.
Copy constructor.
other | the object to be copied |
virtual bool lti::sort< T >::apply | ( | const vector< T > & | src, | |
vector< T > & | dest | |||
) | const [virtual] |
Operates on a copy of the given parameters.
src | vector<T> with the source data. | |
dest | vector<T> where the result will be left. |
virtual bool lti::sort< T >::apply | ( | const matrix< T > & | src, | |
matrix< T > & | dest | |||
) | const [virtual] |
Sort all the elements of the matrix.
The elements will be ordered row-wise. For example, the matrix at the left will be sorted into the matrix at the right side:
| 2 8 3 | | 1 2 3 | | 1 4 5 | ---> | 4 5 6 | | 7 9 6 | | 7 8 9 |
src | matrix<T> with the source data. | |
dest | matrix<T> where the result will be left. |
Operates on the given parameter.
srcdest | vector<T> with the source data. The result will be left here too. |
Sort all the elements of the matrix.
The elements will be ordered row-wise. For example, the matrix at the left will be sorted into the matrix at the right side:
| 2 8 3 | | 1 2 3 | | 1 4 5 | ---> | 4 5 6 | | 7 9 6 | | 7 8 9 |
srcdest | matrix<T> with the source data. The result will be left here too. |
Returns a pointer to a clone of this functor.
Implements lti::functor.
Reimplemented in lti::sort2< T, U >.
Copy data of "other" functor.
other | the functor to be copied |
Reimplemented from lti::functor.
Reimplemented in lti::sort2< T, U >.
const parameters& lti::sort< T >::getParameters | ( | ) | const |
virtual const char* lti::sort< T >::getTypeName | ( | ) | const [virtual] |
Returns the name of this type ("sort").
Reimplemented from lti::functor.
Reimplemented in lti::sort2< T, U >.
bool lti::sort< T >::updateParameters | ( | ) | [virtual] |
Set parameters.
Reimplemented from lti::functor.