| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "kutergin_a_closest_pair/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cstdlib> | ||
| 5 | #include <ranges> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 8 | #include "kutergin_a_closest_pair/common/include/common.hpp" | ||
| 9 | |||
| 10 | namespace kutergin_a_closest_pair { | ||
| 11 | |||
| 12 |
1/2✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
|
80 | KuterginAClosestPairSEQ::KuterginAClosestPairSEQ(const InType &in) { |
| 13 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 14 |
1/2✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
|
80 | GetInput() = in; |
| 15 | 80 | GetOutput() = -1; | |
| 16 | 80 | } | |
| 17 | |||
| 18 | 80 | bool KuterginAClosestPairSEQ::ValidationImpl() { | |
| 19 | 80 | return true; | |
| 20 | } | ||
| 21 | |||
| 22 | 80 | bool KuterginAClosestPairSEQ::PreProcessingImpl() { | |
| 23 | 80 | return true; | |
| 24 | } | ||
| 25 | |||
| 26 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 64 times.
|
80 | bool KuterginAClosestPairSEQ::RunImpl() { |
| 27 | const auto &v = GetInput(); | ||
| 28 | |||
| 29 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 64 times.
|
80 | if (v.size() < 2) { |
| 30 | 16 | GetOutput() = -1; | |
| 31 | 16 | return true; | |
| 32 | } | ||
| 33 | |||
| 34 | 64 | auto idx_range = std::views::iota(size_t{0}, v.size() - 1); | |
| 35 | |||
| 36 | 144 | auto comparator = [&](size_t i, size_t j) { | |
| 37 |
2/2✓ Branch 0 taken 104 times.
✓ Branch 1 taken 40 times.
|
144 | int diff_i = std::abs(v[i] - v[i + 1]); |
| 38 | 144 | int diff_j = std::abs(v[j] - v[j + 1]); | |
| 39 |
2/2✓ Branch 0 taken 104 times.
✓ Branch 1 taken 40 times.
|
144 | return (diff_i < diff_j) || (diff_i == diff_j && i < j); |
| 40 | 64 | }; | |
| 41 | |||
| 42 | 64 | auto min_it = std::ranges::min_element(idx_range, comparator); | |
| 43 | 64 | int min_idx = static_cast<int>(*min_it); | |
| 44 | |||
| 45 | 64 | GetOutput() = min_idx; | |
| 46 | 64 | return true; | |
| 47 | } | ||
| 48 | |||
| 49 | 80 | bool KuterginAClosestPairSEQ::PostProcessingImpl() { | |
| 50 | 80 | return true; | |
| 51 | } | ||
| 52 | |||
| 53 | } // namespace kutergin_a_closest_pair | ||
| 54 |