Go to the documentation of this file.
14 #ifndef SORTER_INCLUDED
15 #define SORTER_INCLUDED
52 void sort(std::vector<T>& v);
55 void sort(std::vector<T>& v,
const size_t nelem);
58 std::vector<int>
sort_index(std::vector<T>& v);
61 std::vector<int>
sort_index(std::vector<T>& v,
const size_t nelem);
64 bool comp(
const T& lhs,
const T& rhs);
70 struct by_abs_descend;
77 typedef std::pair<int, T>
pair_t;
94 bool operator()(
const T& lhs,
const T& rhs)
const = 0;
98 return operator()(lhs.second, rhs.second);
109 {
return abs(lhs) < abs(rhs); }
120 return abs(lhs) > abs(rhs);
177 if (
type ==
"abs_ascending")
m_order =
new by_abs_ascend;
178 if (
type ==
"abs_descending")
m_order =
new by_abs_descend;
180 if (
type ==
"descending")
m_order =
new by_descend;
200 return std::sort(v.begin(), v.end(), proxy(*
m_order));
211 return std::sort(v.begin(), v.begin() + nelem, proxy(*
m_order));
222 std::vector<pair_t> w(v.size());
224 for (
size_t i = 0, n = v.size(); i < n; ++i) {
229 std::sort(w.begin(), w.end(), proxy(*
m_order));
231 std::vector<int>
idx(v.size());
233 for (
size_t i = 0, n = v.size(); i < n; ++i) {
249 std::vector<pair_t> w(v.size());
251 for (
size_t i = 0, n = v.size(); i < n; ++i) {
256 std::sort(w.begin(), w.begin() + nelem, proxy(*
m_order));
258 std::vector<int>
idx(v.size());
260 for (
size_t i = 0, n = v.size(); i < n; ++i) {
275 return m_order->operator()(lhs, rhs);
286 bool operator()(
const dcomplex& lhs,
const dcomplex& rhs)
const
301 bool operator()(
const dcomplex& lhs,
const dcomplex& rhs)
const
317 bool operator()(
const fcomplex& lhs,
const fcomplex& rhs)
const
332 bool operator()(
const fcomplex& lhs,
const fcomplex& rhs)
const
bool operator()(const pair_t &lhs, const pair_t &rhs) const
base class for sort ordering
virtual bool operator()(const T &lhs, const T &rhs) const
std::pair< int, T > pair_t
virtual bool operator()(const dcomplex &lhs, const dcomplex &rhs) const
const Sorter::by_order & m_order
Sorter(const std::string &type)
constructor with sort ordering as a string arg
std::pair< int, double > pair_t
virtual bool operator()(const dcomplex &lhs, const dcomplex &rhs) const
std::vector< int > sort_index(std::vector< double > &v)
sort an array and return list of index; v is sorted on exit.
proxy(const Sorter::by_order &order)
int idx(const int in, const int Nin, const int ist, const int Nx2, const int Ny, const int leo, const int Nvol2, const int ex)
bool comp(const double lhs, const double rhs)
call sort condition.
virtual bool operator()(const fcomplex &lhs, const fcomplex &rhs) const
virtual bool operator()(const fcomplex &lhs, const fcomplex &rhs) const
void sort(std::vector< double > &v)
sort an array of values; v is sorted on exit.
Sorter & operator=(const Sorter &)
bool operator()(const T &lhs, const T &rhs) const
void crucial(const char *format,...)
bool operator()(const T &lhs, const T &rhs) const
bool operator()(const T &lhs, const T &rhs) const
virtual bool operator()(const T &lhs, const T &rhs) const
virtual ~Sorter()
destructor
bool operator()(const pair_t &lhs, const pair_t &rhs) const