-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathkernel.cpp
More file actions
59 lines (44 loc) · 1.28 KB
/
kernel.cpp
File metadata and controls
59 lines (44 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "kernel.hpp"
#include <algorithm>
#ifndef _MIN_VALUE_RANGE
#define _MIN_VALUE_RANGE 0
#endif
#ifndef _MAX_VALUE_RANGE
#define _MAX_VALUE_RANGE 10
#endif
namespace {
const size_t range_size = _MAX_VALUE_RANGE - _MIN_VALUE_RANGE;
std::vector<size_t> counter(range_size);
}
void sort(std::vector<int32_t> &array, const int32_t min, const int32_t max) {
const size_t my_range_size = max - min;
std::vector<size_t> my_counter(my_range_size);
std::fill(my_counter.begin(), my_counter.end(), 0);
for( size_t i = 0; i < array.size(); i++ ) {
my_counter[array[i] - min]++;
}
auto it = array.begin();
for( int32_t i = min; i < max; i++ ) {
const size_t increment = my_counter[i - min];
std::fill_n(it, increment, i);
std::advance(it, increment);
}
return;
}
extern "C"
void vc_sort(std::vector<int32_t> &array) {
const int32_t max = _MAX_VALUE_RANGE;
const int32_t min = _MIN_VALUE_RANGE;
std::fill(counter.begin(), counter.end(), 0);
for( size_t i = 0; i < array.size(); i++ ) {
counter[array[i] - min]++;
}
auto it = array.begin();
for( size_t i = 0; i < range_size; i++ ) {
const int32_t index = i + min;
const size_t increment = counter[i];
std::fill_n(it, increment, index);
std::advance(it, increment);
}
return;
}