Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::BaseUUID Class Reference

The BaseUUID class contains UUID related common and util functions. More...

#include <duckdb.hpp>

Inheritance diagram for duckdb::BaseUUID:

Static Public Member Functions

static bool FromString (const string &str, hugeint_t &result, bool strict=false)
 Convert a uuid string to a hugeint object.
static bool FromCString (const char *str, idx_t len, hugeint_t &result)
 Convert a uuid string to a hugeint object.
static void ToString (hugeint_t input, char *buf)
 Convert a hugeint object to a uuid style string.
static hugeint_t FromUHugeint (uhugeint_t input)
 Convert a uhugeint_t object to a uuid value.
static uhugeint_t ToUHugeint (hugeint_t input)
 Convert a uuid value to a uhugeint_t object.
static hugeint_t FromBlob (const_data_ptr_t input)
 Convert 16-byte binary data to UUID (hugeint_t).
static void ToBlob (hugeint_t input, data_ptr_t output)
 Convert UUID (hugeint_t) to 16-byte binary data.
static string ToString (hugeint_t input)
 Convert a hugeint object to a uuid style string.
static hugeint_t FromString (const string &str)

Static Public Attributes

static constexpr const uint8_t STRING_SIZE = 36

Static Protected Member Functions

static hugeint_t Convert (const std::array< uint8_t, 16 > &bytes)
 Util function, which converts uint8_t array to hugeint_t.

Detailed Description

The BaseUUID class contains UUID related common and util functions.

Member Function Documentation

◆ FromString() [1/2]

bool duckdb::BaseUUID::FromString ( const string & str,
hugeint_t & result,
bool strict = false )
static

Convert a uuid string to a hugeint object.

130879 {
130880 auto hex2char = [](char ch) -> unsigned char {
130881 if (ch >= '0' && ch <= '9') {
130882 return UnsafeNumericCast<unsigned char>(ch - '0');
130883 }
130884 if (ch >= 'a' && ch <= 'f') {
130885 return UnsafeNumericCast<unsigned char>(10 + ch - 'a');
130886 }
130887 if (ch >= 'A' && ch <= 'F') {
130888 return UnsafeNumericCast<unsigned char>(10 + ch - 'A');
130889 }
130890 return 0;
130891 };
130892 auto is_hex = [](char ch) -> bool {
130893 return (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F');
130894 };
130895
130896 if (str.empty()) {
130897 return false;
130898 }
130899 idx_t has_braces = 0;
130900 if (str.front() == '{') {
130901 has_braces = 1;
130902 }
130903 if (has_braces && str.back() != '}') {
130904 return false;
130905 }
130906
130907 if (strict) {
130908 // 32 characters and 4 hyphens
130909 if (str.length() != 36) {
130910 return false;
130911 }
130912 const auto c_str = str.c_str();
130913 if (c_str[8] != '-' || c_str[13] != '-' || c_str[18] != '-' || c_str[23] != '-') {
130914 return false;
130915 }
130916 }
130917
130918 result.lower = 0;
130919 result.upper = 0;
130920 size_t count = 0;
130921 for (size_t i = has_braces; i < str.size() - has_braces; ++i) {
130922 if (str[i] == '-') {
130923 continue;
130924 }
130925 if (count >= 32 || !is_hex(str[i])) {
130926 return false;
130927 }
130928 if (count >= 16) {
130929 result.lower = (result.lower << 4) | hex2char(str[i]);
130930 } else {
130931 result.upper = (result.upper << 4) | hex2char(str[i]);
130932 }
130933 count++;
130934 }
130935 // Flip the first bit to make `order by uuid` same as `order by uuid::varchar`
130936 result.upper ^= NumericLimits<int64_t>::Minimum();
130937 return count == 32;
130938}
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
Here is the caller graph for this function:

◆ FromCString()

bool duckdb::BaseUUID::FromCString ( const char * str,
idx_t len,
hugeint_t & result )
inlinestatic

Convert a uuid string to a hugeint object.

57421 {
57422 return FromString(string(str, 0, len), result);
57423 }
static bool FromString(const string &str, hugeint_t &result, bool strict=false)
Convert a uuid string to a hugeint object.
Definition duckdb.cpp:130879
Here is the call graph for this function:

◆ ToString() [1/2]

void duckdb::BaseUUID::ToString ( hugeint_t input,
char * buf )
static

Convert a hugeint object to a uuid style string.

130940 {
130941 auto byte_to_hex = [](uint64_t byte_val, char *buf, idx_t &pos) {
130942 D_ASSERT(byte_val <= 0xFF);
130943 static char const HEX_DIGITS[] = "0123456789abcdef";
130944 buf[pos++] = HEX_DIGITS[(byte_val >> 4) & 0xf];
130945 buf[pos++] = HEX_DIGITS[byte_val & 0xf];
130946 };
130947
130948 // Flip back before convert to string
130949 int64_t upper = int64_t(uint64_t(input.upper) ^ (uint64_t(1) << 63));
130950 idx_t pos = 0;
130951 byte_to_hex(upper >> 56 & 0xFF, buf, pos);
130952 byte_to_hex(upper >> 48 & 0xFF, buf, pos);
130953 byte_to_hex(upper >> 40 & 0xFF, buf, pos);
130954 byte_to_hex(upper >> 32 & 0xFF, buf, pos);
130955 buf[pos++] = '-';
130956 byte_to_hex(upper >> 24 & 0xFF, buf, pos);
130957 byte_to_hex(upper >> 16 & 0xFF, buf, pos);
130958 buf[pos++] = '-';
130959 byte_to_hex(upper >> 8 & 0xFF, buf, pos);
130960 byte_to_hex(upper & 0xFF, buf, pos);
130961 buf[pos++] = '-';
130962 byte_to_hex(input.lower >> 56 & 0xFF, buf, pos);
130963 byte_to_hex(input.lower >> 48 & 0xFF, buf, pos);
130964 buf[pos++] = '-';
130965 byte_to_hex(input.lower >> 40 & 0xFF, buf, pos);
130966 byte_to_hex(input.lower >> 32 & 0xFF, buf, pos);
130967 byte_to_hex(input.lower >> 24 & 0xFF, buf, pos);
130968 byte_to_hex(input.lower >> 16 & 0xFF, buf, pos);
130969 byte_to_hex(input.lower >> 8 & 0xFF, buf, pos);
130970 byte_to_hex(input.lower & 0xFF, buf, pos);
130971}
::int64_t int64_t
::uint64_t uint64_t
Here is the caller graph for this function:

◆ FromUHugeint()

hugeint_t duckdb::BaseUUID::FromUHugeint ( uhugeint_t input)
static

Convert a uhugeint_t object to a uuid value.

130973 {
130974 hugeint_t result;
130975 result.lower = input.lower;
130976 if (input.upper > uint64_t(NumericLimits<int64_t>::Maximum())) {
130977 result.upper = int64_t(input.upper - uint64_t(NumericLimits<int64_t>::Maximum()) - 1);
130978 } else {
130979 result.upper = int64_t(input.upper) - NumericLimits<int64_t>::Maximum() - 1;
130980 }
130981 return result;
130982}
Here is the caller graph for this function:

◆ ToUHugeint()

uhugeint_t duckdb::BaseUUID::ToUHugeint ( hugeint_t input)
static

Convert a uuid value to a uhugeint_t object.

130984 {
130985 uhugeint_t result;
130986 result.lower = input.lower;
130987 if (input.upper >= 0) {
130988 result.upper = uint64_t(input.upper) + uint64_t(NumericLimits<int64_t>::Maximum()) + 1;
130989 } else {
130990 result.upper = uint64_t(input.upper + NumericLimits<int64_t>::Maximum() + 1);
130991 }
130992 return result;
130993}
Here is the caller graph for this function:

◆ FromBlob()

hugeint_t duckdb::BaseUUID::FromBlob ( const_data_ptr_t input)
static

Convert 16-byte binary data to UUID (hugeint_t).

131094 {
131095 // Based on UUIDValueConversion::ReadParquetUUID from parquet extension
131096 hugeint_t result;
131097 result.lower = 0;
131098 uint64_t unsigned_upper = 0;
131099 for (idx_t i = 0; i < sizeof(uint64_t); i++) {
131100 unsigned_upper <<= 8;
131101 unsigned_upper += static_cast<uint64_t>(input[i]);
131102 }
131103 for (idx_t i = sizeof(uint64_t); i < sizeof(hugeint_t); i++) {
131104 result.lower <<= 8;
131105 result.lower += static_cast<uint64_t>(input[i]);
131106 }
131107 result.upper = static_cast<int64_t>(unsigned_upper ^ (uint64_t(1) << 63));
131108 return result;
131109}

◆ ToBlob()

void duckdb::BaseUUID::ToBlob ( hugeint_t input,
data_ptr_t output )
static

Convert UUID (hugeint_t) to 16-byte binary data.

131111 {
131112 // Based on ParquetUUIDOperator::Operation from parquet extension
131113 uint64_t high_bytes = static_cast<uint64_t>(input.upper) ^ (uint64_t(1) << 63);
131114 uint64_t low_bytes = input.lower;
131115 for (idx_t i = 0; i < sizeof(uint64_t); i++) {
131116 auto shift_count = (sizeof(uint64_t) - i - 1) * 8;
131117 output[i] = static_cast<uint8_t>((high_bytes >> shift_count) & 0xFF);
131118 }
131119 for (idx_t i = 0; i < sizeof(uint64_t); i++) {
131120 auto shift_count = (sizeof(uint64_t) - i - 1) * 8;
131121 output[sizeof(uint64_t) + i] = static_cast<uint8_t>((low_bytes >> shift_count) & 0xFF);
131122 }
131123}
::uint8_t uint8_t

◆ ToString() [2/2]

string duckdb::BaseUUID::ToString ( hugeint_t input)
inlinestatic

Convert a hugeint object to a uuid style string.

57438 {
57439 char buff[STRING_SIZE];
57440 ToString(input, buff);
57441 return string(buff, STRING_SIZE);
57442 }
static void ToString(hugeint_t input, char *buf)
Convert a hugeint object to a uuid style string.
Definition duckdb.cpp:130940
Here is the call graph for this function:

◆ FromString() [2/2]

hugeint_t duckdb::BaseUUID::FromString ( const string & str)
inlinestatic
57444 {
57445 hugeint_t result;
57446 FromString(str, result);
57447 return result;
57448 }

◆ Convert()

hugeint_t duckdb::BaseUUID::Convert ( const std::array< uint8_t, 16 > & bytes)
staticprotected

Util function, which converts uint8_t array to hugeint_t.

130995 {
130996 hugeint_t result;
130997 result.upper = 0;
130998 result.upper |= ((int64_t)bytes[0] << 56);
130999 result.upper |= ((int64_t)bytes[1] << 48);
131000 result.upper |= ((int64_t)bytes[2] << 40);
131001 result.upper |= ((int64_t)bytes[3] << 32);
131002 result.upper |= ((int64_t)bytes[4] << 24);
131003 result.upper |= ((int64_t)bytes[5] << 16);
131004 result.upper |= ((int64_t)bytes[6] << 8);
131005 result.upper |= (int64_t)bytes[7];
131006 result.lower = 0;
131007 result.lower |= ((uint64_t)bytes[8] << 56);
131008 result.lower |= ((uint64_t)bytes[9] << 48);
131009 result.lower |= ((uint64_t)bytes[10] << 40);
131010 result.lower |= ((uint64_t)bytes[11] << 32);
131011 result.lower |= ((uint64_t)bytes[12] << 24);
131012 result.lower |= ((uint64_t)bytes[13] << 16);
131013 result.lower |= ((uint64_t)bytes[14] << 8);
131014 result.lower |= (uint64_t)bytes[15];
131015 return result;
131016}
Here is the caller graph for this function:

The documentation for this class was generated from the following files: