GCC Code Coverage Report


Directory: ./
File: tasks/timofeev_n_radix_batcher_sort/seq/src/ops_seq.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 50 59 84.7%
Functions: 7 10 70.0%
Branches: 45 58 77.6%

Line Branch Exec Source
1 #include "timofeev_n_radix_batcher_sort/seq/include/ops_seq.hpp"
2
3 #include <algorithm>
4 #include <climits>
5 #include <utility>
6 #include <vector>
7
8 #include "timofeev_n_radix_batcher_sort/common/include/common.hpp"
9 // #include "util/include/util.hpp"
10
11 namespace timofeev_n_radix_batcher_sort_threads {
12
13
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 TimofeevNRadixBatcherSEQ::TimofeevNRadixBatcherSEQ(const InType &in) {
14 SetTypeOfTask(GetStaticTypeOfTask());
15
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 GetInput() = in;
16
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 GetOutput() = in;
17 24 }
18
19 void TimofeevNRadixBatcherSEQ::CompExch(int &a, int &b, int digit) {
20 2304 int b_r = b % (digit * 10) / digit;
21 2304 int a_r = a % (digit * 10) / digit;
22
2/4
✓ Branch 0 taken 344 times.
✓ Branch 1 taken 1960 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2304 if (b_r < a_r) {
23 std::swap(a, b);
24 }
25 }
26
27 64 void TimofeevNRadixBatcherSEQ::BubbleSort(std::vector<int> &arr, int digit, int left, int right) {
28
2/2
✓ Branch 0 taken 416 times.
✓ Branch 1 taken 64 times.
480 for (int i = left; i <= right; i++) {
29
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 416 times.
2720 for (int j = 0; j + 1 < right - left; j++) {
30
2/2
✓ Branch 0 taken 344 times.
✓ Branch 1 taken 1960 times.
2304 CompExch(arr[left + j], arr[left + j + 1], digit);
31 }
32 }
33 64 }
34
35 void TimofeevNRadixBatcherSEQ::ComparR(int &a, int &b) {
36
2/4
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
184 if (a > b) {
37 std::swap(a, b);
38 }
39 }
40
41 24 void TimofeevNRadixBatcherSEQ::OddEvenMerge(std::vector<int> &arr, int lft, int n) {
42
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if (n <= 1) {
43 return;
44 }
45
46 24 int otstup = n / 2;
47
2/2
✓ Branch 0 taken 112 times.
✓ Branch 1 taken 24 times.
136 for (int i = 0; i < otstup; i += 1) {
48
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 80 times.
112 if (arr[lft + i] > arr[lft + otstup + i]) {
49 std::swap(arr[lft + i], arr[lft + otstup + i]);
50 }
51 }
52
53
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 24 times.
72 for (otstup = n / 4; otstup > 0; otstup /= 2) {
54 48 int h = otstup * 2;
55
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 48 times.
176 for (int start = otstup; start + otstup < n; start += h) {
56
2/2
✓ Branch 0 taken 184 times.
✓ Branch 1 taken 128 times.
312 for (int i = 0; i < otstup; i += 1) {
57
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 152 times.
184 ComparR(arr[lft + start + i], arr[lft + start + i + otstup]);
58 }
59 }
60 }
61 }
62
63 int TimofeevNRadixBatcherSEQ::Loggo(int inputa) {
64 int count = 0;
65 while (inputa > 1) {
66 inputa /= 2;
67 count++;
68 }
69 return count;
70 }
71
72 24 bool TimofeevNRadixBatcherSEQ::ValidationImpl() {
73 24 return GetInput().size() >= 2;
74 }
75
76 24 bool TimofeevNRadixBatcherSEQ::PreProcessingImpl() {
77 24 return true;
78 }
79
80 24 bool TimofeevNRadixBatcherSEQ::RunImpl() {
81 24 std::vector<int> in = GetInput();
82 24 int n = static_cast<int>(in.size());
83 int m = n;
84
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 24 times.
56 while (n % 2 == 0) {
85 32 n /= 2;
86 }
87
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 8 times.
24 if (n > 1) {
88 n = static_cast<int>(in.size());
89 int p = 1;
90
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 16 times.
56 while (p < n) {
91 40 p *= 2;
92 }
93 n = p;
94 } else {
95 n = m;
96 }
97 24 int max_x = *(std::ranges::max_element(in.begin(), in.end()));
98
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 8 times.
24 if (n != m) {
99
1/2
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
16 in.resize(n, max_x);
100 }
101 // std::cout << "\n\n" << n << " " << in.size() << " " << "1\n\n";
102
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 24 times.
72 for (int i = 0; std::cmp_less(i, static_cast<int>(in.size())); i += static_cast<int>(in.size() / 2)) {
103
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 48 times.
112 for (int k = 1; k <= max_x; k *= 10) {
104 64 BubbleSort(in, k, i, i + static_cast<int>(in.size() / 2));
105 }
106 }
107 24 OddEvenMerge(in, 0, static_cast<int>(in.size()));
108 // std::cout << "\n\n" << n << " " << in.size() << " " << "2\n\n";
109
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 8 times.
24 if (m != n) {
110
1/2
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
16 in.resize(m);
111 }
112
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 24 times.
216 for (int i = 0; std::cmp_less(i, static_cast<int>(in.size())); i++) {
113 192 GetInput()[i] = in[i];
114 }
115
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 GetOutput() = GetInput();
116 24 return true;
117 }
118
119 24 bool TimofeevNRadixBatcherSEQ::PostProcessingImpl() {
120 24 return true;
121 }
122
123 } // namespace timofeev_n_radix_batcher_sort_threads
124