33 #ifndef SHARK_CORE_FUNCTIONAL_H 34 #define SHARK_CORE_FUNCTIONAL_H 36 #include <boost/range/numeric.hpp> 43 template<
class Iterator,
class Rng>
44 void shuffle(Iterator begin, Iterator end, Rng& rng){
46 Iterator next = begin;
47 for (std::size_t index = 1; ++next != end; ++index){
54 template<
class RandomAccessIterator,
class Rng>
55 void partial_shuffle(RandomAccessIterator begin, RandomAccessIterator middle, RandomAccessIterator end, Rng& rng){
70 template<
class RandomAccessIterator>
71 void partial_shuffle(RandomAccessIterator begin, RandomAccessIterator middle, RandomAccessIterator end){
81 std::size_t size = range.size();
82 std::size_t medianPos = (size+1)/2;
83 auto medianIter = boost::begin(range)+medianPos;
85 std::nth_element(range.begin(),medianIter, range.end());
91 typename boost::range_iterator<Range>::type
median_element(Range
const& rangeAdaptor){
92 Range adaptorCopy(rangeAdaptor);
104 template<
class Range>
106 auto begin = range.begin();
107 auto end = range.end();
112 auto median = *medianIter;
113 typedef typename Range::const_reference const_ref;
114 auto left = std::partition(begin,medianIter,[&](const_ref elem){
return elem < median;});
115 auto right = std::partition(medianIter,end,[&](const_ref elem){
return elem == median;});
123 if (left - begin >= end - right)
132 template<
class Range>
134 Range adaptorCopy(rangeAdaptor);