51#ifndef __ADS_MergeSort
52 #define __ADS_MergeSort
109 class T = std::ranges::range_value_t< std::remove_cvref_t< Store > > ,
110 class C = std::less<> >
111void mergeParts( Store && A , std::vector< T > & B , std::size_t start ,
112 std::size_t mid , std::size_t end , C less = C() ,
113 long long * inv =
nullptr );
116template<
class T ,
class C = std::less<> >
117void mergeParts( std::vector< T > & A , std::vector< T > & B ,
119 std::size_t mid , std::size_t end , C less = C() ,
120 long long * inv =
nullptr );
152 class T = std::ranges::range_value_t< std::remove_cvref_t< Store > > ,
153 class C = std::less<> >
154void mergeSortRec( Store && A , std::vector< T > & B , std::size_t start ,
155 std::size_t end , std::size_t cutoff , C less = C() ,
156 long long * inv =
nullptr );
159template<
class T ,
class C = std::less<> >
161 std::size_t start , std::size_t end , std::size_t cutoff ,
162 C less = C() ,
long long * inv =
nullptr );
175 class T = std::ranges::range_value_t< std::remove_cvref_t< Store > > ,
176 class C = std::less<> >
177void mergeSort( Store && A , std::size_t cutoff = 1 , C less = C() );
180template<
class T ,
class C = std::less<> >
181void mergeSort( std::vector< T > & A , std::size_t cutoff = 1 , C less = C() );
202 class T = std::ranges::range_value_t< std::remove_cvref_t< Store > > ,
203 class C = std::less<> >
207template<
class T ,
class C = std::less<> >
228 class T = std::ranges::range_value_t< std::remove_cvref_t< Store > > ,
229 class C = std::less<> >
233template<
class T ,
class C = std::less<> >
260template<
class T ,
class C = std::less<> >
272 requires requires( std::vector< std::ranges::range_value_t< R > > & v ,
274{
mergeSort( v , std::forward< P >( p )... ); }
277 const auto f = [ & ](
auto & v ) ->
decltype(
auto ) {
278 return(
mergeSort( v , std::forward< P >( p )... ) );
280 return( detail::sortRange( A , f , f ) );
287template< SortRange R ,
class... P >
288 requires requires( std::vector< std::ranges::range_value_t< R > > & v ,
295 const auto f = [ & ](
auto & v ) ->
decltype(
auto ) {
298 return( detail::sortRange( A , f , f ) );
305template< SortRange R ,
class... P >
306 requires requires( std::vector< std::ranges::range_value_t< R > > & v ,
313 const auto f = [ & ](
auto & v ) ->
decltype(
auto ) {
316 return( detail::sortRange( A , f , f ) );
327#include "ADS/sort/impl/MergeSort.tpp"
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
Insertion Sort (section 2.7.2), as one sorts a hand of cards: is inserted in the sorted prefix ,...
The LIST of the book: a SEQUENCE [see ADT.h] realized as a bidirectional circular list of cells with ...
The checks of the contracts of the sorts [see Contract.h]: a copy of the input kept only when the aud...
a SEQUENCE realized as a bidirectional circular list with a sentinel, its cells from a pool if Pooled
Definition List.h:118
the storage on which the sorts of the book work in place, which read the items by their ranks only: a...
Definition Sorted.h:184
a range that the sorts take beside std::vector and std::span: random access, sized,...
Definition Sorted.h:153
void mergeSort(Store &&A, std::size_t cutoff=1, C less=C())
in increasing order, stable; the parts of at most items by insertionSort() (1 is the book)
void mergeSortBottomUp(Store &&A, C less=C())
the iterative Merge Sort: the runs of length are merged in pairs, for
long long countInversions(Store &&A, C less=C())
the number of inversions of , the pairs with , by Merge Sort, ; ends sorted
void mergeParts(Store &&A, std::vector< T > &B, std::size_t start, std::size_t mid, std::size_t end, C less=C(), long long *inv=nullptr)
and , sorted, merged through (the Merge() of the book); the inversions met are added to *inv,...
void mergeSortRec(Store &&A, std::vector< T > &B, std::size_t start, std::size_t end, std::size_t cutoff, C less=C(), long long *inv=nullptr)
the sort of (the MergeSort() of the book), insertionSort() on at most items; with also no merge of...