| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "tochilin_e_hoar_sort_sim_mer/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <iterator> | ||
| 5 | #include <utility> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 8 | #include "tochilin_e_hoar_sort_sim_mer/common/include/common.hpp" | ||
| 9 | |||
| 10 | namespace tochilin_e_hoar_sort_sim_mer { | ||
| 11 | |||
| 12 |
1/2✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
|
64 | TochilinEHoarSortSimMerSEQ::TochilinEHoarSortSimMerSEQ(const InType &in) { |
| 13 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 14 |
1/2✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
|
64 | GetInput() = in; |
| 15 | 64 | } | |
| 16 | |||
| 17 | 64 | bool TochilinEHoarSortSimMerSEQ::ValidationImpl() { | |
| 18 | 64 | return !GetInput().empty(); | |
| 19 | } | ||
| 20 | |||
| 21 | 64 | bool TochilinEHoarSortSimMerSEQ::PreProcessingImpl() { | |
| 22 | 64 | GetOutput() = GetInput(); | |
| 23 | 64 | return true; | |
| 24 | } | ||
| 25 | |||
| 26 | 5477 | std::pair<int, int> TochilinEHoarSortSimMerSEQ::Partition(std::vector<int> &arr, int l, int r) { | |
| 27 | int i = l; | ||
| 28 | int j = r; | ||
| 29 | 5477 | int pivot = arr[(l + r) / 2]; | |
| 30 | |||
| 31 |
2/2✓ Branch 0 taken 13111 times.
✓ Branch 1 taken 5477 times.
|
24065 | while (i <= j) { |
| 32 |
2/2✓ Branch 0 taken 16802 times.
✓ Branch 1 taken 13111 times.
|
29913 | while (arr[i] < pivot) { |
| 33 | 16802 | ++i; | |
| 34 | } | ||
| 35 |
2/2✓ Branch 0 taken 17139 times.
✓ Branch 1 taken 13111 times.
|
30250 | while (arr[j] > pivot) { |
| 36 | 17139 | --j; | |
| 37 | } | ||
| 38 |
2/2✓ Branch 0 taken 1394 times.
✓ Branch 1 taken 11717 times.
|
13111 | if (i <= j) { |
| 39 | std::swap(arr[i], arr[j]); | ||
| 40 | 11717 | ++i; | |
| 41 | 11717 | --j; | |
| 42 | } | ||
| 43 | } | ||
| 44 | 5477 | return {i, j}; | |
| 45 | } | ||
| 46 | |||
| 47 | 128 | void TochilinEHoarSortSimMerSEQ::QuickSort(std::vector<int> &arr, int low, int high) { | |
| 48 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 96 times.
|
128 | if (low >= high) { |
| 49 | 32 | return; | |
| 50 | } | ||
| 51 | |||
| 52 | 96 | std::vector<std::pair<int, int>> stack; | |
| 53 |
1/2✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
|
96 | stack.emplace_back(low, high); |
| 54 | |||
| 55 |
2/2✓ Branch 0 taken 5477 times.
✓ Branch 1 taken 96 times.
|
5573 | while (!stack.empty()) { |
| 56 | auto [l, r] = stack.back(); | ||
| 57 | stack.pop_back(); | ||
| 58 | |||
| 59 | 5477 | auto [i, j] = Partition(arr, l, r); | |
| 60 | |||
| 61 |
2/2✓ Branch 0 taken 2610 times.
✓ Branch 1 taken 2867 times.
|
5477 | if (l < j) { |
| 62 |
1/2✓ Branch 1 taken 2610 times.
✗ Branch 2 not taken.
|
2610 | stack.emplace_back(l, j); |
| 63 | } | ||
| 64 |
2/2✓ Branch 0 taken 2771 times.
✓ Branch 1 taken 2706 times.
|
5477 | if (i < r) { |
| 65 |
1/2✓ Branch 1 taken 2771 times.
✗ Branch 2 not taken.
|
2771 | stack.emplace_back(i, r); |
| 66 | } | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | 64 | std::vector<int> TochilinEHoarSortSimMerSEQ::MergeSortedVectors(const std::vector<int> &a, const std::vector<int> &b) { | |
| 71 |
1/2✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
|
64 | std::vector<int> result; |
| 72 |
1/2✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
|
64 | result.reserve(a.size() + b.size()); |
| 73 |
1/2✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
|
64 | std::ranges::merge(a, b, std::back_inserter(result)); |
| 74 | 64 | return result; | |
| 75 | } | ||
| 76 | |||
| 77 |
1/2✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
|
64 | bool TochilinEHoarSortSimMerSEQ::RunImpl() { |
| 78 | auto &data = GetOutput(); | ||
| 79 |
1/2✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
|
64 | if (data.empty()) { |
| 80 | return false; | ||
| 81 | } | ||
| 82 | |||
| 83 | 64 | const auto mid = static_cast<std::vector<int>::difference_type>(data.size() / 2); | |
| 84 | |||
| 85 |
1/2✓ Branch 2 taken 64 times.
✗ Branch 3 not taken.
|
64 | std::vector<int> left(data.begin(), data.begin() + mid); |
| 86 |
2/6✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 64 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
64 | std::vector<int> right(data.begin() + mid, data.end()); |
| 87 | |||
| 88 |
1/2✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
|
64 | QuickSort(left, 0, static_cast<int>(left.size()) - 1); |
| 89 |
1/2✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
|
64 | QuickSort(right, 0, static_cast<int>(right.size()) - 1); |
| 90 | |||
| 91 |
2/6✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 64 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
128 | data = MergeSortedVectors(left, right); |
| 92 | |||
| 93 | return true; | ||
| 94 | } | ||
| 95 | |||
| 96 |
1/2✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
|
64 | bool TochilinEHoarSortSimMerSEQ::PostProcessingImpl() { |
| 97 | 64 | return std::is_sorted(GetOutput().begin(), GetOutput().end()); | |
| 98 | } | ||
| 99 | |||
| 100 | } // namespace tochilin_e_hoar_sort_sim_mer | ||
| 101 |