ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
SampleSort.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*--------------------------- File SampleSort.h ----------------------------*/
3/*--------------------------------------------------------------------------*/
81/*--------------------------------------------------------------------------*/
82/*----------------------------- DEFINITIONS --------------------------------*/
83/*--------------------------------------------------------------------------*/
84
85#ifndef __ADS_SampleSort
86 #define __ADS_SampleSort
87/* self-identification: #endif constant */
88
89/*--------------------------------------------------------------------------*/
90/*------------------------------ INCLUDES ----------------------------------*/
91/*--------------------------------------------------------------------------*/
92
93#include "ADS/Contract.h"
95#include "ADS/sort/Sorted.h"
96
97#include <algorithm>
98#include <bit>
99#include <cstddef>
100#include <cstdint>
101#include <functional>
102#include <memory>
103#include <utility>
104#include <vector>
105
106/*--------------------------------------------------------------------------*/
107/*--------------------------- NAMESPACE ------------------------------------*/
108/*--------------------------------------------------------------------------*/
109
110namespace ADS
111{
112
141template< SortStore Store ,
142 class T = std::ranges::range_value_t< std::remove_cvref_t< Store > > ,
143 class C = std::less<> >
144void sampleSort( Store && A , C less = C() );
145
147template< class T , class C = std::less<> >
148void sampleSort( std::vector< T > & A , C less = C() );
149
150/*--------------------------------------------------------------------------*/
151/*------------------------- THE SORTS OF A RANGE ---------------------------*/
152/*--------------------------------------------------------------------------*/
153
158template< SortRange R , class... P >
159 requires requires( std::vector< std::ranges::range_value_t< R > > & v ,
160 P &&... p )
161{ sampleSort( v , std::forward< P >( p )... ); }
162decltype( auto ) sampleSort( R && A , P &&... p )
163{
164 const auto f = [ & ]( auto & v ) -> decltype( auto ) {
165 return( sampleSort( v , std::forward< P >( p )... ) );
166 };
167 return( detail::sortRange( A , f ) );
168 }
169
170/*--------------------------------------------------------------------------*/
171
172} // end( namespace ADS )
173
174/*--------------------------------------------------------------------------*/
175/*-------------------------- IMPLEMENTATION --------------------------------*/
176/*--------------------------------------------------------------------------*/
177
178#include "ADS/sort/impl/SampleSort.tpp"
179
180/*--------------------------------------------------------------------------*/
181
182#endif /* SampleSort.h included */
183
184/*--------------------------------------------------------------------------*/
185/*------------------------- End File SampleSort.h --------------------------*/
186/*--------------------------------------------------------------------------*/
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 ...
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 sampleSort(Store &&A, C less=C())
the in-place super scalar samplesort of by less
Definition ADT.h:96