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
nentries of a vector.Given a vector
data, this function sets the firstkentries of the vectorsmallestequal to the indexes of the k smallest entries from vectordatain ascending order. The vectorsmallestis resized if necessary to hold at leastkelements.If
kis zero ornis 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
indexis 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.