last update 20 Sep 2009 |
#include <cvrSort2.h>
Classes | |
class | parameters |
The parameters for the class sort. More... | |
Public Types | |
enum | eWhichVectors { Columns, Rows } |
Public Member Functions | |
sort2 (const eSortingOrder sortingOrder=Ascending, const eWhichVectors whichVectors=Rows) | |
sort2 (const sort2 &other) | |
sort2 (const parameters &par) | |
virtual | ~sort2 () |
template<typename T , typename U > | |
bool | apply (matrix< T > &key, matrix< U > &srcdest) const |
template<typename T , typename U > | |
bool | apply (vector< T > &key, vector< U > &srcdest) const |
template<typename T , typename U > | |
bool | apply (vector< T > &key, matrix< U > &srcdest) const |
template<typename T , typename U > | |
bool | apply (const matrix< T > &key, const matrix< U > &src, matrix< T > &destkey, matrix< U > &dest) const |
template<typename T , typename U > | |
bool | apply (const vector< T > &key, const vector< U > &src, vector< T > &destkey, vector< U > &dest) const |
template<typename T , typename U > | |
bool | apply (const vector< T > &key, const matrix< U > &src, vector< T > &destkey, matrix< U > &dest) const |
sort2 & | copy (const sort2 &other) |
const std::string & | name () const |
virtual sort2 * | clone () const |
virtual sort2 * | newInstance () const |
const parameters & | getParameters () const |
This class is used to sort the elements of two given vectors or matrices. The first one (of type T) contains always the keys to be used by sorting, and the second (of type U) one will be sorted accordingly to first one.
For example, if you have a second vector of integers, which was initialized with the indices (0 for the first element, 1 for the second and so on), at the end you can use this sorted vector to know which position has an element of the first vector after sorting:
// the key vector const float fdata[] = {3.2, 1.5, 4.2, 2.0}; cvr::vector<float> a(4,fdata); // the data vector const int idata[] = {0,1,2,3}; cvr::vector<int> idx(4,idata); // sorting object: sort2<float,int> sorter; // sort the vector a, and accordingly the vector b sorter.apply(a,b); // after this you will get: // a = 1.5, 2.0, 3.2, 4.2 // b = 1 , 3 , 0 , 2
The sort2::parameters inherit from sort::parameters, and therefore you can also here specify the sorting order and the threshold for applying bubble- sort.
This functor requires that the type T accept the operator<.
cvr::sort2::sort2 | ( | const eSortingOrder | sortingOrder = Ascending , |
|
const eWhichVectors | whichVectors = Rows | |||
) |
Default constructor.
sortingOrder | sets the sorting order in the parameters. Default is Ascending. | |
whichVectors | sets the vectors treated in a matrix. Default is Rows |
cvr::sort2::sort2 | ( | const sort2 & | other | ) |
cvr::sort2::sort2 | ( | const parameters & | par | ) |
Construct with given parameters.
virtual cvr::sort2::~sort2 | ( | ) | [virtual] |
Destructor.
bool cvr::sort2::apply | ( | const vector< T > & | key, | |
const matrix< U > & | src, | |||
vector< T > & | destkey, | |||
matrix< U > & | dest | |||
) | const [inline] |
Sort the rows of the matrix, using as key the elements of the given vector.
For example, the matrix at the left side will be sorted in the matrix at the right side with the key-vector (5 2 3):
| 2 8 3 | | 1 4 5 | | 1 4 5 | ---> | 7 9 6 | | 7 9 6 | | 2 8 3 |
The number of rows of the matrix must be equal to the number of elements in the key vector.
key | vector<T> with the key data. | |
src | matrix<U> with the rows that will be sorted according to the key data | |
destkey | the sorted key-vector | |
dest | the matrix with sorted rows. |
bool cvr::sort2::apply | ( | const vector< T > & | key, | |
const vector< U > & | src, | |||
vector< T > & | destkey, | |||
vector< U > & | dest | |||
) | const [inline] |
Operates on a copy of the given parameters.
key | vector<T> with the key data. | |
src | vector<U> with the source data. | |
destkey | vector<T> where the sorted keys will be left. | |
dest | vector<U> where the sorted data (using the key) will be left. |
bool cvr::sort2::apply | ( | const matrix< T > & | key, | |
const matrix< U > & | src, | |||
matrix< T > & | destkey, | |||
matrix< U > & | dest | |||
) | const [inline] |
Sort all the elements of the matrix.
The elements will be ordered row-wise. For example, the key 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 |
key | matrix<T> with the key data. | |
src | matrix<U> with the source data. | |
destkey | matrix<T> where the sorted keys will be left. | |
dest | matrix<U> where the sorted data (using the key) will be left. |
bool cvr::sort2::apply | ( | vector< T > & | key, | |
matrix< U > & | srcdest | |||
) | const [inline] |
Sort the rows of the matrix, using as key the elements of the given vector.
For example, the matrix at the left side will be sorted in the matrix at the right side with the key-vector (5 2 3):
| 2 8 3 | | 1 4 5 | | 1 4 5 | ---> | 7 9 6 | | 7 9 6 | | 2 8 3 |
The number of rows of the matrix must be equal to the number of elements in the key vector.
key | vector<T> with the key data. The result will be left here too. | |
srcdest | matrix<U> with the rows that will be sorted according to the key data |
bool cvr::sort2::apply | ( | vector< T > & | key, | |
vector< U > & | srcdest | |||
) | const [inline] |
Operates on the given parameter.
key | vector<T> with the key data. The result will be left here too. | |
srcdest | vector<U> with the data that will be sorted according to the key data |
bool cvr::sort2::apply | ( | matrix< T > & | key, | |
matrix< U > & | srcdest | |||
) | const [inline] |
Sort all the elements of the matrix.
The elements will be ordered row-wise. For example, the key 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 |
key | matrix<T> with the key data. The result will be left here too. | |
srcdest | matrix<U> with the data that will be sorted according to the key data |
virtual sort2* cvr::sort2::clone | ( | ) | const [virtual] |
const parameters& cvr::sort2::getParameters | ( | ) | const |
const std::string& cvr::sort2::name | ( | ) | const [virtual] |
virtual sort2* cvr::sort2::newInstance | ( | ) | const [virtual] |