ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
EngineeredQuickSorts.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*---------------------- File EngineeredQuickSorts.h -----------------------*/
3/*--------------------------------------------------------------------------*/
54/*--------------------------------------------------------------------------*/
55/*----------------------------- DEFINITIONS --------------------------------*/
56/*--------------------------------------------------------------------------*/
57
58#ifndef __ADS_EngineeredQuickSorts
59 #define __ADS_EngineeredQuickSorts
60/* self-identification: #endif constant */
61
62/*--------------------------------------------------------------------------*/
63/*------------------------------ INCLUDES ----------------------------------*/
64/*--------------------------------------------------------------------------*/
65
66#include "ADS/Contract.h"
68#include "ADS/sort/Sorted.h"
69
70#include <algorithm>
71#include <bit>
72#include <cstddef>
73#include <cstdint>
74#include <functional>
75#include <type_traits>
76#include <utility>
77#include <vector>
78
79/*--------------------------------------------------------------------------*/
80/*--------------------------- NAMESPACE ------------------------------------*/
81/*--------------------------------------------------------------------------*/
82
83namespace ADS
84{
85
120template< SortStore Store ,
121 class T = std::ranges::range_value_t< std::remove_cvref_t< Store > > ,
122 class C = std::less<> >
123void dualPivotQuickSort( Store && A , C less = C() );
124
126template< class T , class C = std::less<> >
127void dualPivotQuickSort( std::vector< T > & A , C less = C() );
128
167template< SortStore Store ,
168 class T = std::ranges::range_value_t< std::remove_cvref_t< Store > > ,
169 class C = std::less<> >
170void threeWayQuickSort( Store && A , C less = C() );
171
173template< class T , class C = std::less<> >
174void threeWayQuickSort( std::vector< T > & A , C less = C() );
175
176/*--------------------------------------------------------------------------*/
177/*------------------------- THE SORTS OF A RANGE ---------------------------*/
178/*--------------------------------------------------------------------------*/
179
184template< SortRange R , class... P >
185 requires requires( std::vector< std::ranges::range_value_t< R > > & v ,
186 P &&... p )
187{
188 dualPivotQuickSort( v , std::forward< P >( p )... );
189 }
190decltype( auto ) dualPivotQuickSort( R && A , P &&... p )
191{
192 const auto f = [ & ]( auto & v ) -> decltype( auto ) {
193 return( dualPivotQuickSort( v , std::forward< P >( p )... ) );
194 };
195 return( detail::sortRange( A , f ) );
196 }
197
202template< SortRange R , class... P >
203 requires requires( std::vector< std::ranges::range_value_t< R > > & v ,
204 P &&... p )
205{
206 threeWayQuickSort( v , std::forward< P >( p )... );
207 }
208decltype( auto ) threeWayQuickSort( R && A , P &&... p )
209{
210 const auto f = [ & ]( auto & v ) -> decltype( auto ) {
211 return( threeWayQuickSort( v , std::forward< P >( p )... ) );
212 };
213 return( detail::sortRange( A , f ) );
214 }
215
216/*--------------------------------------------------------------------------*/
217
218} // end( namespace ADS )
219
220/*--------------------------------------------------------------------------*/
221/*-------------------------- IMPLEMENTATION --------------------------------*/
222/*--------------------------------------------------------------------------*/
223
224#include "ADS/sort/impl/EngineeredQuickSorts.tpp"
225
226/*--------------------------------------------------------------------------*/
227/*-------------------- THE PATTERN-DEFEATING QUICKSORT ---------------------*/
228/*--------------------------------------------------------------------------*/
229
230#include "ADS/sort/PdqSort.h"
231
232/*--------------------------------------------------------------------------*/
233
234#endif /* EngineeredQuickSorts.h included */
235
236/*--------------------------------------------------------------------------*/
237/*-------------------- End File EngineeredQuickSorts.h ---------------------*/
238/*--------------------------------------------------------------------------*/
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 pattern-defeating quicksort, beyond the book and beyond the quicksorts of Ferragina's book,...
The checks of the contracts of the sorts [see Contract.h]: a copy of the input kept only when the aud...
a range that the sorts take beside std::vector and std::span: random access, sized,...
Definition Sorted.h:153
the storage on which the sorts work in place, by reference: a std::vector or a std::span of its items...
Definition Sorted.h:178
void dualPivotQuickSort(Store &&A, C less=C())
the dual-pivot quicksort
void threeWayQuickSort(Store &&A, C less=C())
the quicksort with the three-way partition of Ferragina's book
Definition ADT.h:96