mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
Enable randomization of sort only in debug
This commit is contained in:
parent
1d69737395
commit
e13a0bfb39
@ -2,7 +2,7 @@
|
||||
|
||||
#include <pdqsort.h>
|
||||
|
||||
// #ifdef NDEBUG
|
||||
#ifndef NDEBUG
|
||||
|
||||
#include <pcg_random.hpp>
|
||||
#include <base/getThreadId.h>
|
||||
@ -52,12 +52,12 @@ void shuffle(RandomIt first, RandomIt last)
|
||||
std::shuffle(first, last, rng);
|
||||
}
|
||||
|
||||
// #else
|
||||
#else
|
||||
|
||||
// template <typename Comparator>
|
||||
// using ComparatorWrapper = Comparator;
|
||||
template <typename Comparator>
|
||||
using ComparatorWrapper = Comparator;
|
||||
|
||||
// #endif
|
||||
#endif
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wold-style-cast"
|
||||
@ -73,25 +73,33 @@ void nth_element(RandomIt first, RandomIt nth, RandomIt last)
|
||||
comparator compare;
|
||||
ComparatorWrapper<comparator> compare_wrapper = compare;
|
||||
|
||||
#ifndef NDEBUG
|
||||
::shuffle(first, last);
|
||||
#endif
|
||||
|
||||
::miniselect::floyd_rivest_select(first, nth, last, compare_wrapper);
|
||||
|
||||
#ifndef NDEBUG
|
||||
::shuffle(first, nth);
|
||||
|
||||
if (nth != last)
|
||||
::shuffle(nth + 1, last);
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename RandomIt, typename Compare>
|
||||
void partial_sort(RandomIt first, RandomIt middle, RandomIt last, Compare compare)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
::shuffle(first, last);
|
||||
#endif
|
||||
|
||||
ComparatorWrapper<Compare> compare_wrapper = compare;
|
||||
::miniselect::floyd_rivest_partial_sort(first, middle, last, compare_wrapper);
|
||||
|
||||
#ifndef NDEBUG
|
||||
::shuffle(middle, last);
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename RandomIt>
|
||||
@ -108,7 +116,9 @@ void partial_sort(RandomIt first, RandomIt middle, RandomIt last)
|
||||
template <typename RandomIt, typename Compare>
|
||||
void sort(RandomIt first, RandomIt last, Compare compare)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
::shuffle(first, last);
|
||||
#endif
|
||||
|
||||
ComparatorWrapper<Compare> compare_wrapper = compare;
|
||||
::pdqsort(first, last, compare_wrapper);
|
||||
|
Loading…
Reference in New Issue
Block a user