index_sort

View page source

Returns Indices that Sort a Vector

Syntax

# include <cppad/utility/index_sort.hpp>

index_sort ( keys , ind )

keys

The argument keys has prototype

const KeyVector & keys

where KeyVector is a SimpleVector class with elements that support the < operation.

ind

The argument ind has prototype

SizeVector & ind

where SizeVector is a SimpleVector class with elements of type Size_t , where Size_t is an integral type. The routine CheckSimpleVector will generate an error message if this is not the case.

Input

The size of ind must be the same as the size of keys and the value of its input elements does not matter.

Return

Upon return, ind is a permutation of the set of indices that yields increasing order for keys . In other words, for all i != j ,

ind [ i ] != ind [ j ]

and for i = 0 , … , size -2 ,

( keys [ ind [ i +1] ] < keys [ ind [ i ] ] ) == false

Example

The file index_sort.cpp contains an example and test of this routine. It return true if it succeeds and false otherwise.