| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "spichek_d_radix_sort_for_integers_with_simple_merging/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <vector> | ||
| 5 | |||
| 6 | #include "spichek_d_radix_sort_for_integers_with_simple_merging/common/include/common.hpp" | ||
| 7 | |||
| 8 | namespace spichek_d_radix_sort_for_integers_with_simple_merging { | ||
| 9 | |||
| 10 |
1/2✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
|
120 | SpichekDRadixSortSEQ::SpichekDRadixSortSEQ(const InType &in) { |
| 11 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 12 |
1/2✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
|
120 | GetInput() = in; |
| 13 | 120 | } | |
| 14 | |||
| 15 | 120 | bool SpichekDRadixSortSEQ::ValidationImpl() { | |
| 16 | 120 | return !GetInput().empty(); | |
| 17 | } | ||
| 18 | |||
| 19 | 120 | bool SpichekDRadixSortSEQ::PreProcessingImpl() { | |
| 20 | 120 | GetOutput() = GetInput(); | |
| 21 | 120 | return true; | |
| 22 | } | ||
| 23 | |||
| 24 |
1/2✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
|
120 | bool SpichekDRadixSortSEQ::RunImpl() { |
| 25 |
1/2✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
|
120 | if (GetOutput().empty()) { |
| 26 | return true; | ||
| 27 | } | ||
| 28 | |||
| 29 | 120 | RadixSort(GetOutput()); | |
| 30 | 120 | return true; | |
| 31 | } | ||
| 32 | |||
| 33 |
1/2✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
|
120 | bool SpichekDRadixSortSEQ::PostProcessingImpl() { |
| 34 | 120 | return std::ranges::is_sorted(GetOutput()); | |
| 35 | } | ||
| 36 | |||
| 37 |
1/2✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
|
120 | void SpichekDRadixSortSEQ::RadixSort(std::vector<int> &data) { |
| 38 |
1/2✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
|
120 | if (data.empty()) { |
| 39 | return; | ||
| 40 | } | ||
| 41 | |||
| 42 | 120 | int min_val = *std::ranges::min_element(data); | |
| 43 |
2/2✓ Branch 0 taken 96 times.
✓ Branch 1 taken 24 times.
|
120 | if (min_val < 0) { |
| 44 |
2/2✓ Branch 0 taken 195200 times.
✓ Branch 1 taken 96 times.
|
195296 | for (auto &x : data) { |
| 45 | 195200 | x -= min_val; | |
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | 120 | int max_val = *std::ranges::max_element(data); | |
| 50 | |||
| 51 |
2/2✓ Branch 0 taken 504 times.
✓ Branch 1 taken 120 times.
|
624 | for (int exp = 1; max_val / exp > 0; exp *= 10) { |
| 52 | 504 | std::vector<int> output(data.size()); | |
| 53 |
1/4✓ Branch 1 taken 504 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
504 | std::vector<int> count(10, 0); |
| 54 | |||
| 55 |
2/2✓ Branch 0 taken 1024800 times.
✓ Branch 1 taken 504 times.
|
1025304 | for (int x : data) { |
| 56 | 1024800 | count[(x / exp) % 10]++; | |
| 57 | } | ||
| 58 | |||
| 59 |
2/2✓ Branch 0 taken 4536 times.
✓ Branch 1 taken 504 times.
|
5040 | for (int i = 1; i < 10; i++) { |
| 60 | 4536 | count[i] += count[i - 1]; | |
| 61 | } | ||
| 62 | |||
| 63 |
2/2✓ Branch 0 taken 1024800 times.
✓ Branch 1 taken 504 times.
|
1025304 | for (int i = static_cast<int>(data.size()) - 1; i >= 0; i--) { |
| 64 | 1024800 | output[count[(data[i] / exp) % 10] - 1] = data[i]; | |
| 65 | 1024800 | count[(data[i] / exp) % 10]--; | |
| 66 | } | ||
| 67 | |||
| 68 |
1/2✓ Branch 1 taken 504 times.
✗ Branch 2 not taken.
|
504 | data = output; |
| 69 | } | ||
| 70 | |||
| 71 |
2/2✓ Branch 0 taken 96 times.
✓ Branch 1 taken 24 times.
|
120 | if (min_val < 0) { |
| 72 |
2/2✓ Branch 0 taken 195200 times.
✓ Branch 1 taken 96 times.
|
195296 | for (auto &x : data) { |
| 73 | 195200 | x += min_val; | |
| 74 | } | ||
| 75 | } | ||
| 76 | } | ||
| 77 | |||
| 78 | } // namespace spichek_d_radix_sort_for_integers_with_simple_merging | ||
| 79 |