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::OutputBitStream< EMPTY > Class Template Reference

Public Member Functions

idx_t BytesWritten () const
idx_t BitsWritten () const
void Flush ()
void SetStream (uint8_t *output_stream)
uint64_t * Stream ()
idx_t BitSize () const
template<class T>
void WriteRemainder (T value, uint8_t i)
template<class T, uint8_t VALUE_SIZE>
void WriteValue (T value)
template<class T>
void WriteValue (T value, const uint8_t &value_size)

Static Public Attributes

static constexpr uint8_t INTERNAL_TYPE_BITSIZE = sizeof(INTERNAL_TYPE) * 8

Private Types

using INTERNAL_TYPE = uint8_t

Private Member Functions

void WriteBit (bool value)
bool FitsInCurrent (uint8_t bits)
INTERNAL_TYPE GetMask () const
INTERNAL_TYPE & GetCurrentByte ()
void WriteToStream (INTERNAL_TYPE value)
 Write a value of type INTERNAL_TYPE directly to the stream.
void WriteToStream ()
void DecreaseFreeBits (uint8_t value=1)
void WriteInCurrent (INTERNAL_TYPE value, uint8_t value_size)
template<uint8_t VALUE_SIZE = INTERNAL_TYPE_BITSIZE>
void WriteInCurrent (INTERNAL_TYPE value)

Private Attributes

uint8_t * stream
INTERNAL_TYPE current
 The stream we're writing our output to.
uint8_t free_bits
 The current value we're writing into (zero-initialized).
idx_t stream_index
 How many bits are still unwritten in 'current'.
idx_t bits_written
 Index used to keep track of which index we're at in the stream.

Friends

class BitStreamWriter
class EmptyWriter

Constructor & Destructor Documentation

◆ OutputBitStream()

template<bool EMPTY>
duckdb::OutputBitStream< EMPTY >::OutputBitStream ( )
inline
396823 : stream(nullptr), current(0), free_bits(INTERNAL_TYPE_BITSIZE), stream_index(0), bits_written(0) {
396824 }
idx_t stream_index
How many bits are still unwritten in 'current'.
Definition duckdb.cpp:397004
uint8_t free_bits
The current value we're writing into (zero-initialized).
Definition duckdb.cpp:397003
INTERNAL_TYPE current
The stream we're writing our output to.
Definition duckdb.cpp:397002
idx_t bits_written
Index used to keep track of which index we're at in the stream.
Definition duckdb.cpp:397006

Member Function Documentation

◆ BytesWritten()

template<bool EMPTY>
idx_t duckdb::OutputBitStream< EMPTY >::BytesWritten ( ) const
inline
396829 {
396830 return (bits_written >> 3) + ((bits_written & 7) != 0);
396831 }

◆ BitsWritten()

template<bool EMPTY>
idx_t duckdb::OutputBitStream< EMPTY >::BitsWritten ( ) const
inline
396833 {
396834 return bits_written;
396835 }

◆ Flush()

template<bool EMPTY>
void duckdb::OutputBitStream< EMPTY >::Flush ( )
inline
396837 {
396838 if (free_bits == INTERNAL_TYPE_BITSIZE) {
396839 // the bit buffer is empty, nothing to write
396840 return;
396841 }
396842 WriteToStream();
396843 }
void WriteToStream(INTERNAL_TYPE value)
Write a value of type INTERNAL_TYPE directly to the stream.
Definition duckdb.cpp:396969

◆ SetStream()

template<bool EMPTY>
void duckdb::OutputBitStream< EMPTY >::SetStream ( uint8_t * output_stream)
inline
396845 {
396846 stream = output_stream;
396847 stream_index = 0;
396848 bits_written = 0;
396849 free_bits = INTERNAL_TYPE_BITSIZE;
396850 current = 0;
396851 }
Definition duckdb.cpp:396816

◆ Stream()

template<bool EMPTY>
uint64_t * duckdb::OutputBitStream< EMPTY >::Stream ( )
inline
396853 {
396854 return (uint64_t *)stream;
396855 }

◆ BitSize()

template<bool EMPTY>
idx_t duckdb::OutputBitStream< EMPTY >::BitSize ( ) const
inline
396857 {
396858 return (stream_index * INTERNAL_TYPE_BITSIZE) + (INTERNAL_TYPE_BITSIZE - free_bits);
396859 }

◆ WriteRemainder()

template<bool EMPTY>
template<class T>
void duckdb::OutputBitStream< EMPTY >::WriteRemainder ( T value,
uint8_t i )
inline
396862 {
396863 if (sizeof(T) * 8 > 32) {
396864 if (i == 64) {
396865 WriteToStream(((uint64_t)value >> 56) & 0xFF);
396866 }
396867 if (i > 55) {
396868 WriteToStream(((uint64_t)value >> 48) & 0xFF);
396869 }
396870 if (i > 47) {
396871 WriteToStream(((uint64_t)value >> 40) & 0xFF);
396872 }
396873 if (i > 39) {
396874 WriteToStream(((uint64_t)value >> 32) & 0xFF);
396875 }
396876 }
396877 if (i > 31) {
396878 WriteToStream((value >> 24) & 0xFF);
396879 }
396880 if (i > 23) {
396881 WriteToStream((value >> 16) & 0xFF);
396882 }
396883 if (i > 15) {
396884 WriteToStream((value >> 8) & 0xFF);
396885 }
396886 if (i > 7) {
396888 }
396889 }

◆ WriteValue() [1/2]

template<bool EMPTY>
template<class T, uint8_t VALUE_SIZE>
void duckdb::OutputBitStream< EMPTY >::WriteValue ( T value)
inline

If we can write the entire value in one go

396892 {
396894 if (EMPTY) {
396895 return;
396896 }
396897 if (FitsInCurrent(VALUE_SIZE)) {
396899 WriteInCurrent<VALUE_SIZE>((INTERNAL_TYPE)value);
396900 return;
396901 }
396902 auto i = VALUE_SIZE - free_bits;
396903 const uint8_t queue = i & 7;
396904
396905 if (free_bits != 0) {
396906 // Reset the number of free bits
396907 WriteInCurrent(value >> i, free_bits);
396908 }
396909 if (queue != 0) {
396910 // We dont fill the entire 'current' buffer,
396911 // so we can write these to 'current' first without flushing to the stream
396912 // And then write the remaining bytes directly to the stream
396913 i -= queue;
396914 WriteInCurrent((INTERNAL_TYPE)value, queue);
396915 value >>= queue;
396916 }
396917 WriteRemainder<T>(value, i);
396918 }

◆ WriteValue() [2/2]

template<bool EMPTY>
template<class T>
void duckdb::OutputBitStream< EMPTY >::WriteValue ( T value,
const uint8_t & value_size )
inline

If we can write the entire value in one go

396921 {
396923 if (EMPTY) {
396924 return;
396925 }
396926 if (FitsInCurrent(value_size)) {
396928 WriteInCurrent((INTERNAL_TYPE)value, value_size);
396929 return;
396930 }
396931 auto i = value_size - free_bits;
396932 const uint8_t queue = i & 7;
396933
396934 if (free_bits != 0) {
396935 // Reset the number of free bits
396936 WriteInCurrent(value >> i, free_bits);
396937 }
396938 if (queue != 0) {
396939 // We dont fill the entire 'current' buffer,
396940 // so we can write these to 'current' first without flushing to the stream
396941 // And then write the remaining bytes directly to the stream
396942 i -= queue;
396943 WriteInCurrent((INTERNAL_TYPE)value, queue);
396944 value >>= queue;
396945 }
396946 WriteRemainder<T>(value, i);
396947 }

◆ WriteBit()

template<bool EMPTY>
void duckdb::OutputBitStream< EMPTY >::WriteBit ( bool value)
inlineprivate
396950 {
396951 auto &byte = GetCurrentByte();
396952 if (value) {
396953 byte = byte | GetMask();
396954 }
396955 DecreaseFreeBits();
396956 }

◆ FitsInCurrent()

template<bool EMPTY>
bool duckdb::OutputBitStream< EMPTY >::FitsInCurrent ( uint8_t bits)
inlineprivate
396958 {
396959 return free_bits >= bits;
396960 }

◆ GetMask()

template<bool EMPTY>
INTERNAL_TYPE duckdb::OutputBitStream< EMPTY >::GetMask ( ) const
inlineprivate
396961 {
396962 return (INTERNAL_TYPE)1 << free_bits;
396963 }

◆ GetCurrentByte()

template<bool EMPTY>
INTERNAL_TYPE & duckdb::OutputBitStream< EMPTY >::GetCurrentByte ( )
inlineprivate
396965 {
396966 return current;
396967 }

◆ WriteToStream() [1/2]

template<bool EMPTY>
void duckdb::OutputBitStream< EMPTY >::WriteToStream ( INTERNAL_TYPE value)
inlineprivate

Write a value of type INTERNAL_TYPE directly to the stream.

396969 {
396970 stream[stream_index++] = value;
396971 }

◆ WriteToStream() [2/2]

template<bool EMPTY>
void duckdb::OutputBitStream< EMPTY >::WriteToStream ( )
inlineprivate
396972 {
396973 stream[stream_index++] = current;
396974 current = 0;
396975 free_bits = INTERNAL_TYPE_BITSIZE;
396976 }

◆ DecreaseFreeBits()

template<bool EMPTY>
void duckdb::OutputBitStream< EMPTY >::DecreaseFreeBits ( uint8_t value = 1)
inlineprivate
396977 {
396979 free_bits -= value;
396980 if (free_bits == 0) {
396981 WriteToStream();
396982 }
396983 }

◆ WriteInCurrent() [1/2]

template<bool EMPTY>
void duckdb::OutputBitStream< EMPTY >::WriteInCurrent ( INTERNAL_TYPE value,
uint8_t value_size )
inlineprivate
396984 {
396985 D_ASSERT(INTERNAL_TYPE_BITSIZE >= value_size);
396986 const auto shift_amount = free_bits - value_size;
396988 DecreaseFreeBits(value_size);
396989 }

◆ WriteInCurrent() [2/2]

template<bool EMPTY>
template<uint8_t VALUE_SIZE = INTERNAL_TYPE_BITSIZE>
void duckdb::OutputBitStream< EMPTY >::WriteInCurrent ( INTERNAL_TYPE value)
inlineprivate
396992 {
396993 D_ASSERT(INTERNAL_TYPE_BITSIZE >= VALUE_SIZE);
396994 const auto shift_amount = free_bits - VALUE_SIZE;
396996 DecreaseFreeBits(VALUE_SIZE);
396997 }

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