ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
CountingSort.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*-------------------------- File CountingSort.h ---------------------------*/
3/*--------------------------------------------------------------------------*/
27/*--------------------------------------------------------------------------*/
28/*----------------------------- DEFINITIONS --------------------------------*/
29/*--------------------------------------------------------------------------*/
30
31#ifndef __ADS_CountingSort
32 #define __ADS_CountingSort
33/* self-identification: #endif constant */
34
35/*--------------------------------------------------------------------------*/
36/*------------------------------ INCLUDES ----------------------------------*/
37/*--------------------------------------------------------------------------*/
38
39#include "ADS/Contract.h"
40#include "ADS/sort/Sorted.h"
41
42#include <algorithm>
43#include <cstddef>
44#include <functional>
45#include <stdexcept>
46#include <vector>
47
48/*--------------------------------------------------------------------------*/
49/*--------------------------- NAMESPACE ------------------------------------*/
50/*--------------------------------------------------------------------------*/
51
52namespace ADS
53{
54
74template< RankStore Store , class T = std::ranges::range_value_t<
75 std::remove_cvref_t< Store > > >
76void countingSort( Store && A , std::size_t k );
77
79template< class T >
80void countingSort( std::vector< T > & A , std::size_t k );
81
82/*--------------------------------------------------------------------------*/
83/*------------------------- THE SORTS OF A RANGE ---------------------------*/
84/*--------------------------------------------------------------------------*/
85
90template< SortRange R , class... P >
91 requires requires( std::vector< std::ranges::range_value_t< R > > & v ,
92 P &&... p )
93{
94 countingSort( v , std::forward< P >( p )... );
95 }
96decltype( auto ) countingSort( R && A , P &&... p )
97{
98 const auto f = [ & ]( auto & v ) -> decltype( auto ) {
99 return( countingSort( v , std::forward< P >( p )... ) );
100 };
101 return( detail::sortRange( A , f , f ) );
102 }
103
104/*--------------------------------------------------------------------------*/
105
106} // end( namespace ADS )
107
108/*--------------------------------------------------------------------------*/
109/*-------------------------- IMPLEMENTATION --------------------------------*/
110/*--------------------------------------------------------------------------*/
111
112#include "ADS/sort/impl/CountingSort.tpp"
113
114/*--------------------------------------------------------------------------*/
115
116#endif /* CountingSort.h included */
117
118/*--------------------------------------------------------------------------*/
119/*------------------------ End File CountingSort.h -------------------------*/
120/*--------------------------------------------------------------------------*/
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
void countingSort(Store &&A, std::size_t k)
, of integers in , in increasing order, by counting the occurrences of each key
Definition ADT.h:96