ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
PdqSort.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*----------------------------- File PdqSort.h -----------------------------*/
3/*--------------------------------------------------------------------------*/
66/*--------------------------------------------------------------------------*/
67/*----------------------------- DEFINITIONS --------------------------------*/
68/*--------------------------------------------------------------------------*/
69
70#ifndef __ADS_PdqSort
71 #define __ADS_PdqSort
72/* self-identification: #endif constant */
73
74/*--------------------------------------------------------------------------*/
75/*------------------------------ INCLUDES ----------------------------------*/
76/*--------------------------------------------------------------------------*/
77
78#include "ADS/Contract.h"
81#include "ADS/sort/Sorted.h"
82
83#include <algorithm>
84#include <bit>
85#include <cstddef>
86#include <cstdint>
87#include <functional>
88#include <type_traits>
89#include <utility>
90#include <vector>
91
92/*--------------------------------------------------------------------------*/
93/*--------------------------- NAMESPACE ------------------------------------*/
94/*--------------------------------------------------------------------------*/
95
96namespace ADS
97{
98
135template< SortStore Store ,
136 class T = std::ranges::range_value_t< std::remove_cvref_t< Store > > ,
137 class C = std::less<> >
138void pdqSort( Store && A , C less = C() );
139
141template< class T , class C = std::less<> >
142void pdqSort( std::vector< T > & A , C less = C() );
143
144/*--------------------------------------------------------------------------*/
145/*------------------------- THE SORTS OF A RANGE ---------------------------*/
146/*--------------------------------------------------------------------------*/
147
152template< SortRange R , class... P >
153 requires requires( std::vector< std::ranges::range_value_t< R > > & v ,
154 P &&... p )
155{ pdqSort( v , std::forward< P >( p )... ); }
156decltype( auto ) pdqSort( R && A , P &&... p )
157{
158 const auto f = [ & ]( auto & v ) -> decltype( auto ) {
159 return( pdqSort( v , std::forward< P >( p )... ) );
160 };
161 return( detail::sortRange( A , f ) );
162 }
163
164/*--------------------------------------------------------------------------*/
165
166} // end( namespace ADS )
167
168/*--------------------------------------------------------------------------*/
169/*-------------------------- IMPLEMENTATION --------------------------------*/
170/*--------------------------------------------------------------------------*/
171
172#include "ADS/sort/impl/PdqSort.tpp"
173
174/*--------------------------------------------------------------------------*/
175
176#endif /* PdqSort.h included */
177
178/*--------------------------------------------------------------------------*/
179/*--------------------------- End File PdqSort.h ---------------------------*/
180/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The quicksorts beyond the quicksort of Montresor's book [see QuickSort.h for it and its improvements ...
Insertion Sort (section 2.7.2), as one sorts a hand of cards: is inserted in the sorted prefix ,...
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 pdqSort(Store &&A, C less=C())
the pattern-defeating quicksort
Definition ADT.h:96