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::Bit Class Reference

The Bit class is a static class that holds helper functions for the BIT type. More...

Static Public Member Functions

static DUCKDB_API idx_t BitLength (bitstring_t bits)
 Returns the number of bits in the bit string.
static DUCKDB_API idx_t BitCount (bitstring_t bits)
 Returns the number of set bits in the bit string.
static DUCKDB_API idx_t OctetLength (bitstring_t bits)
 Returns the number of bytes in the bit string.
static DUCKDB_API idx_t GetBit (bitstring_t bit_string, idx_t n)
 Extracts the nth bit from bit string; the first (leftmost) bit is indexed 0.
static DUCKDB_API void SetBit (bitstring_t &bit_string, idx_t n, idx_t new_value)
 Sets the nth bit in bit string to newvalue; the first (leftmost) bit is indexed 0.
static DUCKDB_API idx_t BitPosition (bitstring_t substring, bitstring_t bits)
 Returns first starting index of the specified substring within bits, or zero if it's not present.
static DUCKDB_API void ToString (bitstring_t bits, char *output)
static DUCKDB_API string ToString (bitstring_t bits)
static DUCKDB_API bool TryGetBitStringSize (string_t str, idx_t &result_size, string *error_message)
 Returns the bit size of a string -> bit conversion.
static DUCKDB_API void ToBit (string_t str, bitstring_t &output)
static DUCKDB_API string ToBit (string_t str)
static DUCKDB_API void BlobToBit (string_t blob, bitstring_t &output)
 output needs to have enough space allocated before calling this function (blob size + 1)
static DUCKDB_API string BlobToBit (string_t blob)
template<class T>
static void NumericToBit (T numeric, bitstring_t &output_str)
 output_str needs to have enough space allocated before calling this function (sizeof(T) + 1)
template<class T>
static string NumericToBit (T numeric)
template<class T>
static void BitToNumeric (bitstring_t bit, T &output_num)
 bit is expected to fit inside of output num (bit size <= sizeof(T) + 1)
template<class T>
static T BitToNumeric (bitstring_t bit)
static void BitToBlob (bitstring_t bit, string_t &output_blob)
 bit is expected to fit inside of output_blob (bit size = output_blob + 1)
static string BitToBlob (bitstring_t bit)
static DUCKDB_API void BitString (const string_t &input, idx_t len, bitstring_t &result)
 Creates a new bitstring of determined length.
static DUCKDB_API void ExtendBitString (const bitstring_t &input, idx_t bit_length, bitstring_t &result)
static DUCKDB_API void SetEmptyBitString (bitstring_t &target, string_t &input)
static DUCKDB_API void SetEmptyBitString (bitstring_t &target, idx_t len)
static DUCKDB_API idx_t ComputeBitstringLen (idx_t len)
static DUCKDB_API void RightShift (const bitstring_t &bit_string, idx_t shift, bitstring_t &result)
static DUCKDB_API void LeftShift (const bitstring_t &bit_string, idx_t shift, bitstring_t &result)
static DUCKDB_API void BitwiseAnd (const bitstring_t &rhs, const bitstring_t &lhs, bitstring_t &result)
static DUCKDB_API void BitwiseOr (const bitstring_t &rhs, const bitstring_t &lhs, bitstring_t &result)
static DUCKDB_API void BitwiseXor (const bitstring_t &rhs, const bitstring_t &lhs, bitstring_t &result)
static DUCKDB_API void BitwiseNot (const bitstring_t &rhs, bitstring_t &result)
static DUCKDB_API void Verify (const bitstring_t &input)

Static Private Member Functions

static void Finalize (bitstring_t &str)
static idx_t GetBitInternal (bitstring_t bit_string, idx_t n)
static void SetBitInternal (bitstring_t &bit_string, idx_t n, idx_t new_value)
static idx_t GetBitIndex (idx_t n)
static uint8_t GetFirstByte (const bitstring_t &str)

Detailed Description

The Bit class is a static class that holds helper functions for the BIT type.

Member Function Documentation

◆ BitLength()

idx_t duckdb::Bit::BitLength ( bitstring_t bits)
static

Returns the number of bits in the bit string.

112914 {
112915 return ((bits.GetSize() - 1) * 8) - GetBitPadding(bits);
112916}
Here is the caller graph for this function:

◆ BitCount()

idx_t duckdb::Bit::BitCount ( bitstring_t bits)
static

Returns the number of set bits in the bit string.

112922 {
112923 idx_t count = 0;
112924 const char *buf = bits.GetData();
112925 for (idx_t byte_idx = 1; byte_idx < OctetLength(bits) + 1; byte_idx++) {
112926 for (idx_t bit_idx = 0; bit_idx < 8; bit_idx++) {
112927 count += (buf[byte_idx] & (1 << bit_idx)) ? 1 : 0;
112928 }
112929 }
112930 return count - GetBitPadding(bits);
112931}
static DUCKDB_API idx_t OctetLength(bitstring_t bits)
Returns the number of bytes in the bit string.
Definition duckdb.cpp:112918
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
Here is the call graph for this function:

◆ OctetLength()

idx_t duckdb::Bit::OctetLength ( bitstring_t bits)
static

Returns the number of bytes in the bit string.

112918 {
112919 return bits.GetSize() - 1;
112920}
Here is the caller graph for this function:

◆ GetBit()

idx_t duckdb::Bit::GetBit ( bitstring_t bit_string,
idx_t n )
static

Extracts the nth bit from bit string; the first (leftmost) bit is indexed 0.

112967 {
112968 return Bit::GetBitInternal(bit_string, n + GetBitPadding(bit_string));
112969}
Here is the caller graph for this function:

◆ SetBit()

void duckdb::Bit::SetBit ( bitstring_t & bit_string,
idx_t n,
idx_t new_value )
static

Sets the nth bit in bit string to newvalue; the first (leftmost) bit is indexed 0.

112983 {
112984 SetBitInternal(bit_string, n + GetBitPadding(bit_string), new_value);
112985 Bit::Finalize(bit_string);
112986}

◆ BitPosition()

idx_t duckdb::Bit::BitPosition ( bitstring_t substring,
bitstring_t bits )
static

Returns first starting index of the specified substring within bits, or zero if it's not present.

112933 {
112934 const char *buf = bits.GetData();
112935 auto len = bits.GetSize();
112936 auto substr_len = BitLength(substring);
112937 idx_t substr_idx = 0;
112938
112939 for (idx_t bit_idx = GetBitPadding(bits); bit_idx < 8; bit_idx++) {
112940 idx_t bit = buf[1] & (1 << (7 - bit_idx)) ? 1 : 0;
112941 if (bit == GetBit(substring, substr_idx)) {
112942 substr_idx++;
112943 if (substr_idx == substr_len) {
112944 return (bit_idx - GetBitPadding(bits)) - substr_len + 2;
112945 }
112946 } else {
112947 substr_idx = 0;
112948 }
112949 }
112950
112951 for (idx_t byte_idx = 2; byte_idx < len; byte_idx++) {
112952 for (idx_t bit_idx = 0; bit_idx < 8; bit_idx++) {
112953 idx_t bit = buf[byte_idx] & (1 << (7 - bit_idx)) ? 1 : 0;
112954 if (bit == GetBit(substring, substr_idx)) {
112955 substr_idx++;
112956 if (substr_idx == substr_len) {
112957 return (((byte_idx - 1) * 8) + bit_idx - GetBitPadding(bits)) - substr_len + 2;
112958 }
112959 } else {
112960 substr_idx = 0;
112961 }
112962 }
112963 }
112964 return 0;
112965}
static DUCKDB_API idx_t BitLength(bitstring_t bits)
Returns the number of bits in the bit string.
Definition duckdb.cpp:112914
static DUCKDB_API idx_t GetBit(bitstring_t bit_string, idx_t n)
Extracts the nth bit from bit string; the first (leftmost) bit is indexed 0.
Definition duckdb.cpp:112967
Here is the call graph for this function:

◆ ToString() [1/2]

void duckdb::Bit::ToString ( bitstring_t bits,
char * output )
static

Converts bits to a string, writing the output to the designated output string. The string needs to have space for at least GetStringSize(bits) bytes.

112748 {
112749 auto data = const_data_ptr_cast(bits.GetData());
112750 auto len = bits.GetSize();
112751
112752 idx_t padding = GetBitPadding(bits);
112753 idx_t output_idx = 0;
112754 for (idx_t bit_idx = padding; bit_idx < 8; bit_idx++) {
112755 output[output_idx++] = data[1] & (1 << (7 - bit_idx)) ? '1' : '0';
112756 }
112757 for (idx_t byte_idx = 2; byte_idx < len; byte_idx++) {
112758 for (idx_t bit_idx = 0; bit_idx < 8; bit_idx++) {
112759 output[output_idx++] = data[byte_idx] & (1 << (7 - bit_idx)) ? '1' : '0';
112760 }
112761 }
112762}

◆ ToString() [2/2]

string duckdb::Bit::ToString ( bitstring_t bits)
static
112764 {
112765 auto len = BitLength(str);
112766 auto buffer = make_unsafe_uniq_array_uninitialized<char>(len);
112767 ToString(str, buffer.get());
112768 return string(buffer.get(), len);
112769}
static DUCKDB_API void ToString(bitstring_t bits, char *output)
Definition duckdb.cpp:112748

◆ TryGetBitStringSize()

bool duckdb::Bit::TryGetBitStringSize ( string_t str,
idx_t & result_size,
string * error_message )
static

Returns the bit size of a string -> bit conversion.

112771 {
112772 auto data = const_data_ptr_cast(str.GetData());
112773 auto len = str.GetSize();
112774 str_len = 0;
112775 for (idx_t i = 0; i < len; i++) {
112776 if (data[i] == '0' || data[i] == '1') {
112777 str_len++;
112778 } else {
112779 string error = StringUtil::Format("Invalid character encountered in string -> bit conversion: '%s'",
112780 string(const_char_ptr_cast(data) + i, 1));
112781 HandleCastError::AssignError(error, error_message);
112782 return false;
112783 }
112784 }
112785 if (str_len == 0) {
112786 string error = "Cannot cast empty string to BIT";
112787 HandleCastError::AssignError(error, error_message);
112788 return false;
112789 }
112790 str_len = ComputeBitstringLen(str_len);
112791 return true;
112792}
static string Format(const string fmt_str, ARGS... params)
Format a string using printf semantics.
Definition duckdb.hpp:4002
Here is the call graph for this function:

◆ ToBit() [1/2]

void duckdb::Bit::ToBit ( string_t str,
bitstring_t & output )
static

Convert a string to a bit. This function should ONLY be called after calling GetBitSize, since it does NOT perform data validation.

112794 {
112795 auto data = const_data_ptr_cast(str.GetData());
112796 auto len = str.GetSize();
112797 auto output = output_str.GetDataWriteable();
112798
112799 char byte = 0;
112800 idx_t padded_byte = len % 8;
112801 for (idx_t i = 0; i < padded_byte; i++) {
112802 byte <<= 1;
112803 if (data[i] == '1') {
112804 byte |= 1;
112805 }
112806 }
112807 if (padded_byte != 0) {
112808 *(output++) = UnsafeNumericCast<char>((8 - padded_byte)); // the first byte contains the number of padded zeroes
112809 }
112810 *(output++) = byte;
112811
112812 for (idx_t byte_idx = padded_byte; byte_idx < len; byte_idx += 8) {
112813 byte = 0;
112814 for (idx_t bit_idx = 0; bit_idx < 8; bit_idx++) {
112815 byte <<= 1;
112816 if (data[byte_idx + bit_idx] == '1') {
112817 byte |= 1;
112818 }
112819 }
112820 *(output++) = byte;
112821 }
112822 Bit::Finalize(output_str);
112823}

◆ ToBit() [2/2]

string duckdb::Bit::ToBit ( string_t str)
static
112825 {
112826 auto bit_len = GetBitSize(str);
112827 auto buffer = make_unsafe_uniq_array_uninitialized<char>(bit_len);
112828 bitstring_t output_str(buffer.get(), UnsafeNumericCast<uint32_t>(bit_len));
112829 Bit::ToBit(str, output_str);
112830 return output_str.GetString();
112831}
static DUCKDB_API void ToBit(string_t str, bitstring_t &output)
Definition duckdb.cpp:112794

◆ BlobToBit() [1/2]

void duckdb::Bit::BlobToBit ( string_t blob,
bitstring_t & output )
static

output needs to have enough space allocated before calling this function (blob size + 1)

112833 {
112834 auto data = const_data_ptr_cast(blob.GetData());
112835 auto output = output_str.GetDataWriteable();
112836 idx_t size = blob.GetSize();
112837
112838 *output = 0; // No padding
112839 memcpy(output + 1, data, size);
112840}
GOpaque< Size > size(const GMat &src)

◆ BlobToBit() [2/2]

string duckdb::Bit::BlobToBit ( string_t blob)
static
112842 {
112843 auto buffer = make_unsafe_uniq_array_uninitialized<char>(blob.GetSize() + 1);
112844 bitstring_t output_str(buffer.get(), UnsafeNumericCast<uint32_t>(blob.GetSize() + 1));
112845 Bit::BlobToBit(blob, output_str);
112846 return output_str.GetString();
112847}
static DUCKDB_API void BlobToBit(string_t blob, bitstring_t &output)
output needs to have enough space allocated before calling this function (blob size + 1)
Definition duckdb.cpp:112833

◆ NumericToBit() [1/2]

template<class T>
void duckdb::Bit::NumericToBit ( T numeric,
bitstring_t & output_str )
static

output_str needs to have enough space allocated before calling this function (sizeof(T) + 1)

31110 {
31111 D_ASSERT(output_str.GetSize() >= sizeof(T) + 1);
31112
31113 auto le_numeric = BSwapIfBE(numeric);
31114 auto output = output_str.GetDataWriteable();
31115 auto data = const_data_ptr_cast(&le_numeric);
31116
31117 *output = 0; // set padding to 0
31118 ++output;
31119 for (idx_t idx = 0; idx < sizeof(T); ++idx) {
31120 output[idx] = static_cast<char>(data[sizeof(T) - idx - 1]);
31121 }
31122 Bit::Finalize(output_str);
31123}

◆ NumericToBit() [2/2]

template<class T>
string duckdb::Bit::NumericToBit ( T numeric)
static
31126 {
31127 auto bit_len = sizeof(T) + 1;
31128 auto buffer = make_unsafe_uniq_array_uninitialized<char>(bit_len);
31129 bitstring_t output_str(buffer.get(), UnsafeNumericCast<uint32_t>(bit_len));
31130 Bit::NumericToBit(numeric, output_str);
31131 return output_str.GetString();
31132}
static void NumericToBit(T numeric, bitstring_t &output_str)
output_str needs to have enough space allocated before calling this function (sizeof(T) + 1)
Definition duckdb.cpp:31110

◆ BitToNumeric() [1/2]

template<class T>
void duckdb::Bit::BitToNumeric ( bitstring_t bit,
T & output_num )
static

bit is expected to fit inside of output num (bit size <= sizeof(T) + 1)

31142 {
31143 D_ASSERT(bit.GetSize() <= sizeof(T) + 1);
31144
31145 output_num = 0;
31146 auto data = const_data_ptr_cast(bit.GetData());
31147 auto output = data_ptr_cast(&output_num);
31148
31149 idx_t padded_byte_idx = sizeof(T) - bit.GetSize() + 1;
31150 output[sizeof(T) - 1 - padded_byte_idx] = GetFirstByte(bit);
31151 for (idx_t idx = padded_byte_idx + 1; idx < sizeof(T); ++idx) {
31152 output[sizeof(T) - 1 - idx] = data[1 + idx - padded_byte_idx];
31153 }
31154 output_num = BSwapIfBE(output_num);
31155}

◆ BitToNumeric() [2/2]

template<class T>
T duckdb::Bit::BitToNumeric ( bitstring_t bit)
static
31135 {
31136 T output;
31137 Bit::BitToNumeric(bit, output);
31138 return (output);
31139}
static void BitToNumeric(bitstring_t bit, T &output_num)
bit is expected to fit inside of output num (bit size <= sizeof(T) + 1)
Definition duckdb.cpp:31142

◆ BitToBlob() [1/2]

void duckdb::Bit::BitToBlob ( bitstring_t bit,
string_t & output_blob )
static

bit is expected to fit inside of output_blob (bit size = output_blob + 1)

112849 {
112850 D_ASSERT(bit.GetSize() == output_blob.GetSize() + 1);
112851
112852 auto data = const_data_ptr_cast(bit.GetData());
112853 auto output = output_blob.GetDataWriteable();
112854 idx_t size = output_blob.GetSize();
112855
112856 output[0] = static_cast<char>(GetFirstByte(bit));
112857 if (size >= 2) {
112858 ++output;
112859 // First byte in bitstring contains amount of padded bits,
112860 // second byte in bitstring is the padded byte,
112861 // therefore the rest of the data starts at data + 2 (third byte)
112862 memcpy(output, data + 2, size - 1);
112863 }
112864}

◆ BitToBlob() [2/2]

string duckdb::Bit::BitToBlob ( bitstring_t bit)
static
112866 {
112867 D_ASSERT(bit.GetSize() > 1);
112868
112869 auto buffer = make_unsafe_uniq_array_uninitialized<char>(bit.GetSize() - 1);
112870 string_t output_str(buffer.get(), UnsafeNumericCast<uint32_t>(bit.GetSize() - 1));
112871 Bit::BitToBlob(bit, output_str);
112872 return output_str.GetString();
112873}
static void BitToBlob(bitstring_t bit, string_t &output_blob)
bit is expected to fit inside of output_blob (bit size = output_blob + 1)
Definition duckdb.cpp:112849

◆ BitString()

void duckdb::Bit::BitString ( const string_t & input,
idx_t len,
bitstring_t & result )
static

Creates a new bitstring of determined length.

112876 {
112877 char *res_buf = result.GetDataWriteable();
112878 const char *buf = input.GetData();
112879
112880 auto padding = ComputePadding(bit_length);
112881 res_buf[0] = padding;
112882 auto padding_len = UnsafeNumericCast<idx_t>(padding);
112883 for (idx_t i = 0; i < bit_length; i++) {
112884 if (i < bit_length - input.GetSize()) {
112885 Bit::SetBitInternal(result, i + padding_len, 0);
112886 } else {
112887 idx_t bit = buf[i - (bit_length - input.GetSize())] == '1' ? 1 : 0;
112888 Bit::SetBitInternal(result, i + padding_len, bit);
112889 }
112890 }
112891 Bit::Finalize(result);
112892}

◆ ExtendBitString()

void duckdb::Bit::ExtendBitString ( const bitstring_t & input,
idx_t bit_length,
bitstring_t & result )
static
112894 {
112895 uint8_t *res_buf = reinterpret_cast<uint8_t *>(result.GetDataWriteable());
112896
112897 auto padding = ComputePadding(bit_length);
112898 res_buf[0] = static_cast<uint8_t>(padding);
112899
112900 idx_t original_length = Bit::BitLength(input);
112901 D_ASSERT(bit_length >= original_length);
112902 idx_t shift = bit_length - original_length;
112903 for (idx_t i = 0; i < bit_length; i++) {
112904 if (i < shift) {
112905 Bit::SetBit(result, i, 0);
112906 } else {
112907 idx_t bit = Bit::GetBit(input, i - shift);
112908 Bit::SetBit(result, i, bit);
112909 }
112910 }
112911 Bit::Finalize(result);
112912}
static DUCKDB_API void SetBit(bitstring_t &bit_string, idx_t n, idx_t new_value)
Sets the nth bit in bit string to newvalue; the first (leftmost) bit is indexed 0.
Definition duckdb.cpp:112983
::uint8_t uint8_t

◆ SetEmptyBitString() [1/2]

void duckdb::Bit::SetEmptyBitString ( bitstring_t & target,
string_t & input )
static
112732 {
112733 char *res_buf = target.GetDataWriteable();
112734 const char *buf = input.GetData();
112735 memset(res_buf, 0, input.GetSize());
112736 res_buf[0] = buf[0];
112737 Bit::Finalize(target);
112738}

◆ SetEmptyBitString() [2/2]

void duckdb::Bit::SetEmptyBitString ( bitstring_t & target,
idx_t len )
static
112740 {
112741 char *res_buf = target.GetDataWriteable();
112742 memset(res_buf, 0, target.GetSize());
112743 res_buf[0] = ComputePadding(len);
112744 Bit::Finalize(target);
112745}

◆ ComputeBitstringLen()

idx_t duckdb::Bit::ComputeBitstringLen ( idx_t len)
static
112689 {
112690 idx_t result = len / 8;
112691 if (len % 8 != 0) {
112692 result++;
112693 }
112694 // additional first byte to store info on zero padding
112695 result++;
112696 return result;
112697}

◆ RightShift()

void duckdb::Bit::RightShift ( const bitstring_t & bit_string,
idx_t shift,
bitstring_t & result )
static
113003 {
113004 uint8_t *res_buf = reinterpret_cast<uint8_t *>(result.GetDataWriteable());
113005 const uint8_t *buf = reinterpret_cast<const uint8_t *>(bit_string.GetData());
113006
113007 res_buf[0] = buf[0];
113008 auto padding = GetBitPadding(result);
113009 for (idx_t i = 0; i < Bit::BitLength(result); i++) {
113010 if (i < shift) {
113011 Bit::SetBitInternal(result, i + padding, 0);
113012 } else {
113013 idx_t bit = Bit::GetBit(bit_string, i - shift);
113014 Bit::SetBitInternal(result, i + padding, bit);
113015 }
113016 }
113017 Bit::Finalize(result);
113018}

◆ LeftShift()

void duckdb::Bit::LeftShift ( const bitstring_t & bit_string,
idx_t shift,
bitstring_t & result )
static
113020 {
113021 uint8_t *res_buf = reinterpret_cast<uint8_t *>(result.GetDataWriteable());
113022 const uint8_t *buf = reinterpret_cast<const uint8_t *>(bit_string.GetData());
113023
113024 res_buf[0] = buf[0];
113025 auto padding = GetBitPadding(result);
113026 for (idx_t i = 0; i < Bit::BitLength(bit_string); i++) {
113027 if (i < (Bit::BitLength(bit_string) - shift)) {
113028 idx_t bit = Bit::GetBit(bit_string, shift + i);
113029 Bit::SetBitInternal(result, i + padding, bit);
113030 } else {
113031 Bit::SetBitInternal(result, i + padding, 0);
113032 }
113033 }
113034 Bit::Finalize(result);
113035}

◆ BitwiseAnd()

void duckdb::Bit::BitwiseAnd ( const bitstring_t & rhs,
const bitstring_t & lhs,
bitstring_t & result )
static
113037 {
113038 if (Bit::BitLength(lhs) != Bit::BitLength(rhs)) {
113039 throw InvalidInputException("Cannot AND bit strings of different sizes");
113040 }
113041
113042 uint8_t *buf = reinterpret_cast<uint8_t *>(result.GetDataWriteable());
113043 const uint8_t *r_buf = reinterpret_cast<const uint8_t *>(rhs.GetData());
113044 const uint8_t *l_buf = reinterpret_cast<const uint8_t *>(lhs.GetData());
113045
113046 buf[0] = l_buf[0];
113047 for (idx_t i = 1; i < lhs.GetSize(); i++) {
113048 buf[i] = l_buf[i] & r_buf[i];
113049 }
113050 Bit::Finalize(result);
113051}

◆ BitwiseOr()

void duckdb::Bit::BitwiseOr ( const bitstring_t & rhs,
const bitstring_t & lhs,
bitstring_t & result )
static
113053 {
113054 if (Bit::BitLength(lhs) != Bit::BitLength(rhs)) {
113055 throw InvalidInputException("Cannot OR bit strings of different sizes");
113056 }
113057
113058 uint8_t *buf = reinterpret_cast<uint8_t *>(result.GetDataWriteable());
113059 const uint8_t *r_buf = reinterpret_cast<const uint8_t *>(rhs.GetData());
113060 const uint8_t *l_buf = reinterpret_cast<const uint8_t *>(lhs.GetData());
113061
113062 buf[0] = l_buf[0];
113063 for (idx_t i = 1; i < lhs.GetSize(); i++) {
113064 buf[i] = l_buf[i] | r_buf[i];
113065 }
113066 Bit::Finalize(result);
113067}

◆ BitwiseXor()

void duckdb::Bit::BitwiseXor ( const bitstring_t & rhs,
const bitstring_t & lhs,
bitstring_t & result )
static
113069 {
113070 if (Bit::BitLength(lhs) != Bit::BitLength(rhs)) {
113071 throw InvalidInputException("Cannot XOR bit strings of different sizes");
113072 }
113073
113074 uint8_t *buf = reinterpret_cast<uint8_t *>(result.GetDataWriteable());
113075 const uint8_t *r_buf = reinterpret_cast<const uint8_t *>(rhs.GetData());
113076 const uint8_t *l_buf = reinterpret_cast<const uint8_t *>(lhs.GetData());
113077
113078 buf[0] = l_buf[0];
113079 for (idx_t i = 1; i < lhs.GetSize(); i++) {
113080 buf[i] = l_buf[i] ^ r_buf[i];
113081 }
113082 Bit::Finalize(result);
113083}

◆ BitwiseNot()

void duckdb::Bit::BitwiseNot ( const bitstring_t & rhs,
bitstring_t & result )
static
113085 {
113086 uint8_t *result_buf = reinterpret_cast<uint8_t *>(result.GetDataWriteable());
113087 const uint8_t *buf = reinterpret_cast<const uint8_t *>(input.GetData());
113088
113089 result_buf[0] = buf[0];
113090 for (idx_t i = 1; i < input.GetSize(); i++) {
113091 result_buf[i] = ~buf[i];
113092 }
113093 Bit::Finalize(result);
113094}

◆ Verify()

void duckdb::Bit::Verify ( const bitstring_t & input)
static
113096 {
113097#ifdef DEBUG
113098 // bit strings require all padding bits to be set to 1
113099 auto padding = GetBitPadding(input);
113100 for (idx_t i = 0; i < padding; i++) {
113101 D_ASSERT(Bit::GetBitInternal(input, i));
113102 }
113103 // verify bit respects the "normal" string_t rules (i.e. null padding for inlined strings, prefix matches)
113104 input.VerifyCharacters();
113105#endif
113106}

◆ Finalize()

void duckdb::Bit::Finalize ( bitstring_t & str)
staticprivate
112721 {
112722 // bit strings require all padding bits to be set to 1
112723 // this method sets all padding bits to 1
112724 auto padding = GetBitPadding(str);
112725 for (idx_t i = 0; i < idx_t(padding); i++) {
112726 Bit::SetBitInternal(str, i, 1);
112727 }
112728 str.Finalize();
112729 Bit::Verify(str);
112730}

◆ GetBitInternal()

idx_t duckdb::Bit::GetBitInternal ( bitstring_t bit_string,
idx_t n )
staticprivate
112975 {
112976 const char *buf = bit_string.GetData();
112977 auto idx = Bit::GetBitIndex(n);
112978 D_ASSERT(idx < bit_string.GetSize());
112979 auto byte = buf[idx] >> (7 - (n % 8));
112980 return (byte & 1 ? 1 : 0);
112981}

◆ SetBitInternal()

void duckdb::Bit::SetBitInternal ( bitstring_t & bit_string,
idx_t n,
idx_t new_value )
staticprivate
112988 {
112989 uint8_t *buf = reinterpret_cast<uint8_t *>(bit_string.GetDataWriteable());
112990
112991 auto idx = Bit::GetBitIndex(n);
112992 D_ASSERT(idx < bit_string.GetSize());
112993 auto shift_byte = UnsafeNumericCast<uint8_t>(1 << (7 - (n % 8)));
112994 if (new_value == 0) {
112995 shift_byte = ~shift_byte;
112996 buf[idx] &= shift_byte;
112997 } else {
112998 buf[idx] |= shift_byte;
112999 }
113000}

◆ GetBitIndex()

idx_t duckdb::Bit::GetBitIndex ( idx_t n)
staticprivate
112971 {
112972 return n / 8 + 1;
112973}

◆ GetFirstByte()

uint8_t duckdb::Bit::GetFirstByte ( const bitstring_t & str)
staticprivate
112714 {
112715 D_ASSERT(str.GetSize() > 1);
112716
112717 auto data = const_data_ptr_cast(str.GetData());
112718 return data[1] & ((1 << (8 - data[0])) - 1);
112719}

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