40 #ifndef GEOGRAM_BASIC_ALGORITHM
41 #define GEOGRAM_BASIC_ALGORITHM
45 #if defined(GEO_OS_LINUX) && defined(GEO_OPENMP)
46 #if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 4) && !defined(GEO_OS_ANDROID)
47 #include <parallel/algorithm>
48 #define GEO_USE_GCC_PARALLEL_STL
50 #elif defined(GEO_OS_WINDOWS)
51 #if (_MSC_VER >= 1700)
53 #define GEO_USE_MSVC_PARALLEL_STL
89 template <
typename ITERATOR>
91 const ITERATOR& begin,
const ITERATOR& end
94 #if defined(GEO_USE_GCC_PARALLEL_STL)
96 #elif defined(GEO_USE_MSVC_PARALLEL_STL)
97 concurrency::parallel_sort(begin, end);
125 template <
typename ITERATOR,
typename CMP>
127 const ITERATOR& begin,
const ITERATOR& end,
const CMP& cmp
130 #if defined(GEO_USE_GCC_PARALLEL_STL)
132 #elif defined(GEO_USE_MSVC_PARALLEL_STL)
133 concurrency::parallel_sort(begin, end, cmp);
153 std::unique(v.begin(), v.end()), v.end()
163 template <
typename ITERATOR>
inline void sort_3(ITERATOR items) {
164 if (items[0]> items[1]) {
165 std::swap(items[0], items[1]);
167 if (items[1]> items[2]) {
168 std::swap(items[1], items[2]);
170 if (items[0]> items[1]) {
171 std::swap(items[0], items[1]);
181 template <
typename ITERATOR>
inline void sort_4(ITERATOR items) {
182 if (items[1] < items[0]) {
183 std::swap(items[0], items[1]);
185 if (items[3] < items[2]) {
186 std::swap(items[2], items[3]);
188 if (items[2] < items[0]) {
189 std::swap(items[0], items[2]);
190 std::swap(items[1], items[3]);
192 if (items[2] < items[1]) {
193 std::swap(items[1], items[2]);
195 if (items[3] < items[2]) {
196 std::swap(items[2], items[3]);
207 template <
typename ITERATOR>
209 const ITERATOR& begin,
const ITERATOR& end
211 std::random_device rng;
212 std::mt19937 urng(rng());
213 std::shuffle(begin, end, urng);
Common include file, providing basic definitions. Should be included before anything else by all head...
Global Vorpaline namespace.
void sort_unique(VECTOR &v)
Sorts a vector and suppresses all duplicated elements.
bool uses_parallel_algorithm()
Checks whether parallel algorithms are used.
void sort_4(ITERATOR items)
Specialized sort routine for 4 elements.
void sort(const ITERATOR &begin, const ITERATOR &end)
Sorts elements in parallel.
void sort(const ITERATOR &begin, const ITERATOR &end, const CMP &cmp)
Sorts elements in parallel.
void sort_3(ITERATOR items)
Specialized sort routine for 3 elements.
void random_shuffle(const ITERATOR &begin, const ITERATOR &end)
Applies a random permutation to a sequence.