| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "frolova_s_radix_sort_double/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <bit> | ||
| 5 | #include <cstdint> | ||
| 6 | #include <cstring> | ||
| 7 | #include <utility> | ||
| 8 | #include <vector> | ||
| 9 | |||
| 10 | #include "frolova_s_radix_sort_double/common/include/common.hpp" | ||
| 11 | |||
| 12 | namespace frolova_s_radix_sort_double { | ||
| 13 | |||
| 14 |
1/2✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
|
80 | FrolovaSRadixSortDoubleSEQ::FrolovaSRadixSortDoubleSEQ(const InType &in) { |
| 15 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 16 |
1/2✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
|
80 | GetInput() = in; |
| 17 | 80 | } | |
| 18 | |||
| 19 | 80 | bool FrolovaSRadixSortDoubleSEQ::ValidationImpl() { | |
| 20 | 80 | return !GetInput().empty(); | |
| 21 | } | ||
| 22 | |||
| 23 | 80 | bool FrolovaSRadixSortDoubleSEQ::PreProcessingImpl() { | |
| 24 | 80 | return true; | |
| 25 | } | ||
| 26 | |||
| 27 |
1/2✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
|
80 | bool FrolovaSRadixSortDoubleSEQ::RunImpl() { |
| 28 | const std::vector<double> &input = GetInput(); | ||
| 29 |
1/2✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
|
80 | if (input.empty()) { |
| 30 | return false; | ||
| 31 | } | ||
| 32 | |||
| 33 | 80 | std::vector<double> working = input; | |
| 34 | |||
| 35 | const int radix = 256; | ||
| 36 | const int num_bits = 8; | ||
| 37 | const int num_passes = sizeof(uint64_t); | ||
| 38 | |||
| 39 |
2/6✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 80 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
80 | std::vector<int> count(radix); |
| 40 |
1/4✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
80 | std::vector<double> temp(working.size()); |
| 41 | |||
| 42 |
2/2✓ Branch 0 taken 640 times.
✓ Branch 1 taken 80 times.
|
720 | for (int pass = 0; pass < num_passes; ++pass) { |
| 43 | std::ranges::fill(count, 0); | ||
| 44 | |||
| 45 | // Подсчёт | ||
| 46 |
2/2✓ Branch 0 taken 266240 times.
✓ Branch 1 taken 640 times.
|
266880 | for (double val : working) { |
| 47 | auto bits = std::bit_cast<uint64_t>(val); | ||
| 48 | 266240 | int byte = static_cast<int>((bits >> (pass * num_bits)) & 0xFF); | |
| 49 | 266240 | ++count[byte]; | |
| 50 | } | ||
| 51 | |||
| 52 | // Преобразование счётчиков в позиции | ||
| 53 | int total = 0; | ||
| 54 |
2/2✓ Branch 0 taken 163840 times.
✓ Branch 1 taken 640 times.
|
164480 | for (int i = 0; i < radix; ++i) { |
| 55 | 163840 | int old = count[i]; | |
| 56 | 163840 | count[i] = total; | |
| 57 | 163840 | total += old; | |
| 58 | } | ||
| 59 | |||
| 60 | // Распределение | ||
| 61 |
2/2✓ Branch 0 taken 266240 times.
✓ Branch 1 taken 640 times.
|
266880 | for (double val : working) { |
| 62 | auto bits = std::bit_cast<uint64_t>(val); | ||
| 63 | 266240 | int byte = static_cast<int>((bits >> (pass * num_bits)) & 0xFF); | |
| 64 | 266240 | temp[count[byte]++] = val; | |
| 65 | } | ||
| 66 | |||
| 67 |
1/2✓ Branch 1 taken 640 times.
✗ Branch 2 not taken.
|
640 | working = temp; |
| 68 | } | ||
| 69 | |||
| 70 | // Коррекция порядка отрицательных чисел | ||
| 71 | 80 | std::vector<double> negative; | |
| 72 | 80 | std::vector<double> positive; | |
| 73 |
2/2✓ Branch 0 taken 33280 times.
✓ Branch 1 taken 80 times.
|
33360 | for (double val : working) { |
| 74 |
2/2✓ Branch 0 taken 7928 times.
✓ Branch 1 taken 25352 times.
|
33280 | if (val < 0) { |
| 75 | negative.push_back(val); | ||
| 76 | } else { | ||
| 77 | positive.push_back(val); | ||
| 78 | } | ||
| 79 | } | ||
| 80 | std::ranges::reverse(negative); | ||
| 81 | |||
| 82 | working.clear(); | ||
| 83 |
1/2✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
|
80 | working.insert(working.end(), negative.begin(), negative.end()); |
| 84 | 80 | working.insert(working.end(), positive.begin(), positive.end()); | |
| 85 | |||
| 86 | GetOutput() = std::move(working); | ||
| 87 | return true; | ||
| 88 | } | ||
| 89 | |||
| 90 | 80 | bool FrolovaSRadixSortDoubleSEQ::PostProcessingImpl() { | |
| 91 | 80 | return true; | |
| 92 | } | ||
| 93 | |||
| 94 | } // namespace frolova_s_radix_sort_double | ||
| 95 |