CVR-Lib last update 20 Sep 2009

cvr::sort2 Class Reference
[Sorting and scrambling algorithms]

Sort two vectors, using the first one as key. More...

#include <cvrSort2.h>

Inheritance diagram for cvr::sort2:

Inheritance graph
[legend]
Collaboration diagram for cvr::sort2:

Collaboration graph
[legend]

List of all members.

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
sort2copy (const sort2 &other)
const std::string & name () const
virtual sort2clone () const
virtual sort2newInstance () const
const parametersgetParameters () const


Detailed Description

Sort two vectors, using the first one as key.

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<.

See also:
cvr::scramble, cvr::sort, cvr::quickPartialSort2

Member Enumeration Documentation

Type used in the specification of the sorting order (used when sorting the rows or columns of a matrix using as keys the values of a vector).

Enumerator:
Columns  sort the columns of the matrix
Rows  sort the rows of the matrix


Constructor & Destructor Documentation

cvr::sort2::sort2 ( const eSortingOrder  sortingOrder = Ascending,
const eWhichVectors  whichVectors = Rows 
)

Default constructor.

Parameters:
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  ) 

Copy constructor.

Parameters:
other the object to be copied

cvr::sort2::sort2 ( const parameters par  ) 

Construct with given parameters.

virtual cvr::sort2::~sort2 (  )  [virtual]

Destructor.


Member Function Documentation

template<typename T , typename U >
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.

Parameters:
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.
Returns:
true if successful, false otherwise

template<typename T , typename U >
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.

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.
Returns:
true if successful, false otherwise

template<typename T , typename U >
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 |
Parameters:
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.
Returns:
true if successful, false otherwise

template<typename T , typename U >
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.

Parameters:
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
Returns:
true if successful, false otherwise

template<typename T , typename U >
bool cvr::sort2::apply ( vector< T > &  key,
vector< U > &  srcdest 
) const [inline]

Operates on the given parameter.

Parameters:
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
Returns:
true if successful, false otherwise

template<typename T , typename U >
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 |
Parameters:
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
Returns:
true if successful, false otherwise

virtual sort2* cvr::sort2::clone (  )  const [virtual]

Returns a pointer to a clone of this functor.

Implements cvr::functor.

sort2& cvr::sort2::copy ( const sort2 other  ) 

Copy data of "other" functor.

Parameters:
other the functor to be copied
Returns:
a reference to this functor object

const parameters& cvr::sort2::getParameters (  )  const

Returns used parameters.

Reimplemented from cvr::parametersManager.

const std::string& cvr::sort2::name (  )  const [virtual]

Returns the name of this class.

Implements cvr::functor.

virtual sort2* cvr::sort2::newInstance (  )  const [virtual]

Returns a pointer to a new instance of this functor.

Implements cvr::functor.


The documentation for this class was generated from the following file:

Generated on Sun Sep 20 22:09:05 2009 for CVR-Lib by Doxygen 1.5.8