| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "shelenkova_m_shell_sort_simple_merge/omp/include/ops_omp.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cstddef> | ||
| 5 | #include <vector> | ||
| 6 | |||
| 7 | #include "shelenkova_m_shell_sort_simple_merge/common/include/common.hpp" | ||
| 8 | |||
| 9 | namespace shelenkova_m_shell_sort_simple_merge { | ||
| 10 | |||
| 11 | namespace { | ||
| 12 | |||
| 13 |
2/2✓ Branch 0 taken 88 times.
✓ Branch 1 taken 8 times.
|
96 | void ShellSort(std::vector<int> &data) { |
| 14 | const size_t n = data.size(); | ||
| 15 |
2/2✓ Branch 0 taken 88 times.
✓ Branch 1 taken 8 times.
|
96 | if (n <= 1) { |
| 16 | return; | ||
| 17 | } | ||
| 18 | |||
| 19 |
2/2✓ Branch 0 taken 112 times.
✓ Branch 1 taken 88 times.
|
200 | for (size_t gap = n / 2; gap > 0; gap /= 2) { |
| 20 |
2/2✓ Branch 0 taken 244 times.
✓ Branch 1 taken 112 times.
|
356 | for (size_t i = gap; i < n; ++i) { |
| 21 | 244 | int temp = data[i]; | |
| 22 | size_t j = i; | ||
| 23 |
4/4✓ Branch 0 taken 300 times.
✓ Branch 1 taken 96 times.
✓ Branch 2 taken 152 times.
✓ Branch 3 taken 148 times.
|
396 | while (j >= gap && data[j - gap] > temp) { |
| 24 | 152 | data[j] = data[j - gap]; | |
| 25 | j -= gap; | ||
| 26 | } | ||
| 27 | 244 | data[j] = temp; | |
| 28 | } | ||
| 29 | } | ||
| 30 | } | ||
| 31 | |||
| 32 | 48 | void SimpleMerge(const std::vector<int> &left, const std::vector<int> &right, std::vector<int> &result) { | |
| 33 | size_t left_idx = 0; | ||
| 34 | size_t right_idx = 0; | ||
| 35 | size_t res_idx = 0; | ||
| 36 | |||
| 37 |
4/4✓ Branch 0 taken 214 times.
✓ Branch 1 taken 22 times.
✓ Branch 2 taken 26 times.
✓ Branch 3 taken 188 times.
|
236 | while (left_idx < left.size() && right_idx < right.size()) { |
| 38 |
2/2✓ Branch 0 taken 74 times.
✓ Branch 1 taken 114 times.
|
188 | if (left[left_idx] <= right[right_idx]) { |
| 39 | 74 | result[res_idx++] = left[left_idx++]; | |
| 40 | } else { | ||
| 41 | 114 | result[res_idx++] = right[right_idx++]; | |
| 42 | } | ||
| 43 | } | ||
| 44 | |||
| 45 |
2/2✓ Branch 0 taken 50 times.
✓ Branch 1 taken 48 times.
|
98 | while (left_idx < left.size()) { |
| 46 | 50 | result[res_idx++] = left[left_idx++]; | |
| 47 | } | ||
| 48 | |||
| 49 |
2/2✓ Branch 0 taken 42 times.
✓ Branch 1 taken 48 times.
|
90 | while (right_idx < right.size()) { |
| 50 | 42 | result[res_idx++] = right[right_idx++]; | |
| 51 | } | ||
| 52 | 48 | } | |
| 53 | |||
| 54 | } // namespace | ||
| 55 | |||
| 56 |
1/2✓ Branch 1 taken 52 times.
✗ Branch 2 not taken.
|
52 | ShelenkovaMShellSortSimpleMergeOMP::ShelenkovaMShellSortSimpleMergeOMP(const InType &in) { |
| 57 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 58 |
1/2✓ Branch 1 taken 52 times.
✗ Branch 2 not taken.
|
52 | GetInput() = in; |
| 59 |
1/2✓ Branch 1 taken 52 times.
✗ Branch 2 not taken.
|
52 | GetOutput() = in; |
| 60 | 52 | } | |
| 61 | |||
| 62 | 52 | bool ShelenkovaMShellSortSimpleMergeOMP::ValidationImpl() { | |
| 63 | 52 | return !GetInput().empty(); | |
| 64 | } | ||
| 65 | |||
| 66 | 52 | bool ShelenkovaMShellSortSimpleMergeOMP::PreProcessingImpl() { | |
| 67 | 52 | GetOutput() = GetInput(); | |
| 68 | 52 | return true; | |
| 69 | } | ||
| 70 | |||
| 71 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 4 times.
|
52 | bool ShelenkovaMShellSortSimpleMergeOMP::RunImpl() { |
| 72 | std::vector<int> &data = GetOutput(); | ||
| 73 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 4 times.
|
52 | if (data.size() <= 1) { |
| 74 | return true; | ||
| 75 | } | ||
| 76 | |||
| 77 | 48 | const size_t mid = data.size() / 2; | |
| 78 |
1/2✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
|
48 | std::vector<int> left(data.begin(), data.begin() + static_cast<std::ptrdiff_t>(mid)); |
| 79 |
1/4✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
48 | std::vector<int> right(data.begin() + static_cast<std::ptrdiff_t>(mid), data.end()); |
| 80 | |||
| 81 | 48 | #pragma omp parallel sections default(none) shared(left, right) | |
| 82 | { | ||
| 83 | #pragma omp section | ||
| 84 | { | ||
| 85 | ShellSort(left); | ||
| 86 | } | ||
| 87 | #pragma omp section | ||
| 88 | { | ||
| 89 | ShellSort(right); | ||
| 90 | } | ||
| 91 | } | ||
| 92 | |||
| 93 | 48 | SimpleMerge(left, right, data); | |
| 94 | |||
| 95 | return std::ranges::is_sorted(data); | ||
| 96 | } | ||
| 97 | |||
| 98 | 52 | bool ShelenkovaMShellSortSimpleMergeOMP::PostProcessingImpl() { | |
| 99 | 52 | return !GetOutput().empty(); | |
| 100 | } | ||
| 101 | |||
| 102 | } // namespace shelenkova_m_shell_sort_simple_merge | ||
| 103 |