include/simdb/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
17 / 18
94.4%
Branches:
10 / 34
29.4%
Functions:
3 / 3
100.0%

utils/utf16.hpp
Line Branch Exec Source
1 #pragma once
2
3 #include "simdb/Assert.hpp"
4 #include "simdb/Exceptions.hpp"
5
6 #include <cstdint>
7 #include <string>
8
9 namespace simdb::utils {
10
11 3050 inline void uint64_to_utf16(uint64_t value, char16_t* out)
12 {
13
2/2
✓ Branch 4 → 3 taken 61000 times.
✓ Branch 4 → 5 taken 3050 times.
64050 for (int i = 19; i >= 0; --i)
14 {
15 61000 out[i] = static_cast<char16_t>(u'0' + (value % 10));
16 61000 value /= 10;
17 }
18 3050 }
19
20 3050 inline std::u16string uint64_to_utf16(uint64_t value)
21 {
22
1/1
✓ Branch 4 → 5 taken 3050 times.
3050 std::u16string result(20, u'0');
23
1/1
✓ Branch 6 → 7 taken 3050 times.
3050 uint64_to_utf16(value, &result[0]);
24 3050 return result;
25 ✗ }
26
27 3023 inline uint64_t utf16_to_uint64(const char16_t* str, int length)
28 {
29
1/12
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 21 taken 3023 times.
✗ Branch 5 → 6 not taken.
✗ Branch 6 → 7 not taken.
✗ Branch 8 → 9 not taken.
✗ Branch 12 → 13 not taken.
✗ Branch 13 → 14 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 15 → 16 not taken.
✗ Branch 16 → 17 not taken.
✗ Branch 17 → 18 not taken.
✗ Branch 19 → 20 not taken.
3023 simdb_assert(length == 20, "Invalid UTF-16 uint64 length");
30
31 3023 uint64_t value = 0;
32
2/2
✓ Branch 46 → 22 taken 60460 times.
✓ Branch 46 → 47 taken 3023 times.
63483 for (int i = 0; i < 20; ++i)
33 {
34 60460 char16_t ch = str[i];
35
3/16
✓ Branch 22 → 23 taken 60460 times.
✗ Branch 22 → 24 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 60460 times.
✗ Branch 26 → 27 not taken.
✓ Branch 26 → 45 taken 60460 times.
✗ Branch 29 → 30 not taken.
✗ Branch 30 → 31 not taken.
✗ Branch 32 → 33 not taken.
✗ Branch 36 → 37 not taken.
✗ Branch 37 → 38 not taken.
✗ Branch 38 → 39 not taken.
✗ Branch 39 → 40 not taken.
✗ Branch 40 → 41 not taken.
✗ Branch 41 → 42 not taken.
✗ Branch 43 → 44 not taken.
60460 simdb_assert(ch >= u'0' && ch <= u'9', "Invalid digit");
36 60460 value = value * 10 + (ch - u'0');
37 }
38
39 3023 return value;
40 }
41
42 } // namespace simdb::utils
43