| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "nikitina_v_hoar_sort_batcher/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <utility> | ||
| 5 | #include <vector> | ||
| 6 | |||
| 7 | #include "nikitina_v_hoar_sort_batcher/common/include/common.hpp" | ||
| 8 | |||
| 9 | namespace nikitina_v_hoar_sort_batcher { | ||
| 10 | |||
| 11 | namespace { | ||
| 12 | |||
| 13 | 24 | void QuickSortHoare(std::vector<int> &arr, int low, int high) { | |
| 14 | 24 | std::vector<std::pair<int, int>> stack; | |
| 15 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | stack.emplace_back(low, high); |
| 16 | |||
| 17 |
2/2✓ Branch 0 taken 456 times.
✓ Branch 1 taken 24 times.
|
480 | while (!stack.empty()) { |
| 18 | auto [l, h] = stack.back(); | ||
| 19 | stack.pop_back(); | ||
| 20 | |||
| 21 |
2/2✓ Branch 0 taken 240 times.
✓ Branch 1 taken 216 times.
|
456 | if (l >= h) { |
| 22 | 240 | continue; | |
| 23 | } | ||
| 24 | |||
| 25 | 216 | int pivot = arr[l + ((h - l) / 2)]; | |
| 26 | 216 | int i = l - 1; | |
| 27 | 216 | int j = h + 1; | |
| 28 | |||
| 29 | while (true) { | ||
| 30 | 408 | i++; | |
| 31 |
2/2✓ Branch 0 taken 152 times.
✓ Branch 1 taken 408 times.
|
560 | while (arr[i] < pivot) { |
| 32 | 152 | i++; | |
| 33 | } | ||
| 34 | |||
| 35 | 408 | j--; | |
| 36 |
2/2✓ Branch 0 taken 408 times.
✓ Branch 1 taken 408 times.
|
816 | while (arr[j] > pivot) { |
| 37 | 408 | j--; | |
| 38 | } | ||
| 39 | |||
| 40 |
2/2✓ Branch 0 taken 192 times.
✓ Branch 1 taken 216 times.
|
408 | if (i >= j) { |
| 41 | break; | ||
| 42 | } | ||
| 43 | std::swap(arr[i], arr[j]); | ||
| 44 | } | ||
| 45 | |||
| 46 |
1/2✓ Branch 1 taken 216 times.
✗ Branch 2 not taken.
|
216 | stack.emplace_back(l, j); |
| 47 |
1/4✓ Branch 1 taken 216 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
216 | stack.emplace_back(j + 1, h); |
| 48 | } | ||
| 49 | 24 | } | |
| 50 | |||
| 51 | } // namespace | ||
| 52 | |||
| 53 |
1/2✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
|
32 | HoareSortBatcherSEQ::HoareSortBatcherSEQ(const InType &in) { |
| 54 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 55 |
1/2✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
|
32 | GetInput() = in; |
| 56 | 32 | } | |
| 57 | |||
| 58 | 32 | bool HoareSortBatcherSEQ::ValidationImpl() { | |
| 59 | 32 | return true; | |
| 60 | } | ||
| 61 | |||
| 62 | 32 | bool HoareSortBatcherSEQ::PreProcessingImpl() { | |
| 63 | 32 | GetOutput() = GetInput(); | |
| 64 | 32 | return true; | |
| 65 | } | ||
| 66 | |||
| 67 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 8 times.
|
32 | bool HoareSortBatcherSEQ::RunImpl() { |
| 68 | auto &out = GetOutput(); | ||
| 69 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 8 times.
|
32 | if (!out.empty()) { |
| 70 | 24 | QuickSortHoare(out, 0, static_cast<int>(out.size()) - 1); | |
| 71 | } | ||
| 72 | 32 | return true; | |
| 73 | } | ||
| 74 | |||
| 75 | 32 | bool HoareSortBatcherSEQ::PostProcessingImpl() { | |
| 76 | 32 | return true; | |
| 77 | } | ||
| 78 | |||
| 79 | } // namespace nikitina_v_hoar_sort_batcher | ||
| 80 |