| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "akimov_i_radix_sort_double_batcher_merge/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <cstddef> | ||
| 4 | #include <cstdint> | ||
| 5 | #include <cstring> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 8 | #include "akimov_i_radix_sort_double_batcher_merge/common/include/common.hpp" | ||
| 9 | |||
| 10 | namespace akimov_i_radix_sort_double_batcher_merge { | ||
| 11 | |||
| 12 |
1/2✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
|
120 | AkimovIRadixBatcherSortSEQ::AkimovIRadixBatcherSortSEQ(const InType &in) { |
| 13 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 14 |
1/2✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
|
120 | GetInput() = in; |
| 15 | GetOutput() = {}; | ||
| 16 | 120 | } | |
| 17 | |||
| 18 | 120 | bool AkimovIRadixBatcherSortSEQ::ValidationImpl() { | |
| 19 | 120 | return true; | |
| 20 | } | ||
| 21 | 120 | bool AkimovIRadixBatcherSortSEQ::PreProcessingImpl() { | |
| 22 | 120 | return true; | |
| 23 | } | ||
| 24 | 120 | bool AkimovIRadixBatcherSortSEQ::PostProcessingImpl() { | |
| 25 | 120 | return true; | |
| 26 | } | ||
| 27 | |||
| 28 | ✗ | uint64_t AkimovIRadixBatcherSortSEQ::PackDouble(double v) noexcept { | |
| 29 | uint64_t bits = 0ULL; | ||
| 30 | std::memcpy(&bits, &v, sizeof(bits)); | ||
| 31 |
2/4✓ Branch 0 taken 136 times.
✓ Branch 1 taken 360 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
496 | if ((bits & (1ULL << 63)) != 0ULL) { |
| 32 | 136 | bits = ~bits; | |
| 33 | } else { | ||
| 34 | 360 | bits ^= (1ULL << 63); | |
| 35 | } | ||
| 36 | ✗ | return bits; | |
| 37 | } | ||
| 38 | |||
| 39 | ✗ | double AkimovIRadixBatcherSortSEQ::UnpackDouble(uint64_t k) noexcept { | |
| 40 | ✗ | if ((k & (1ULL << 63)) != 0ULL) { | |
| 41 | 360 | k ^= (1ULL << 63); | |
| 42 | } else { | ||
| 43 | 136 | k = ~k; | |
| 44 | } | ||
| 45 | double v = 0.0; | ||
| 46 | std::memcpy(&v, &k, sizeof(v)); | ||
| 47 | ✗ | return v; | |
| 48 | } | ||
| 49 | |||
| 50 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 104 times.
|
120 | void AkimovIRadixBatcherSortSEQ::LsdRadixSort(std::vector<double> &arr) { |
| 51 | const std::size_t n = arr.size(); | ||
| 52 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 104 times.
|
120 | if (n <= 1U) { |
| 53 | 16 | return; | |
| 54 | } | ||
| 55 | |||
| 56 | constexpr int kBits = 8; | ||
| 57 | constexpr int kBuckets = 1 << kBits; | ||
| 58 | constexpr int kPasses = static_cast<int>((sizeof(uint64_t) * 8) / kBits); | ||
| 59 | |||
| 60 | 104 | std::vector<uint64_t> keys; | |
| 61 |
1/2✓ Branch 1 taken 104 times.
✗ Branch 2 not taken.
|
104 | keys.resize(n); |
| 62 |
2/2✓ Branch 0 taken 496 times.
✓ Branch 1 taken 104 times.
|
600 | for (std::size_t i = 0; i < n; ++i) { |
| 63 |
2/2✓ Branch 0 taken 136 times.
✓ Branch 1 taken 360 times.
|
992 | keys[i] = PackDouble(arr[i]); |
| 64 | } | ||
| 65 | |||
| 66 | 104 | std::vector<uint64_t> tmp_keys; | |
| 67 |
1/2✓ Branch 1 taken 104 times.
✗ Branch 2 not taken.
|
104 | tmp_keys.resize(n); |
| 68 | 104 | std::vector<double> tmp_vals; | |
| 69 |
1/2✓ Branch 1 taken 104 times.
✗ Branch 2 not taken.
|
104 | tmp_vals.resize(n); |
| 70 | |||
| 71 |
2/2✓ Branch 0 taken 832 times.
✓ Branch 1 taken 104 times.
|
936 | for (int pass = 0; pass < kPasses; ++pass) { |
| 72 | 832 | int shift = pass * kBits; | |
| 73 | 832 | std::vector<std::size_t> cnt; | |
| 74 |
1/4✓ Branch 1 taken 832 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
832 | cnt.assign(kBuckets + 1, 0U); |
| 75 | |||
| 76 |
2/2✓ Branch 0 taken 3968 times.
✓ Branch 1 taken 832 times.
|
4800 | for (std::size_t i = 0; i < n; ++i) { |
| 77 | 3968 | auto d = static_cast<std::size_t>((keys[i] >> shift) & (kBuckets - 1)); | |
| 78 | 3968 | ++cnt[d + 1]; | |
| 79 | } | ||
| 80 |
2/2✓ Branch 0 taken 212992 times.
✓ Branch 1 taken 832 times.
|
213824 | for (int i = 0; i < kBuckets; ++i) { |
| 81 | 212992 | cnt[i + 1] += cnt[i]; | |
| 82 | } | ||
| 83 | |||
| 84 |
2/2✓ Branch 0 taken 3968 times.
✓ Branch 1 taken 832 times.
|
4800 | for (std::size_t i = 0; i < n; ++i) { |
| 85 | 3968 | auto d = static_cast<std::size_t>((keys[i] >> shift) & (kBuckets - 1)); | |
| 86 | 3968 | std::size_t pos = cnt[d]++; | |
| 87 | 3968 | tmp_keys[pos] = keys[i]; | |
| 88 | 3968 | tmp_vals[pos] = arr[i]; | |
| 89 | } | ||
| 90 | |||
| 91 | keys.swap(tmp_keys); | ||
| 92 | arr.swap(tmp_vals); | ||
| 93 | } | ||
| 94 | |||
| 95 |
2/2✓ Branch 0 taken 496 times.
✓ Branch 1 taken 104 times.
|
600 | for (std::size_t i = 0; i < n; ++i) { |
| 96 |
2/2✓ Branch 0 taken 360 times.
✓ Branch 1 taken 136 times.
|
992 | arr[i] = UnpackDouble(keys[i]); |
| 97 | } | ||
| 98 | } | ||
| 99 | |||
| 100 | 120 | bool AkimovIRadixBatcherSortSEQ::RunImpl() { | |
| 101 | 120 | std::vector<double> data = GetInput(); | |
| 102 |
1/2✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
|
120 | LsdRadixSort(data); |
| 103 |
1/2✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
|
120 | GetOutput() = data; |
| 104 | 120 | return true; | |
| 105 | } | ||
| 106 | |||
| 107 | } // namespace akimov_i_radix_sort_double_batcher_merge | ||
| 108 |