| 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 | 347324 | ++i; | |
| 19 |
2/2✓ Branch 0 taken 426877 times.
✓ Branch 1 taken 347324 times.
|
774201 | while (arr[i] < pivot) { |
| 20 | 426877 | ++i; | |
| 21 | } | ||
| 22 | 347324 | --j; | |
| 23 |
2/2✓ Branch 0 taken 506893 times.
✓ Branch 1 taken 347324 times.
|
854217 | while (arr[j] > pivot) { |
| 24 | 506893 | --j; | |
| 25 | } | ||
| 26 |
2/2✓ Branch 0 taken 88856 times.
✓ Branch 1 taken 258468 times.
|
347324 | 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 217681 times.
✓ Branch 1 taken 88856 times.
|
306537 | for (int step = 1; step < n; step *= 2) { |
| 36 |
2/2✓ Branch 0 taken 1399913 times.
✓ Branch 1 taken 217681 times.
|
1617594 | for (int i = lo; i + step <= hi; i += step * 2) { |
| 37 |
2/2✓ Branch 0 taken 486267 times.
✓ Branch 1 taken 913646 times.
|
1399913 | 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 31183 times.
✓ Branch 1 taken 57673 times.
|
88856 | if (p - l > r - p - 1) { |
| 55 | stk.emplace(l, p); | ||
| 56 |
1/2✓ Branch 1 taken 31183 times.
✗ Branch 2 not taken.
|
31183 | stk.emplace(p + 1, r); |
| 57 | } else { | ||
| 58 |
2/4✓ Branch 1 taken 57673 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 57673 times.
✗ Branch 5 not taken.
|
57673 | 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 |