| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "dorogin_v_bitwise_simple_merge/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cstdint> | ||
| 5 | #include <cstring> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 8 | #include "dorogin_v_bitwise_simple_merge/common/include/common.hpp" | ||
| 9 | |||
| 10 | namespace dorogin_v_bitwise_simple_merge { | ||
| 11 | |||
| 12 | namespace { | ||
| 13 | |||
| 14 | uint64_t DoubleToSortableKey(double value) { | ||
| 15 | uint64_t bits = 0; | ||
| 16 | std::memcpy(&bits, &value, sizeof(double)); | ||
| 17 |
2/2✓ Branch 0 taken 6326 times.
✓ Branch 1 taken 6474 times.
|
12800 | if ((bits >> 63) != 0) { |
| 18 | 6326 | bits = ~bits; | |
| 19 | } else { | ||
| 20 | 6474 | bits ^= (static_cast<uint64_t>(1) << 63); | |
| 21 | } | ||
| 22 | return bits; | ||
| 23 | } | ||
| 24 | |||
| 25 | double SortableKeyToDouble(uint64_t bits) { | ||
| 26 | 12800 | if ((bits >> 63) != 0) { | |
| 27 | 6474 | bits ^= (static_cast<uint64_t>(1) << 63); | |
| 28 | } else { | ||
| 29 | 6326 | bits = ~bits; | |
| 30 | } | ||
| 31 | double value = 0; | ||
| 32 | std::memcpy(&value, &bits, sizeof(double)); | ||
| 33 | return value; | ||
| 34 | } | ||
| 35 | |||
| 36 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
|
24 | void RadixSort(std::vector<double> &data) { |
| 37 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
|
24 | if (data.size() <= 1) { |
| 38 | ✗ | return; | |
| 39 | } | ||
| 40 | |||
| 41 | 24 | std::vector<uint64_t> keys(data.size()); | |
| 42 |
2/2✓ Branch 0 taken 12800 times.
✓ Branch 1 taken 24 times.
|
12824 | for (size_t i = 0; i < data.size(); i++) { |
| 43 |
2/2✓ Branch 0 taken 6326 times.
✓ Branch 1 taken 6474 times.
|
25600 | keys[i] = DoubleToSortableKey(data[i]); |
| 44 | } | ||
| 45 | |||
| 46 |
1/4✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
24 | std::vector<uint64_t> temp(data.size()); |
| 47 | |||
| 48 |
2/2✓ Branch 0 taken 192 times.
✓ Branch 1 taken 24 times.
|
216 | for (int shift = 0; shift < 64; shift += 8) { |
| 49 |
1/4✓ Branch 1 taken 192 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
192 | std::vector<size_t> count(257, 0); |
| 50 | |||
| 51 |
2/2✓ Branch 0 taken 102400 times.
✓ Branch 1 taken 192 times.
|
102592 | for (const auto &key : keys) { |
| 52 | 102400 | size_t bucket = (key >> shift) & 0xFF; | |
| 53 | 102400 | count[bucket + 1]++; | |
| 54 | } | ||
| 55 | |||
| 56 |
2/2✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 192 times.
|
49344 | for (int i = 1; i <= 256; i++) { |
| 57 | 49152 | count[i] += count[i - 1]; | |
| 58 | } | ||
| 59 | |||
| 60 |
2/2✓ Branch 0 taken 102400 times.
✓ Branch 1 taken 192 times.
|
102592 | for (const auto &key : keys) { |
| 61 | 102400 | size_t bucket = (key >> shift) & 0xFF; | |
| 62 | 102400 | temp[count[bucket]++] = key; | |
| 63 | } | ||
| 64 | |||
| 65 | std::swap(keys, temp); | ||
| 66 | } | ||
| 67 | |||
| 68 |
2/2✓ Branch 0 taken 12800 times.
✓ Branch 1 taken 24 times.
|
12824 | for (size_t i = 0; i < data.size(); i++) { |
| 69 |
2/2✓ Branch 0 taken 6474 times.
✓ Branch 1 taken 6326 times.
|
25600 | data[i] = SortableKeyToDouble(keys[i]); |
| 70 | } | ||
| 71 | } | ||
| 72 | |||
| 73 | } // namespace | ||
| 74 | |||
| 75 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | DoroginVBitwiseSimpleMergeSEQ::DoroginVBitwiseSimpleMergeSEQ(const InType &in) { |
| 76 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 77 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | GetInput() = in; |
| 78 | GetOutput() = {}; | ||
| 79 | 24 | } | |
| 80 | |||
| 81 | 24 | bool DoroginVBitwiseSimpleMergeSEQ::ValidationImpl() { | |
| 82 | 24 | return true; | |
| 83 | } | ||
| 84 | |||
| 85 | 24 | bool DoroginVBitwiseSimpleMergeSEQ::PreProcessingImpl() { | |
| 86 | 24 | input_data_ = GetInput(); | |
| 87 | output_data_.clear(); | ||
| 88 | 24 | return true; | |
| 89 | } | ||
| 90 | |||
| 91 | 24 | bool DoroginVBitwiseSimpleMergeSEQ::RunImpl() { | |
| 92 | 24 | output_data_ = input_data_; | |
| 93 | 24 | RadixSort(output_data_); | |
| 94 | 24 | return true; | |
| 95 | } | ||
| 96 | |||
| 97 | 24 | bool DoroginVBitwiseSimpleMergeSEQ::PostProcessingImpl() { | |
| 98 | 24 | GetOutput() = output_data_; | |
| 99 | 24 | return true; | |
| 100 | } | ||
| 101 | |||
| 102 | } // namespace dorogin_v_bitwise_simple_merge | ||
| 103 |