| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "sizov_d_bubble_sort/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <cstddef> | ||
| 4 | #include <utility> | ||
| 5 | #include <vector> | ||
| 6 | |||
| 7 | #include "sizov_d_bubble_sort/common/include/common.hpp" | ||
| 8 | |||
| 9 | namespace sizov_d_bubble_sort { | ||
| 10 | |||
| 11 |
1/2✓ Branch 1 taken 320 times.
✗ Branch 2 not taken.
|
320 | SizovDBubbleSortSEQ::SizovDBubbleSortSEQ(const InType &in) { |
| 12 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 13 |
1/2✓ Branch 1 taken 320 times.
✗ Branch 2 not taken.
|
320 | GetInput() = in; |
| 14 | GetOutput().clear(); | ||
| 15 | 320 | } | |
| 16 | |||
| 17 | 320 | bool SizovDBubbleSortSEQ::ValidationImpl() { | |
| 18 | const auto &input = GetInput(); | ||
| 19 | 320 | return !input.empty(); | |
| 20 | } | ||
| 21 | |||
| 22 | 320 | bool SizovDBubbleSortSEQ::PreProcessingImpl() { | |
| 23 | 320 | data_ = GetInput(); | |
| 24 | 320 | return true; | |
| 25 | } | ||
| 26 | |||
| 27 |
2/2✓ Branch 0 taken 312 times.
✓ Branch 1 taken 8 times.
|
320 | bool SizovDBubbleSortSEQ::RunImpl() { |
| 28 | 320 | const std::size_t n = data_.size(); | |
| 29 |
2/2✓ Branch 0 taken 312 times.
✓ Branch 1 taken 8 times.
|
320 | if (n <= 1) { |
| 30 | return true; | ||
| 31 | } | ||
| 32 | |||
| 33 | auto pass = [&](std::size_t start) { | ||
| 34 | bool swapped = false; | ||
| 35 |
4/4✓ Branch 0 taken 14936 times.
✓ Branch 1 taken 1736 times.
✓ Branch 2 taken 14080 times.
✓ Branch 3 taken 1736 times.
|
30752 | for (std::size_t i = start; i + 1 < n; i += 2) { |
| 36 |
4/4✓ Branch 0 taken 7248 times.
✓ Branch 1 taken 7688 times.
✓ Branch 2 taken 6928 times.
✓ Branch 3 taken 7152 times.
|
29016 | if (data_[i] > data_[i + 1]) { |
| 37 | std::swap(data_[i], data_[i + 1]); | ||
| 38 | swapped = true; | ||
| 39 | } | ||
| 40 | } | ||
| 41 | return swapped; | ||
| 42 | }; | ||
| 43 | |||
| 44 | while (true) { | ||
| 45 | bool swapped = pass(0); | ||
| 46 |
2/2✓ Branch 0 taken 1288 times.
✓ Branch 1 taken 448 times.
|
1736 | swapped = pass(1) || swapped; |
| 47 |
2/2✓ Branch 0 taken 1424 times.
✓ Branch 1 taken 312 times.
|
1736 | if (!swapped) { |
| 48 | break; | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | return true; | ||
| 53 | } | ||
| 54 | |||
| 55 | 320 | bool SizovDBubbleSortSEQ::PostProcessingImpl() { | |
| 56 | 320 | GetOutput() = data_; | |
| 57 | 320 | return true; | |
| 58 | } | ||
| 59 | |||
| 60 | } // namespace sizov_d_bubble_sort | ||
| 61 |