| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "baldin_a_radix_sort/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <cstddef> | ||
| 4 | #include <vector> | ||
| 5 | |||
| 6 | #include "baldin_a_radix_sort/common/include/common.hpp" | ||
| 7 | |||
| 8 | namespace baldin_a_radix_sort { | ||
| 9 | |||
| 10 |
1/2✓ Branch 1 taken 104 times.
✗ Branch 2 not taken.
|
104 | BaldinARadixSortSEQ::BaldinARadixSortSEQ(const InType &in) { |
| 11 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 12 |
1/2✓ Branch 1 taken 104 times.
✗ Branch 2 not taken.
|
104 | GetInput() = in; |
| 13 | GetOutput() = {}; | ||
| 14 | 104 | } | |
| 15 | |||
| 16 | 104 | bool BaldinARadixSortSEQ::ValidationImpl() { | |
| 17 | 104 | return true; | |
| 18 | } | ||
| 19 | |||
| 20 | 104 | bool BaldinARadixSortSEQ::PreProcessingImpl() { | |
| 21 | 104 | GetOutput() = GetInput(); | |
| 22 | 104 | return true; | |
| 23 | } | ||
| 24 | |||
| 25 | namespace { | ||
| 26 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 384 times.
|
416 | void CountingSortByByte(std::vector<int> &arr, size_t byte_index) { |
| 27 | size_t n = arr.size(); | ||
| 28 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 384 times.
|
416 | if (n == 0) { |
| 29 | 32 | return; | |
| 30 | } | ||
| 31 | |||
| 32 | 384 | std::vector<int> output(n); | |
| 33 |
1/4✓ Branch 1 taken 384 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
384 | std::vector<int> count(256, 0); |
| 34 | |||
| 35 | 384 | size_t shift = byte_index * 8; | |
| 36 | |||
| 37 |
2/2✓ Branch 0 taken 8160 times.
✓ Branch 1 taken 384 times.
|
8544 | for (size_t i = 0; i < n; i++) { |
| 38 | 8160 | auto raw_val = static_cast<unsigned int>(arr[i]); | |
| 39 | 8160 | unsigned int byte_val = (raw_val >> shift) & 0xFF; | |
| 40 | |||
| 41 |
2/2✓ Branch 0 taken 2040 times.
✓ Branch 1 taken 6120 times.
|
8160 | if (byte_index == sizeof(int) - 1) { |
| 42 | 2040 | byte_val ^= 128; | |
| 43 | } | ||
| 44 | |||
| 45 | 8160 | count[byte_val]++; | |
| 46 | } | ||
| 47 | |||
| 48 |
2/2✓ Branch 0 taken 97920 times.
✓ Branch 1 taken 384 times.
|
98304 | for (int i = 1; i < 256; i++) { |
| 49 | 97920 | count[i] += count[i - 1]; | |
| 50 | } | ||
| 51 | |||
| 52 |
2/2✓ Branch 0 taken 8160 times.
✓ Branch 1 taken 384 times.
|
8544 | for (size_t i = n; i > 0; i--) { |
| 53 |
2/2✓ Branch 0 taken 2040 times.
✓ Branch 1 taken 6120 times.
|
8160 | size_t idx = i - 1; |
| 54 | 8160 | auto raw_val = static_cast<unsigned int>(arr[idx]); | |
| 55 | 8160 | unsigned int byte_val = (raw_val >> shift) & 0xFF; | |
| 56 | |||
| 57 |
2/2✓ Branch 0 taken 2040 times.
✓ Branch 1 taken 6120 times.
|
8160 | if (byte_index == sizeof(int) - 1) { |
| 58 | 2040 | byte_val ^= 128; | |
| 59 | } | ||
| 60 | |||
| 61 | 8160 | output[count[byte_val] - 1] = arr[idx]; | |
| 62 | 8160 | count[byte_val]--; | |
| 63 | } | ||
| 64 | |||
| 65 |
1/2✓ Branch 1 taken 384 times.
✗ Branch 2 not taken.
|
384 | arr = output; |
| 66 | } | ||
| 67 | } // namespace | ||
| 68 | |||
| 69 | 104 | bool BaldinARadixSortSEQ::RunImpl() { | |
| 70 |
2/2✓ Branch 0 taken 416 times.
✓ Branch 1 taken 104 times.
|
520 | for (size_t byte_index = 0; byte_index < sizeof(int); byte_index++) { |
| 71 | 416 | CountingSortByByte(GetOutput(), byte_index); | |
| 72 | } | ||
| 73 | 104 | return true; | |
| 74 | } | ||
| 75 | |||
| 76 | 104 | bool BaldinARadixSortSEQ::PostProcessingImpl() { | |
| 77 | 104 | return true; | |
| 78 | } | ||
| 79 | |||
| 80 | } // namespace baldin_a_radix_sort | ||
| 81 |