PSCF v1.4.0

Utilities for sorting real values. More...

Classes

struct  Pscf::Sort::Item< T >
 Struct with value and index, to keep track of permutation. More...

Functions

template<typename T>
bool Pscf::Sort::operator< (Item< T > const &a, Item< T > const &b)
 Less than comparator for Item<T> objects.
template<typename T>
void Pscf::Sort::sort (std::vector< Item< T > > &items)
 Sort a std::vector< Item<T> > by ascending item value.
template<typename T>
void Pscf::Sort::findBunches (std::vector< Item< T > > const &items, GArray< Bunch > &bunches, T epsilon)
 Identify "bunches" of equal values within a sorted vector.

Detailed Description

Utilities for sorting real values.

Function Documentation

◆ operator<()

template<typename T>
bool Pscf::Sort::operator< ( Item< T > const & a,
Item< T > const & b )

Less than comparator for Item<T> objects.

Comparison based on Item<T>::value member.

Parameters
a1st item
b2nd item

Definition at line 66 of file Sort.h.

◆ sort()

template<typename T>
void Pscf::Sort::sort ( std::vector< Item< T > > & items)

Sort a std::vector< Item<T> > by ascending item value.

On return, array "items" is sorted with non-descending values.

Parameters
itemsarray of comparable items

Definition at line 22 of file Sort.cpp.

Referenced by Pscf::Prdc::Cpu::WaveList< D >::sortWaves(), Pscf::Prdc::Cuda::WaveList< D >::sortWaves(), and Pscf::Prdc::sortWaves().

◆ findBunches()

template<typename T>
void Pscf::Sort::findBunches ( std::vector< Item< T > > const & items,
GArray< Bunch > & bunches,
T epsilon )

Identify "bunches" of equal values within a sorted vector.

The array "items" must be sorted on entry to this function. The "sort" function is thus called before this.

On return, each element of array "bunches" contains the begin and end indices delimiting a "bunch" of contiguous items in the sorted "items" array with equal value. Each item belongs to one bunch, and each bunch contains one or more items. Bunches are listed in order increasing beginning index, and span the entire array.

Parameters
itemssorted array of items
bunchesarray of bunches of items with equal value
epsilontolerance

Definition at line 29 of file Sort.cpp.

References Util::GArray< Data >::append(), Util::GArray< Data >::clear(), and UTIL_CHECK.

Referenced by Pscf::Prdc::Cpu::WaveList< D >::sortWaves(), Pscf::Prdc::Cuda::WaveList< D >::sortWaves(), and Pscf::Prdc::sortWaves().