GCC Code Coverage Report


Directory: ./
File: tasks/kolotukhin_a_merge_sort_doubles/seq/src/ops_seq.cpp
Date: 2026-01-27 01:59:34
Exec Total Coverage
Lines: 58 59 98.3%
Functions: 9 9 100.0%
Branches: 36 48 75.0%

Line Branch Exec Source
1 #include "kolotukhin_a_merge_sort_doubles/seq/include/ops_seq.hpp"
2
3 #include <cmath>
4 #include <cstddef>
5 #include <cstdint>
6 #include <cstring>
7 #include <utility>
8 #include <vector>
9
10 #include "kolotukhin_a_merge_sort_doubles/common/include/common.hpp"
11
12 namespace kolotukhin_a_merge_sort_doubles {
13
14 namespace {
15
16 34 std::vector<std::uint64_t> ConvertDoublesToKeys(const std::vector<double> &data) {
17 const std::size_t data_size = data.size();
18 34 std::vector<std::uint64_t> keys(data_size);
19
20
2/2
✓ Branch 0 taken 226 times.
✓ Branch 1 taken 34 times.
260 for (std::size_t i = 0; i < data_size; i++) {
21 std::uint64_t u = 0;
22 std::memcpy(&u, &data[i], sizeof(double));
23
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 154 times.
226 if ((u & 0x8000000000000000ULL) != 0U) {
24 72 u = ~u;
25 } else {
26 154 u |= 0x8000000000000000ULL;
27 }
28 226 keys[i] = u;
29 }
30
31 34 return keys;
32 }
33
34 34 void ConvertKeysToDoubles(const std::vector<std::uint64_t> &keys, std::vector<double> &data) {
35 const std::size_t data_size = data.size();
36
2/2
✓ Branch 0 taken 226 times.
✓ Branch 1 taken 34 times.
260 for (std::size_t i = 0; i < data_size; i++) {
37 226 std::uint64_t u = keys[i];
38
2/2
✓ Branch 0 taken 154 times.
✓ Branch 1 taken 72 times.
226 if ((u & 0x8000000000000000ULL) != 0U) {
39 154 u &= ~0x8000000000000000ULL;
40 } else {
41 72 u = ~u;
42 }
43 std::memcpy(&data[i], &u, sizeof(double));
44 }
45 34 }
46
47
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 34 times.
34 void RadixSortUint64(std::vector<std::uint64_t> &keys) {
48 const std::size_t data_size = keys.size();
49
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 34 times.
34 if (data_size <= 1) {
50 return;
51 }
52
53 const int radix_size = 256;
54 34 std::vector<std::uint64_t> temp(data_size);
55
56
2/2
✓ Branch 0 taken 272 times.
✓ Branch 1 taken 34 times.
306 for (int shift = 0; shift < 64; shift += 8) {
57
1/4
✓ Branch 1 taken 272 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
272 std::vector<std::size_t> count(radix_size + 1, 0);
58
59
2/2
✓ Branch 0 taken 1808 times.
✓ Branch 1 taken 272 times.
2080 for (std::size_t i = 0; i < data_size; i++) {
60 1808 const auto digit = static_cast<std::uint8_t>((keys[i] >> shift) & 0xFF);
61 1808 ++count[digit + 1];
62 }
63
64
2/2
✓ Branch 0 taken 69632 times.
✓ Branch 1 taken 272 times.
69904 for (int i = 0; i < radix_size; i++) {
65 69632 count[i + 1] += count[i];
66 }
67
68
2/2
✓ Branch 0 taken 1808 times.
✓ Branch 1 taken 272 times.
2080 for (std::size_t i = 0; i < data_size; i++) {
69 1808 const auto digit = static_cast<std::uint8_t>((keys[i] >> shift) & 0xFF);
70 1808 const std::size_t pos = count[digit];
71 1808 temp[pos] = keys[i];
72 1808 count[digit] = pos + 1;
73 }
74
75
1/2
✓ Branch 0 taken 272 times.
✗ Branch 1 not taken.
272 if (!temp.empty()) {
76
2/2
✓ Branch 0 taken 1808 times.
✓ Branch 1 taken 272 times.
2080 for (std::size_t i = 0; i < data_size; i++) {
77 1808 keys[i] = temp[i];
78 }
79 }
80 }
81 }
82
83
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 34 times.
42 void RadixSortDoubles(std::vector<double> &data) {
84 const std::size_t data_size = data.size();
85
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 34 times.
42 if (data_size <= 1) {
86 8 return;
87 }
88
89 34 std::vector<std::uint64_t> keys = ConvertDoublesToKeys(data);
90
91
1/2
✓ Branch 1 taken 34 times.
✗ Branch 2 not taken.
34 RadixSortUint64(keys);
92
93 34 ConvertKeysToDoubles(keys, data);
94 }
95
96 } // namespace
97
98
1/2
✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
50 KolotukhinAMergeSortDoublesSEQ::KolotukhinAMergeSortDoublesSEQ(const InType &in) {
99 SetTypeOfTask(GetStaticTypeOfTask());
100
1/2
✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
50 GetInput() = in;
101 50 std::get<0>(GetOutput()) = std::vector<double>();
102 50 std::get<1>(GetOutput()) = -1;
103 50 }
104
105 50 bool KolotukhinAMergeSortDoublesSEQ::ValidationImpl() {
106 50 return true;
107 }
108
109
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
50 bool KolotukhinAMergeSortDoublesSEQ::PreProcessingImpl() {
110 std::get<0>(GetOutput()).clear();
111 50 return true;
112 }
113
114
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 42 times.
50 bool KolotukhinAMergeSortDoublesSEQ::RunImpl() {
115 const auto &input = GetInput();
116
117
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 42 times.
50 if (input.empty()) {
118 8 std::get<0>(GetOutput()) = input;
119 8 std::get<1>(GetOutput()) = 0;
120 8 return true;
121 }
122
123 42 std::vector<double> data = input;
124
1/2
✓ Branch 1 taken 42 times.
✗ Branch 2 not taken.
42 RadixSortDoubles(data);
125
126 std::get<0>(GetOutput()) = std::move(data);
127
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
42 std::get<1>(GetOutput()) = 0;
128 return true;
129 }
130
131 50 bool KolotukhinAMergeSortDoublesSEQ::PostProcessingImpl() {
132 50 return true;
133 }
134
135 } // namespace kolotukhin_a_merge_sort_doubles
136