Function vector_smallest_index (o2scl)

O2scl : Function List

template<class vec_t, class data_t, class vec_size_t>
void o2scl::vector_smallest_index(size_t n, const vec_t &data, size_t k, vec_size_t &index)

Find the indexes of the k smallest entries among the first n entries of a vector.

Given a vector data, this function sets the first k entries of the vector smallest equal to the indexes of the k smallest entries from vector data in ascending order. The vector smallest is resized if necessary to hold at least k elements.

If k is zero or n is zero or \( k > n\), then this function calls the error handler.

Note

This \( {\cal O}(k N) \) algorithm is useful only when \( k << N \). The vector index is always resized to have a size equal to k.

template<class vec_t, class data_t, class vec_size_t>
void o2scl::vector_smallest_index(const vec_t &data, size_t k, vec_size_t &index)

Find the indexes of the k smallest entries of a vector.