Function vector_smallest_index (o2scl)¶
-
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 firstk
entries of the vectorsmallest
equal to the indexes of the k smallest entries from vectordata
in ascending order. The vectorsmallest
is resized if necessary to hold at leastk
elements.If
k
is zero orn
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 tok
.
-
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.