ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
VectorQuickSort.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*------------------------- File VectorQuickSort.h -------------------------*/
3/*--------------------------------------------------------------------------*/
124/*--------------------------------------------------------------------------*/
125/*----------------------------- DEFINITIONS --------------------------------*/
126/*--------------------------------------------------------------------------*/
127
128#ifndef __ADS_VectorQuickSort
129 #define __ADS_VectorQuickSort
130/* self-identification: #endif constant */
131
132/*--------------------------------------------------------------------------*/
133/*------------------------------ INCLUDES ----------------------------------*/
134/*--------------------------------------------------------------------------*/
135
136#include "ADS/Contract.h"
137#include "ADS/Simd.h" // ADS_SIMD, and the dispatch before hwy/highway.h
138#include "ADS/memory/Prefetch.h"
139#include "ADS/sort/Sorted.h"
140
141#include <algorithm>
142#include <array>
143#include <bit>
144#include <cstddef>
145#include <cstdint>
146#include <cstring>
147#include <limits>
148#include <memory>
149#include <type_traits>
150#include <utility>
151#include <vector>
152
156#ifndef ADS_VECTOR_SORT
157 #define ADS_VECTOR_SORT ADS_SIMD
158#endif
159
160#if ADS_VECTOR_SORT
161 #include <hwy/contrib/sort/vqsort.h>
162#endif
163
164/*--------------------------------------------------------------------------*/
165/*--------------------------- NAMESPACE ------------------------------------*/
166/*--------------------------------------------------------------------------*/
167
168namespace ADS
169{
170
173inline constexpr bool kVectorSort = ADS_VECTOR_SORT != 0;
174
177template< class T >
178concept VectorKey =
179 ( std::is_integral_v< T > || std::is_floating_point_v< T > ) &&
180 ( ( sizeof( T ) == 4 ) || ( sizeof( T ) == 8 ) ) &&
181 ( ! std::is_same_v< T , bool > );
182
192template< SortStore Store , VectorKey T = std::ranges::range_value_t<
193 std::remove_cvref_t< Store > > >
194void vectorQuickSort( Store && A );
195
197template< VectorKey T >
198void vectorQuickSort( std::vector< T > & A );
199
230template< VectorKey T >
231void vectorQuickSort( T * a , std::size_t n );
232
233/*--------------------------------------------------------------------------*/
234/*------------------------- THE SORTS OF A RANGE ---------------------------*/
235/*--------------------------------------------------------------------------*/
236
241template< SortRange R , class... P >
242 requires requires( std::vector< std::ranges::range_value_t< R > > & v ,
243 P &&... p )
244{
245 vectorQuickSort( v , std::forward< P >( p )... );
246 }
247decltype( auto ) vectorQuickSort( R && A , P &&... p )
248{
249 const auto f = [ & ]( auto & v ) -> decltype( auto ) {
250 return( vectorQuickSort( v , std::forward< P >( p )... ) );
251 };
252 return( detail::sortRange( A , f ) );
253 }
254
255/*--------------------------------------------------------------------------*/
256
257} // end( namespace ADS )
258
259/*--------------------------------------------------------------------------*/
260/*-------------------------- IMPLEMENTATION --------------------------------*/
261/*--------------------------------------------------------------------------*/
262
263#include "ADS/sort/impl/VectorQuickSort.tpp"
264
265/*--------------------------------------------------------------------------*/
266
267#endif /* VectorQuickSort.h included */
268
269/*--------------------------------------------------------------------------*/
270/*----------------------- End File VectorQuickSort.h -----------------------*/
271/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The prefetch of a line of the cache, beyond the book: ADS::prefetch( p ) asks the processor to bring ...
The vector kernels of ADS on Google Highway, with ADS_WITH_HIGHWAY: the loops over arrays that a stru...
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
the types that vectorQuickSort() sorts: integers and floating point numbers of 32 or 64 bits
Definition VectorQuickSort.h:178
void vectorQuickSort(Store &&A)
the quicksort of in the lanes of the vector registers, by the natural order (the total order of IEEE...
constexpr bool kVectorSort
true if vectorQuickSort() runs in the vectors of the processor, by the quicksort of Highway,...
Definition VectorQuickSort.h:173
#define ADS_VECTOR_SORT
1 if the sort is the quicksort of Highway on the vectors of the processor, 0 if the portable code; by...
Definition VectorQuickSort.h:157
Definition ADT.h:96