GCC Code Coverage Report


Directory: ./
File: tasks/chetverikova_e_shell_sort_simple_merge/tbb/src/ops_tbb.cpp
Date: 2026-05-11 08:26:31
Exec Total Coverage
Lines: 39 42 92.9%
Functions: 7 7 100.0%
Branches: 28 44 63.6%

Line Branch Exec Source
1 #include "chetverikova_e_shell_sort_simple_merge/tbb/include/ops_tbb.hpp"
2
3 #include <tbb/tbb.h>
4
5 #include <algorithm>
6 #include <cstddef>
7 #include <utility>
8 #include <vector>
9
10 #include "chetverikova_e_shell_sort_simple_merge/common/include/common.hpp"
11
12 namespace chetverikova_e_shell_sort_simple_merge {
13
14
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 ChetverikovaEShellSortSimpleMergeTBB::ChetverikovaEShellSortSimpleMergeTBB(const InType &in) {
15 SetTypeOfTask(GetStaticTypeOfTask());
16
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 GetInput() = in;
17 GetOutput().clear();
18 12 }
19
20 12 bool ChetverikovaEShellSortSimpleMergeTBB::ValidationImpl() {
21 12 return !(GetInput().empty());
22 }
23
24 12 bool ChetverikovaEShellSortSimpleMergeTBB::PreProcessingImpl() {
25 12 return true;
26 }
27
28
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 void ChetverikovaEShellSortSimpleMergeTBB::ShellSort(std::vector<int> &data) {
29
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if (data.empty()) {
30 return;
31 }
32
33 size_t n = data.size();
34
2/2
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 48 times.
100 for (size_t gap = n / 2; gap > 0; gap /= 2) {
35
2/2
✓ Branch 0 taken 104 times.
✓ Branch 1 taken 52 times.
156 for (size_t i = gap; i < n; i++) {
36 104 int temp = data[i];
37 size_t j = i;
38
39
4/4
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 96 times.
✓ Branch 3 taken 32 times.
200 while (j >= gap && data[j - gap] > temp) {
40 96 data[j] = data[j - gap];
41 j -= gap;
42 }
43
44 104 data[j] = temp;
45 }
46 }
47 }
48
49
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 bool ChetverikovaEShellSortSimpleMergeTBB::RunImpl() {
50 const auto &input = GetInput();
51 auto &output = GetOutput();
52
53
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (input.empty()) {
54 output.clear();
55 return true;
56 }
57
58
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 const size_t n = input.size();
59
60 const size_t num_threads = std::min<size_t>(4, n);
61 12 const size_t block_size = (n + num_threads - 1) / num_threads;
62 12 std::vector<std::vector<int>> blocks(num_threads);
63
64
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
60 tbb::parallel_for(tbb::blocked_range<size_t>(0, num_threads), [&](const tbb::blocked_range<size_t> &r) {
65 96 for (size_t block_id = r.begin(); block_id < r.end(); ++block_id) {
66 48 size_t start = block_id * block_size;
67
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 36 times.
48 size_t end = std::min(start + block_size, n);
68
69
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if (start >= n) {
70 continue;
71 }
72
73 48 std::vector<int> local;
74
1/2
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
48 local.reserve(end - start);
75
76
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 48 times.
176 for (size_t i = start; i < end; ++i) {
77
1/2
✓ Branch 0 taken 128 times.
✗ Branch 1 not taken.
128 local.push_back(input[i]);
78 }
79
80 48 ShellSort(local);
81
82 48 blocks[block_id] = std::move(local);
83 }
84 48 });
85
86 std::vector<int> result = std::move(blocks[0]);
87
88
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
48 for (size_t i = 1; i < num_threads; ++i) {
89
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 if (blocks[i].empty()) {
90 continue;
91 }
92
93
1/4
✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
36 std::vector<int> tmp(result.size() + blocks[i].size());
94
95
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 std::merge(result.begin(), result.end(), blocks[i].begin(), blocks[i].end(), tmp.begin());
96
97 result.swap(tmp);
98 }
99
100 output = std::move(result);
101 return true;
102 12 }
103
104 12 bool ChetverikovaEShellSortSimpleMergeTBB::PostProcessingImpl() {
105 12 return true;
106 }
107
108 } // namespace chetverikova_e_shell_sort_simple_merge
109