| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "posternak_a_radix_merge_sort/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <cmath> | ||
| 4 | #include <cstddef> | ||
| 5 | #include <cstdint> | ||
| 6 | #include <utility> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "posternak_a_radix_merge_sort/common/include/common.hpp" | ||
| 10 | |||
| 11 | namespace posternak_a_radix_merge_sort { | ||
| 12 | |||
| 13 |
1/2✓ Branch 1 taken 148 times.
✗ Branch 2 not taken.
|
148 | PosternakARadixMergeSortSEQ::PosternakARadixMergeSortSEQ(const InType &in) { |
| 14 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 15 |
1/2✓ Branch 1 taken 148 times.
✗ Branch 2 not taken.
|
148 | GetInput() = in; |
| 16 | 148 | } | |
| 17 | |||
| 18 | 148 | bool PosternakARadixMergeSortSEQ::ValidationImpl() { | |
| 19 | 148 | return !GetInput().empty(); | |
| 20 | } | ||
| 21 | |||
| 22 | 148 | bool PosternakARadixMergeSortSEQ::PreProcessingImpl() { | |
| 23 | 148 | return true; | |
| 24 | } | ||
| 25 | |||
| 26 | 148 | bool PosternakARadixMergeSortSEQ::RunImpl() { | |
| 27 | const std::vector<int> &input = GetInput(); | ||
| 28 | 148 | const auto n = static_cast<int>(input.size()); | |
| 29 | |||
| 30 | 148 | std::vector<uint32_t> unsigned_data(static_cast<size_t>(n)); | |
| 31 |
2/2✓ Branch 0 taken 682 times.
✓ Branch 1 taken 148 times.
|
830 | for (int i = 0; i < n; i++) { |
| 32 | 682 | unsigned_data[static_cast<size_t>(i)] = static_cast<uint32_t>(input[static_cast<size_t>(i)]) ^ 0x80000000U; | |
| 33 | } | ||
| 34 | |||
| 35 |
1/4✓ Branch 1 taken 148 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
148 | std::vector<uint32_t> buffer(static_cast<size_t>(n)); |
| 36 | |||
| 37 | constexpr int kNumBytes = 4; | ||
| 38 | constexpr uint32_t kByteMask = 0xFFU; | ||
| 39 | |||
| 40 |
2/2✓ Branch 0 taken 592 times.
✓ Branch 1 taken 148 times.
|
740 | for (int byte_index = 0; byte_index < kNumBytes; byte_index++) { |
| 41 |
1/2✓ Branch 1 taken 592 times.
✗ Branch 2 not taken.
|
592 | std::vector<int> count(256, 0); |
| 42 | |||
| 43 |
2/2✓ Branch 0 taken 2728 times.
✓ Branch 1 taken 592 times.
|
3320 | for (uint32_t value : unsigned_data) { |
| 44 | 2728 | const auto current_byte = static_cast<uint8_t>((value >> (byte_index * 8)) & kByteMask); | |
| 45 | 2728 | ++count[current_byte]; | |
| 46 | } | ||
| 47 | |||
| 48 |
2/2✓ Branch 0 taken 150960 times.
✓ Branch 1 taken 592 times.
|
151552 | for (int i = 1; i < 256; i++) { |
| 49 | 150960 | count[i] += count[i - 1]; | |
| 50 | } | ||
| 51 | |||
| 52 |
2/2✓ Branch 0 taken 2728 times.
✓ Branch 1 taken 592 times.
|
3320 | for (int i = n - 1; i >= 0; i--) { |
| 53 | const auto current_byte = | ||
| 54 | 2728 | static_cast<uint8_t>((unsigned_data[static_cast<size_t>(i)] >> (byte_index * 8)) & kByteMask); | |
| 55 | 2728 | buffer[static_cast<size_t>(--count[current_byte])] = unsigned_data[static_cast<size_t>(i)]; | |
| 56 | } | ||
| 57 | |||
| 58 | unsigned_data.swap(buffer); | ||
| 59 | } | ||
| 60 | |||
| 61 |
1/4✓ Branch 1 taken 148 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
148 | std::vector<int> sorted_output(static_cast<size_t>(n)); |
| 62 |
2/2✓ Branch 0 taken 682 times.
✓ Branch 1 taken 148 times.
|
830 | for (int i = 0; i < n; i++) { |
| 63 | 682 | sorted_output[static_cast<size_t>(i)] = static_cast<int>(unsigned_data[static_cast<size_t>(i)] ^ 0x80000000U); | |
| 64 | } | ||
| 65 | |||
| 66 | GetOutput() = std::move(sorted_output); | ||
| 67 | 148 | return true; | |
| 68 | } | ||
| 69 | |||
| 70 | 148 | bool PosternakARadixMergeSortSEQ::PostProcessingImpl() { | |
| 71 | 148 | return true; | |
| 72 | } | ||
| 73 | |||
| 74 | } // namespace posternak_a_radix_merge_sort | ||
| 75 |