Function vector_smallest (o2scl)¶
-
template<class vec_t, class data_t>
void o2scl::vector_smallest(size_t n, vec_t &data, size_t k, vec_t &smallest)¶ Find the k smallest entries of the first
nelements of a vector.Given a vector
dataof sizen, this function sets the firstkentries of the vectorsmallestto the k smallest entries from vectordatain ascending order. The vectorsmallestmust be allocated beforehand to hold at leastkelements.This works similarly to the GSL function
gsl_sort_smallest().If
kis zero, then this function does nothing and returns o2scl::success .Note
This \( {\cal O}(k N) \) algorithm is useful only when \( k << N \).
-
template<class vec_t, class data_t>
void o2scl::vector_smallest(vec_t &data, size_t k, vec_t &smallest)¶ Find the k smallest entries of a vector of a vector.
Given a vector
data, this function sets the firstkentries of the vectorsmallestto the k smallest entries from vectordatain ascending order. The vectorsmallestis resized if necessary to hold at leastkelements.This works similarly to the GSL function
gsl_sort_smallest().If
kis zero, then this function does nothing and returns o2scl::success .Note
This \( {\cal O}(k N) \) algorithm is useful only when \( k << N \).