CVR-Lib last update 20 Sep 2009

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

Sort vectors. More...

#include <cvrSort.h>

Inheritance diagram for cvr::sort:

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

Collaboration graph
[legend]

List of all members.

Classes

class  parameters
 The parameters for the class sort. More...

Public Member Functions

 sort (const eSortingOrder sortingOrder=Ascending)
 sort (const parameters &par)
 sort (const sort &other)
virtual ~sort ()
template<class T >
bool apply (matrix< T > &srcdest) const
template<class T >
bool apply (vector< T > &srcdest) const
template<class T >
bool apply (const matrix< T > &src, matrix< T > &dest) const
template<class T >
bool apply (const vector< T > &src, vector< T > &dest) const
sort & copy (const sort &other)
virtual const std::string & name () const
virtual sort * clone () const
virtual sort * newInstance () const
const parameters & getParameters () const
bool updateParameters ()


Detailed Description

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

See also:
cvr::scramble, cvr::sort2, cvr::quickPartialSort
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.


Constructor & Destructor Documentation

cvr::sort::sort ( const eSortingOrder  sortingOrder = Ascending  ) 

Default constructor.

cvr::sort::sort ( const parameters &  par  ) 

Construct with given parameters.

cvr::sort::sort ( const sort &  other  ) 

Copy constructor.

Parameters:
other the object to be copied

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

Destructor.


Member Function Documentation

template<class T >
bool cvr::sort::apply ( const vector< T > &  src,
vector< T > &  dest 
) const [inline]

Operates on a copy of the given parameters.

Parameters:
src vector<T> with the source data.
dest vector<T> where the result will be left.
Returns:
true if successful, false otherwise

template<class T >
bool cvr::sort::apply ( const matrix< T > &  src,
matrix< T > &  dest 
) const [inline]

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 |
Parameters:
src matrix<T> with the source data.
dest matrix<T> where the result will be left.
Returns:
true if successful, false otherwise

template<class T >
bool cvr::sort::apply ( vector< T > &  srcdest  )  const [inline]

Operates on the given parameter.

Parameters:
srcdest vector<T> with the source data. The result will be left here too.
Returns:
true if successful, false otherwise

template<class T >
bool cvr::sort::apply ( matrix< T > &  srcdest  )  const [inline]

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 |
Parameters:
srcdest matrix<T> with the source data. The result will be left here too.
Returns:
true if successful, false otherwise

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

Returns a pointer to a clone of this functor.

Implements cvr::functor.

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

Copy data of "other" functor.

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

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

Returns used parameters.

Reimplemented from cvr::parametersManager.

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

Returns the name of this class.

Implements cvr::functor.

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

Returns a pointer to a new instance of this functor.

Implements cvr::functor.

bool cvr::sort::updateParameters (  )  [virtual]

Set parameters.

Reimplemented from cvr::parametersManager.


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

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