huc::sort::MergeInPlace< IT, Compare > Class Template Reference

#include <merge.hxx>

Public Member Functions

void operator() (const IT &begin, const IT &pivot, const IT &end)

Detailed Description

template<typename IT, typename Compare = std::less<typename std::iterator_traits<IT>::value_type>>
class huc::sort::MergeInPlace< IT, Compare >

MergeInplace Functor - In-Place merging of two ordered sequences of a collection contained in [begin, middle[ and [middle, end[.

Both sequence [bengin, middle[ and [middle, end[ need to be ordered.
use MergeWithBuffer to proceed the merge using a buffer: Takes higher memory consumption and lower computation consumption.
Template Parameters
ITtype using to go through the collection.
Comparefunctor type (std::less_equal in order, std::greater_equal for inverse order).
begin,middle,enditerators to the initial and final positions of the sequence to be sorted. The range used is [first,last), which contains all the elements between first and last, including the element pointed by first but not the element pointed by last.

Definition at line 47 of file merge.hxx.

Member Function Documentation

template<typename IT, typename Compare = std::less<typename std::iterator_traits<IT>::value_type>>
void huc::sort::MergeInPlace< IT, Compare >::operator() ( const IT &  begin,
const IT &  pivot,
const IT &  end 

Definition at line 50 of file merge.hxx.

51  {
52  if (std::distance(begin, pivot) < 1 || std::distance(pivot, end) < 1)
53  return;
55  // Use first half as receiver
56  for(auto curBegin = begin; curBegin < pivot; ++curBegin)
57  {
58  if (Compare()(*curBegin, *pivot))
59  continue;
61  // Place it at the beginning of the second list
62  std::swap(*curBegin, *pivot);
64  // Displace the higher value in the right place of the second list by swapping
65  auto it = pivot;
66  for (; it != end - 1; ++it)
67  {
68  if (Compare()(*it, *(it + 1)))
69  break;
71  std::swap(*it, *(it + 1));
72  }
73  }
74  }

The documentation for this class was generated from the following file: