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::BitReader Struct Reference

Public Member Functions

void SetStream (uint8_t *input)
uint8_t BitIndex () const
uint64_t ByteIndex () const
uint8_t InnerReadByte (const uint8_t &offset)
uint8_t InnerRead (const uint8_t &size, const uint8_t &offset)
template<class T, uint8_t BYTES>
T ReadBytes (const uint8_t &remainder)
template<class T>
T ReadBytes (const uint8_t &bytes, const uint8_t &remainder)
template<class T, uint8_t SIZE>
T ReadValue ()
template<class T>
T ReadValue (const uint8_t &size)

Public Attributes

uint8_t * input
uint32_t index

Static Private Attributes

static constexpr uint8_t MASKS []
 Align the masks to the right.
static constexpr uint8_t REMAINDER_MASKS []

Detailed Description

Every byte read touches at most 2 bytes (1 if it's perfectly aligned) Within a byte we need to mask off the bits that we're interested in

Constructor & Destructor Documentation

◆ BitReader()

duckdb::BitReader::BitReader ( )
inline
396334 : input(nullptr), index(0) {
396335 }

Member Function Documentation

◆ SetStream()

void duckdb::BitReader::SetStream ( uint8_t * input)
inline
396340 {
396341 this->input = input;
396342 index = 0;
396343 }

◆ BitIndex()

uint8_t duckdb::BitReader::BitIndex ( ) const
inline
396345 {
396346 return (index & 7);
396347 }

◆ ByteIndex()

uint64_t duckdb::BitReader::ByteIndex ( ) const
inline
396348 {
396349 return (index >> 3);
396350 }

◆ InnerReadByte()

uint8_t duckdb::BitReader::InnerReadByte ( const uint8_t & offset)
inline
396352 {
396353 uint8_t result = static_cast<uint8_t>(input[ByteIndex() + offset] << BitIndex()) |
396354 ((input[ByteIndex() + offset + 1] & REMAINDER_MASKS[8 + BitIndex()]) >> (8 - BitIndex()));
396355 return result;
396356 }
::uint8_t uint8_t

◆ InnerRead()

uint8_t duckdb::BitReader::InnerRead ( const uint8_t & size,
const uint8_t & offset )
inline

index: 4 size: 7 input: [12345678][12345678] result: [-AAAA BBB]

Result contains 4 bits from the first byte (making up the most significant bits) And 3 bits from the second byte (the least significant bits)

396365 {
396366 const uint8_t right_shift = 8 - size;
396367 const uint8_t bit_remainder = (8 - ((size + BitIndex()) - 8)) & 7;
396368 // The least significant bits are positioned at the far right of the byte
396369
396370 // Create a mask given the size and index
396371 // Take the first byte
396372 // Left-shift it by index, to line up the bits we're interested in with the mask
396373 // Get the mask for the given size
396374 // Bit-wise AND the byte and the mask together
396375 // Right-shift this result (the most significant bits)
396376
396377 // Sometimes we will need to read from the second byte
396378 // But to make this branchless, we will perform what is basically a no-op if this condition is not true
396379 // SPILL = (index + size >= 8)
396380 //
396381 // If SPILL is true:
396382 // The REMAINDER_MASKS gives us the mask for the bits we're interested in
396383 // We bit-wise AND these together (no need to shift anything because the index is essentially zero for this new
396384 // byte) And we then right-shift these bits in place (to the right of the previous bits)
396385 const bool spill_to_next_byte = (size + BitIndex() >= 8);
396386 uint8_t result =
396387 ((input[ByteIndex() + offset] << BitIndex()) & MASKS[size]) >> right_shift |
396388 ((input[ByteIndex() + offset + spill_to_next_byte] & REMAINDER_MASKS[size + BitIndex()]) >> bit_remainder);
396389 return result;
396390 }
GOpaque< Size > size(const GMat &src)
static constexpr uint8_t MASKS[]
Align the masks to the right.
Definition duckdb.cpp:396300

◆ ReadBytes() [1/2]

template<class T, uint8_t BYTES>
T duckdb::BitReader::ReadBytes ( const uint8_t & remainder)
inline
396393 {
396394 T result = 0;
396395 if (BYTES > 0) {
396396 result = UnsafeNumericCast<T>(result << 8 | InnerReadByte(0));
396397 }
396398 if (BYTES > 1) {
396399 result = UnsafeNumericCast<T>(result << 8 | InnerReadByte(1));
396400 }
396401 if (BYTES > 2) {
396402 result = UnsafeNumericCast<T>(result << 8 | InnerReadByte(2));
396403 }
396404 if (BYTES > 3) {
396405 result = UnsafeNumericCast<T>(result << 8 | InnerReadByte(3));
396406 }
396407 if (BYTES > 4) {
396408 result = UnsafeNumericCast<T>(result << 8 | InnerReadByte(4));
396409 }
396410 if (BYTES > 5) {
396411 result = UnsafeNumericCast<T>(result << 8 | InnerReadByte(5));
396412 }
396413 if (BYTES > 6) {
396414 result = UnsafeNumericCast<T>(result << 8 | InnerReadByte(6));
396415 }
396416 if (BYTES > 7) {
396417 result = UnsafeNumericCast<T>(result << 8 | InnerReadByte(7));
396418 }
396419 result = UnsafeNumericCast<T>(result << remainder | InnerRead(remainder, BYTES));
396420 index += (BYTES << 3) + remainder;
396421 return result;
396422 }
uint8_t InnerRead(const uint8_t &size, const uint8_t &offset)
Definition duckdb.cpp:396365

◆ ReadBytes() [2/2]

template<class T>
T duckdb::BitReader::ReadBytes ( const uint8_t & bytes,
const uint8_t & remainder )
inline
396425 {
396426 T result = 0;
396427 for (uint8_t i = 0; i < bytes; i++) {
396428 result = result << 8 | InnerReadByte(i);
396429 }
396430 result = result << remainder | InnerRead(remainder, bytes);
396431 index += static_cast<uint32_t>(bytes << 3) + remainder;
396432 return result;
396433 }
::uint32_t uint32_t

◆ ReadValue() [1/2]

template<class T, uint8_t SIZE>
T duckdb::BitReader::ReadValue ( )
inline
396436 {
396437 constexpr uint8_t BYTES = (SIZE >> 3);
396438 constexpr uint8_t REMAINDER = (SIZE & 7);
396439 return ReadBytes<T, BYTES>(REMAINDER);
396440 }

◆ ReadValue() [2/2]

template<class T>
T duckdb::BitReader::ReadValue ( const uint8_t & size)
inline
396443 {
396444 const uint8_t bytes = size >> 3; // divide by 8;
396445 const uint8_t remainder = size & 7;
396446 return ReadBytes<T>(bytes, remainder);
396447 }

Member Data Documentation

◆ MASKS

uint8_t duckdb::BitReader::MASKS
staticconstexprprivate
Initial value:
= {
0,
128,
192,
224,
240,
248,
252,
254,
255,
254,
252,
248,
240,
224,
192,
128,
}

Align the masks to the right.

396300 {
396301 0, // 0b00000000,
396302 128, // 0b10000000,
396303 192, // 0b11000000,
396304 224, // 0b11100000,
396305 240, // 0b11110000,
396306 248, // 0b11111000,
396307 252, // 0b11111100,
396308 254, // 0b11111110,
396309 255, // 0b11111111,
396310 // These later masks are for the cases where index + SIZE exceeds 8
396311 254, // 0b11111110,
396312 252, // 0b11111100,
396313 248, // 0b11111000,
396314 240, // 0b11110000,
396315 224, // 0b11100000,
396316 192, // 0b11000000,
396317 128, // 0b10000000,
396318 };

◆ REMAINDER_MASKS

uint8_t duckdb::BitReader::REMAINDER_MASKS
staticconstexprprivate
Initial value:
= {
0, 0, 0, 0, 0, 0, 0, 0, 0,
128,
192,
224,
240,
248,
252,
254,
255,
}
396320 {
396321 0, 0, 0, 0, 0, 0, 0, 0, 0,
396322 128, // 0b10000000,
396323 192, // 0b11000000,
396324 224, // 0b11100000,
396325 240, // 0b11110000,
396326 248, // 0b11111000,
396327 252, // 0b11111100,
396328 254, // 0b11111110,
396329 255, // 0b11111111,
396330 };

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