LTI-Lib latest version v1.9 - last update 10 Apr 2010

lti::sort< T > Class Template Reference

Sort vectors. More...

#include <ltiSort.h>

Inheritance diagram for lti::sort< T >:
Inheritance graph
[legend]
Collaboration diagram for lti::sort< T >:
Collaboration graph
[legend]

List of all members.

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
sortcopy (const sort &other)
virtual functorclone () const
const parametersgetParameters () const
bool updateParameters ()

Protected Attributes

Shadows of the parameters to avoid a function access



int thresholdForBubble
parameters::eOrder order

Detailed Description

template<class T>
class lti::sort< T >

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:
lti::scramble, lti::sort2, lti::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

template<class T>
lti::sort< T >::sort ( const bool &  descendingOrder = false  ) 

Default constructor.

template<class T>
lti::sort< T >::sort ( const parameters par  ) 

Construct with given parameters.

template<class T>
lti::sort< T >::sort ( const sort< T > &  other  ) 

Copy constructor.

Parameters:
other the object to be copied
template<class T>
virtual lti::sort< T >::~sort (  )  [virtual]

Destructor.


Member Function Documentation

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

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>
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 |
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>
virtual bool lti::sort< T >::apply ( vector< T > &  srcdest  )  const [virtual]

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>
virtual bool lti::sort< T >::apply ( matrix< T > &  srcdest  )  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 |
Parameters:
srcdest matrix<T> with the source data. The result will be left here too.
Returns:
true if successful, false otherwise
template<class T>
virtual functor* lti::sort< T >::clone (  )  const [virtual]

Returns a pointer to a clone of this functor.

Implements lti::functor.

Reimplemented in lti::sort2< T, U >.

template<class T>
sort& lti::sort< T >::copy ( const sort< T > &  other  ) 

Copy data of "other" functor.

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

Reimplemented from lti::functor.

Reimplemented in lti::sort2< T, U >.

template<class T>
const parameters& lti::sort< T >::getParameters (  )  const

Returns used parameters.

Reimplemented from lti::functor.

Reimplemented in lti::sort2< T, U >.

template<class T>
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 >.

template<class T>
bool lti::sort< T >::updateParameters (  )  [virtual]

Set parameters.

Reimplemented from lti::functor.


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

Generated on Sat Apr 10 15:28:44 2010 for LTI-Lib by Doxygen 1.6.1