ADS
Algorithms and Data Structures
Toggle main menu visibility
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
52
namespace
ADS
53
{
54
74
template
<
RankStore
Store ,
class
T = std::ranges::range_value_t<
75
std::remove_cvref_t< Store > > >
76
void
countingSort
( Store && A , std::size_t k );
77
79
template
<
class
T >
80
void
countingSort
( std::vector< T > & A , std::size_t k );
81
82
/*--------------------------------------------------------------------------*/
83
/*------------------------- THE SORTS OF A RANGE ---------------------------*/
84
/*--------------------------------------------------------------------------*/
85
90
template
<
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
}
96
decltype
( 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
/*--------------------------------------------------------------------------*/
Contract.h
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
Sorted.h
The checks of the contracts of the sorts [see Contract.h]: a copy of the input kept only when the aud...
ADS::RankStore
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
ADS::SortRange
a range that the sorts take beside std::vector and std::span: random access, sized,...
Definition
Sorted.h:153
ADS::countingSort
void countingSort(Store &&A, std::size_t k)
, of integers in , in increasing order, by counting the occurrences of each key
ADS
Definition
ADT.h:96
ADS
sort
CountingSort.h
Generated by
1.17.0