ADS
Algorithms and Data Structures
Toggle main menu visibility
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
"
79
#include "
ADS/sort/EngineeredQuickSorts.h
"
80
#include "
ADS/sort/InsertionSort.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
96
namespace
ADS
97
{
98
135
template
<
SortStore
Store ,
136
class
T = std::ranges::range_value_t< std::remove_cvref_t< Store > > ,
137
class
C = std::less<> >
138
void
pdqSort
( Store && A , C less = C() );
139
141
template
<
class
T ,
class
C = std::less<> >
142
void
pdqSort
( std::vector< T > & A , C less = C() );
143
144
/*--------------------------------------------------------------------------*/
145
/*------------------------- THE SORTS OF A RANGE ---------------------------*/
146
/*--------------------------------------------------------------------------*/
147
152
template
<
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 )... ); }
156
decltype
( 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
/*--------------------------------------------------------------------------*/
Contract.h
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
EngineeredQuickSorts.h
The quicksorts beyond the quicksort of Montresor's book [see QuickSort.h for it and its improvements ...
InsertionSort.h
Insertion Sort (section 2.7.2), as one sorts a hand of cards: is inserted in the sorted prefix ,...
Sorted.h
The checks of the contracts of the sorts [see Contract.h]: a copy of the input kept only when the aud...
ADS::SortRange
a range that the sorts take beside std::vector and std::span: random access, sized,...
Definition
Sorted.h:153
ADS::SortStore
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
ADS::pdqSort
void pdqSort(Store &&A, C less=C())
the pattern-defeating quicksort
ADS
Definition
ADT.h:96
ADS
sort
PdqSort.h
Generated by
1.17.0