GCC Code Coverage Report


Directory: ./
File: tasks/smetanin_d_hoare_even_odd_batchelor/seq/src/ops_seq.cpp
Date: 2026-05-11 08:26:31
Exec Total Coverage
Lines: 43 43 100.0%
Functions: 8 8 100.0%
Branches: 27 32 84.4%

Line Branch Exec Source
1 #include "smetanin_d_hoare_even_odd_batchelor/seq/include/ops_seq.hpp"
2
3 #include <stack>
4 #include <utility>
5 #include <vector>
6
7 #include "smetanin_d_hoare_even_odd_batchelor/common/include/common.hpp"
8
9 namespace smetanin_d_hoare_even_odd_batchelor {
10
11 namespace {
12
13 88856 int HoarePartition(std::vector<int> &arr, int lo, int hi) {
14 88856 int pivot = arr[lo + ((hi - lo) / 2)];
15 88856 int i = lo - 1;
16 88856 int j = hi + 1;
17 while (true) {
18 346308 ++i;
19
2/2
✓ Branch 0 taken 463318 times.
✓ Branch 1 taken 346308 times.
809626 while (arr[i] < pivot) {
20 463318 ++i;
21 }
22 346308 --j;
23
2/2
✓ Branch 0 taken 486812 times.
✓ Branch 1 taken 346308 times.
833120 while (arr[j] > pivot) {
24 486812 --j;
25 }
26
2/2
✓ Branch 0 taken 88856 times.
✓ Branch 1 taken 257452 times.
346308 if (i >= j) {
27 88856 return j;
28 }
29 std::swap(arr[i], arr[j]);
30 }
31 }
32
33 88856 void OddEvenMerge(std::vector<int> &arr, int lo, int hi) {
34 88856 int n = hi - lo + 1;
35
2/2
✓ Branch 0 taken 217884 times.
✓ Branch 1 taken 88856 times.
306740 for (int step = 1; step < n; step *= 2) {
36
2/2
✓ Branch 0 taken 1414534 times.
✓ Branch 1 taken 217884 times.
1632418 for (int i = lo; i + step <= hi; i += step * 2) {
37
2/2
✓ Branch 0 taken 470178 times.
✓ Branch 1 taken 944356 times.
1414534 if (arr[i] > arr[i + step]) {
38 std::swap(arr[i], arr[i + step]);
39 }
40 }
41 }
42 88856 }
43
44 40 void HoarSortBatcher(std::vector<int> &arr, int lo, int hi) {
45 std::stack<std::pair<int, int>> stk;
46 stk.emplace(lo, hi);
47
2/2
✓ Branch 0 taken 177752 times.
✓ Branch 1 taken 40 times.
177792 while (!stk.empty()) {
48 auto [l, r] = stk.top();
49 stk.pop();
50
2/2
✓ Branch 0 taken 88896 times.
✓ Branch 1 taken 88856 times.
177752 if (l >= r) {
51 88896 continue;
52 }
53 88856 int p = HoarePartition(arr, l, r);
54
2/2
✓ Branch 0 taken 30928 times.
✓ Branch 1 taken 57928 times.
88856 if (p - l > r - p - 1) {
55 stk.emplace(l, p);
56
1/2
✓ Branch 1 taken 30928 times.
✗ Branch 2 not taken.
30928 stk.emplace(p + 1, r);
57 } else {
58
2/4
✓ Branch 1 taken 57928 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 57928 times.
✗ Branch 5 not taken.
57928 stk.emplace(p + 1, r);
59 stk.emplace(l, p);
60 }
61 88856 OddEvenMerge(arr, l, r);
62 }
63 40 }
64
65 } // namespace
66
67
1/2
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
56 SmetaninDHoarSortSEQ::SmetaninDHoarSortSEQ(const InType &in) {
68 SetTypeOfTask(GetStaticTypeOfTask());
69
1/2
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
56 GetInput() = in;
70 56 }
71
72 56 bool SmetaninDHoarSortSEQ::ValidationImpl() {
73 56 return true;
74 }
75
76 56 bool SmetaninDHoarSortSEQ::PreProcessingImpl() {
77 56 GetOutput() = GetInput();
78 56 return true;
79 }
80
81
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 16 times.
56 bool SmetaninDHoarSortSEQ::RunImpl() {
82 auto &data = GetOutput();
83 56 int n = static_cast<int>(data.size());
84
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 16 times.
56 if (n > 1) {
85 40 HoarSortBatcher(data, 0, n - 1);
86 }
87 56 return true;
88 }
89
90 56 bool SmetaninDHoarSortSEQ::PostProcessingImpl() {
91 56 return true;
92 }
93
94 } // namespace smetanin_d_hoare_even_odd_batchelor
95