ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ShellSort.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*---------------------------- File ShellSort.h ----------------------------*/
3/*--------------------------------------------------------------------------*/
49/*--------------------------------------------------------------------------*/
50/*----------------------------- DEFINITIONS --------------------------------*/
51/*--------------------------------------------------------------------------*/
52
53#ifndef __ADS_ShellSort
54 #define __ADS_ShellSort
55/* self-identification: #endif constant */
56
57/*--------------------------------------------------------------------------*/
58/*------------------------------ INCLUDES ----------------------------------*/
59/*--------------------------------------------------------------------------*/
60
61#include "ADS/Contract.h"
62#include "ADS/sort/Sorted.h"
63
64#include <algorithm>
65#include <cstddef>
66#include <functional>
67#include <vector>
68
69/*--------------------------------------------------------------------------*/
70/*--------------------------- NAMESPACE ------------------------------------*/
71/*--------------------------------------------------------------------------*/
72
73namespace ADS
74{
75
79inline std::vector< std::size_t > knuthGaps( std::size_t n );
80
84inline std::vector< std::size_t > shellGaps( std::size_t n );
85
89inline std::vector< std::size_t > hibbardGaps( std::size_t n );
90
93inline std::vector< std::size_t > prattGaps( std::size_t n );
94
98inline std::vector< std::size_t > ciuraGaps( std::size_t n );
99
119template< RankStore Store ,
120 class T = std::ranges::range_value_t< std::remove_cvref_t< Store > > ,
121 class C = std::less<> >
122void shellSort( Store && A , const std::vector< std::size_t > & gaps ,
123 C less = C() );
124
126template< class T , class C = std::less<> >
127void shellSort( std::vector< T > & A ,
128 const std::vector< std::size_t > & gaps ,
129 C less = C() );
130
138template< RankStore Store ,
139 class T = std::ranges::range_value_t< std::remove_cvref_t< Store > > ,
140 class C = std::less<> >
141void shellSort( Store && A , C less = C() );
142
144template< class T , class C = std::less<> >
145void shellSort( std::vector< T > & A , C less = C() );
146
147/*--------------------------------------------------------------------------*/
148/*------------------------- THE SORTS OF A RANGE ---------------------------*/
149/*--------------------------------------------------------------------------*/
150
155template< SortRange R , class... P >
156 requires requires( std::vector< std::ranges::range_value_t< R > > & v ,
157 P &&... p )
158{ shellSort( v , std::forward< P >( p )... ); }
159decltype( auto ) shellSort( R && A , P &&... p )
160{
161 const auto f = [ & ]( auto & v ) -> decltype( auto ) {
162 return( shellSort( v , std::forward< P >( p )... ) );
163 };
164 return( detail::sortRange( A , f , f ) );
165 }
166
167/*--------------------------------------------------------------------------*/
168
169} // end( namespace ADS )
170
171/*--------------------------------------------------------------------------*/
172/*-------------------------- IMPLEMENTATION --------------------------------*/
173/*--------------------------------------------------------------------------*/
174
175#include "ADS/sort/impl/ShellSort.tpp"
176
177/*--------------------------------------------------------------------------*/
178
179#endif /* ShellSort.h included */
180
181/*--------------------------------------------------------------------------*/
182/*-------------------------- End File ShellSort.h --------------------------*/
183/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The checks of the contracts of the sorts [see Contract.h]: a copy of the input kept only when the aud...
the storage on which the sorts of the book work in place, which read the items by their ranks only: a...
Definition Sorted.h:184
a range that the sorts take beside std::vector and std::span: random access, sized,...
Definition Sorted.h:153
std::vector< std::size_t > prattGaps(std::size_t n)
the gaps up to , increasing
std::vector< std::size_t > shellGaps(std::size_t n)
the gaps of Shell, each half the next one, increasing
void shellSort(Store &&A, const std::vector< std::size_t > &gaps, C less=C())
the Shell Sort with the given gaps, increasing and starting from 1
std::vector< std::size_t > knuthGaps(std::size_t n)
the gaps , below ( ), increasing
std::vector< std::size_t > hibbardGaps(std::size_t n)
the gaps below ( ), increasing
std::vector< std::size_t > ciuraGaps(std::size_t n)
the gaps of Ciura below , and then each times the one before, increasing
Definition ADT.h:96