| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "papulina_y_radix_sort/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <array> | ||
| 4 | #include <cmath> | ||
| 5 | #include <cstddef> | ||
| 6 | #include <cstdint> | ||
| 7 | #include <cstring> | ||
| 8 | #include <vector> | ||
| 9 | |||
| 10 | #include "papulina_y_radix_sort/common/include/common.hpp" | ||
| 11 | |||
| 12 | namespace papulina_y_radix_sort { | ||
| 13 | |||
| 14 |
1/2✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
|
56 | PapulinaYRadixSortSEQ::PapulinaYRadixSortSEQ(const InType &in) { |
| 15 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 16 |
1/2✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
|
56 | GetInput() = in; |
| 17 | 56 | GetOutput() = std::vector<double>(); | |
| 18 | 56 | } | |
| 19 | 56 | bool PapulinaYRadixSortSEQ::ValidationImpl() { | |
| 20 | 56 | return true; | |
| 21 | } | ||
| 22 | |||
| 23 | 56 | bool PapulinaYRadixSortSEQ::PreProcessingImpl() { | |
| 24 | 56 | return true; | |
| 25 | } | ||
| 26 | |||
| 27 | 56 | bool PapulinaYRadixSortSEQ::RunImpl() { | |
| 28 | double *result = GetInput().data(); | ||
| 29 | size_t size = GetInput().size(); | ||
| 30 | |||
| 31 | 56 | RadixSort(result, static_cast<int>(size)); | |
| 32 | |||
| 33 | 56 | GetOutput() = std::vector<double>(size); | |
| 34 |
2/2✓ Branch 0 taken 400 times.
✓ Branch 1 taken 56 times.
|
456 | for (size_t i = 0; i < size; i++) { |
| 35 | 400 | GetOutput()[i] = result[i]; | |
| 36 | } | ||
| 37 | |||
| 38 | 56 | return true; | |
| 39 | } | ||
| 40 | |||
| 41 | 56 | bool PapulinaYRadixSortSEQ::PostProcessingImpl() { | |
| 42 | 56 | return true; | |
| 43 | } | ||
| 44 | 448 | void PapulinaYRadixSortSEQ::SortByByte(uint64_t *bytes, uint64_t *out, int byte, int size) { | |
| 45 | auto *byte_view = reinterpret_cast<unsigned char *>(bytes); // просматриваем как массив байтов | ||
| 46 | 448 | std::array<int, 256> counter = {0}; | |
| 47 | |||
| 48 |
2/2✓ Branch 0 taken 3200 times.
✓ Branch 1 taken 448 times.
|
3648 | for (int i = 0; i < size; i++) { |
| 49 | 3200 | int index = byte_view[(8 * i) + byte]; | |
| 50 | 3200 | *(counter.data() + index) += 1; | |
| 51 | } | ||
| 52 | int tmp = 0; | ||
| 53 | int j = 0; | ||
| 54 |
1/2✓ Branch 0 taken 21048 times.
✗ Branch 1 not taken.
|
21048 | for (; j < 256; j++) { |
| 55 |
2/2✓ Branch 0 taken 448 times.
✓ Branch 1 taken 20600 times.
|
21048 | if (*(counter.data() + j) != 0) { |
| 56 | tmp = *(counter.data() + j); | ||
| 57 | 448 | *(counter.data() + j) = 0; | |
| 58 | 448 | j++; | |
| 59 | 448 | break; | |
| 60 | } | ||
| 61 | } | ||
| 62 |
2/2✓ Branch 0 taken 93640 times.
✓ Branch 1 taken 448 times.
|
94088 | for (; j < 256; j++) { |
| 63 | 93640 | int a = *(counter.data() + j); | |
| 64 | 93640 | *(counter.data() + j) = tmp; | |
| 65 | 93640 | tmp += a; | |
| 66 | } | ||
| 67 |
2/2✓ Branch 0 taken 3200 times.
✓ Branch 1 taken 448 times.
|
3648 | for (int i = 0; i < size; i++) { |
| 68 | 3200 | int index = byte_view[(8 * i) + byte]; | |
| 69 | 3200 | out[*(counter.data() + index)] = bytes[i]; | |
| 70 | 3200 | *(counter.data() + index) += 1; | |
| 71 | } | ||
| 72 | 448 | } | |
| 73 | ✗ | uint64_t PapulinaYRadixSortSEQ::InBytes(double d) { | |
| 74 | uint64_t bits = 0; | ||
| 75 | memcpy(&bits, &d, sizeof(double)); | ||
| 76 |
2/4✓ Branch 0 taken 80 times.
✓ Branch 1 taken 320 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
400 | if ((bits & kMask) != 0) { |
| 77 | 80 | bits = ~bits; | |
| 78 | } else { | ||
| 79 | 320 | bits = bits ^ kMask; | |
| 80 | } | ||
| 81 | ✗ | return bits; | |
| 82 | } | ||
| 83 | ✗ | double PapulinaYRadixSortSEQ::FromBytes(uint64_t bits) { | |
| 84 | double d = NAN; | ||
| 85 |
2/4✓ Branch 0 taken 320 times.
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
400 | if ((bits & kMask) != 0) { |
| 86 | 320 | bits = bits ^ kMask; | |
| 87 | } else { | ||
| 88 | 80 | bits = ~bits; | |
| 89 | } | ||
| 90 | memcpy(&d, &bits, sizeof(double)); | ||
| 91 | ✗ | return d; | |
| 92 | } | ||
| 93 | 56 | void PapulinaYRadixSortSEQ::RadixSort(double *arr, int size) { | |
| 94 | 56 | std::vector<uint64_t> bytes(size); | |
| 95 |
1/4✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
56 | std::vector<uint64_t> out(size); |
| 96 | |||
| 97 |
2/2✓ Branch 0 taken 400 times.
✓ Branch 1 taken 56 times.
|
456 | for (int i = 0; i < size; i++) { |
| 98 |
2/2✓ Branch 0 taken 80 times.
✓ Branch 1 taken 320 times.
|
800 | bytes[i] = InBytes(arr[i]); |
| 99 | } | ||
| 100 | |||
| 101 | 56 | SortByByte(bytes.data(), out.data(), 0, size); | |
| 102 | 56 | SortByByte(out.data(), bytes.data(), 1, size); | |
| 103 | 56 | SortByByte(bytes.data(), out.data(), 2, size); | |
| 104 | 56 | SortByByte(out.data(), bytes.data(), 3, size); | |
| 105 | 56 | SortByByte(bytes.data(), out.data(), 4, size); | |
| 106 | 56 | SortByByte(out.data(), bytes.data(), 5, size); | |
| 107 | 56 | SortByByte(bytes.data(), out.data(), 6, size); | |
| 108 | 56 | SortByByte(out.data(), bytes.data(), 7, size); | |
| 109 | |||
| 110 |
2/2✓ Branch 0 taken 400 times.
✓ Branch 1 taken 56 times.
|
456 | for (int i = 0; i < size; i++) { |
| 111 |
2/2✓ Branch 0 taken 320 times.
✓ Branch 1 taken 80 times.
|
800 | arr[i] = FromBytes(bytes[i]); |
| 112 | } | ||
| 113 | 56 | } | |
| 114 | } // namespace papulina_y_radix_sort | ||
| 115 |