| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "chetverikova_e_shell_sort_simple_merge/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cstddef> | ||
| 5 | #include <utility> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 8 | #include "chetverikova_e_shell_sort_simple_merge/common/include/common.hpp" | ||
| 9 | |||
| 10 | namespace chetverikova_e_shell_sort_simple_merge { | ||
| 11 | |||
| 12 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | ChetverikovaEShellSortSimpleMergeSEQ::ChetverikovaEShellSortSimpleMergeSEQ(const InType &in) { |
| 13 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 14 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | GetInput() = in; |
| 15 | GetOutput().clear(); | ||
| 16 | 24 | } | |
| 17 | |||
| 18 | 24 | bool ChetverikovaEShellSortSimpleMergeSEQ::ValidationImpl() { | |
| 19 | 24 | return !(GetInput().empty()); | |
| 20 | } | ||
| 21 | |||
| 22 | 24 | bool ChetverikovaEShellSortSimpleMergeSEQ::PreProcessingImpl() { | |
| 23 | 24 | return true; | |
| 24 | } | ||
| 25 | |||
| 26 |
1/2✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 | void ChetverikovaEShellSortSimpleMergeSEQ::ShellSort(std::vector<int> &data) { |
| 27 |
1/2✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 | if (data.empty()) { |
| 28 | return; | ||
| 29 | } | ||
| 30 | |||
| 31 | size_t n = data.size(); | ||
| 32 |
2/2✓ Branch 0 taken 96 times.
✓ Branch 1 taken 48 times.
|
144 | for (size_t gap = n / 2; gap > 0; gap /= 2) { |
| 33 |
2/2✓ Branch 0 taken 384 times.
✓ Branch 1 taken 96 times.
|
480 | for (size_t i = gap; i < n; i++) { |
| 34 | 384 | int temp = data[i]; | |
| 35 | size_t j = i; | ||
| 36 | |||
| 37 |
4/4✓ Branch 0 taken 464 times.
✓ Branch 1 taken 144 times.
✓ Branch 2 taken 224 times.
✓ Branch 3 taken 240 times.
|
608 | while (j >= gap && data[j - gap] > temp) { |
| 38 | 224 | data[j] = data[j - gap]; | |
| 39 | j -= gap; | ||
| 40 | } | ||
| 41 | |||
| 42 | 384 | data[j] = temp; | |
| 43 | } | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
|
24 | bool ChetverikovaEShellSortSimpleMergeSEQ::RunImpl() { |
| 48 | const auto &input = GetInput(); | ||
| 49 | auto &output = GetOutput(); | ||
| 50 | |||
| 51 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
|
24 | if (input.empty()) { |
| 52 | GetOutput().clear(); | ||
| 53 | ✗ | return true; | |
| 54 | } | ||
| 55 | |||
| 56 | 24 | const size_t mid = input.size() / 2; | |
| 57 |
1/2✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
|
24 | std::vector<int> left(input.begin(), input.begin() + static_cast<std::ptrdiff_t>(mid)); |
| 58 |
1/4✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
24 | std::vector<int> right(input.begin() + static_cast<std::ptrdiff_t>(mid), input.end()); |
| 59 | 24 | ShellSort(left); | |
| 60 | 24 | ShellSort(right); | |
| 61 | |||
| 62 |
1/4✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
24 | std::vector<int> merged(left.size() + right.size()); |
| 63 | 24 | std::ranges::merge(left, right, merged.begin()); | |
| 64 | output = std::move(merged); | ||
| 65 | |||
| 66 | return true; | ||
| 67 | } | ||
| 68 | |||
| 69 | 24 | bool ChetverikovaEShellSortSimpleMergeSEQ::PostProcessingImpl() { | |
| 70 | 24 | return true; | |
| 71 | } | ||
| 72 | |||
| 73 | } // namespace chetverikova_e_shell_sort_simple_merge | ||
| 74 |