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::BitpackingState< T, T_S > Struct Template Reference
Collaboration diagram for duckdb::BitpackingState< T, T_S >:

Public Member Functions

void Reset ()
void CalculateFORStats ()
void CalculateDeltaStats ()
template<class T_INNER>
void SubtractFrameOfReference (T_INNER *buffer, T_INNER frame_of_reference)
template<class OP>
bool Flush ()
template<class OP = EmptyBitpackingWriter>
bool Update (T value, bool is_valid)

Public Attributes

T compression_buffer_internal [BITPACKING_METADATA_GROUP_SIZE+1]
T * compression_buffer
T_S delta_buffer [BITPACKING_METADATA_GROUP_SIZE]
bool compression_buffer_validity [BITPACKING_METADATA_GROUP_SIZE]
idx_t compression_buffer_idx
idx_t total_size
void * data_ptr
T minimum
T maximum
T min_max_diff
T_S minimum_delta
T_S maximum_delta
T_S min_max_delta_diff
T_S delta_offset
bool all_valid
bool all_invalid
bool has_valid
bool has_invalid
bool can_do_delta
bool can_do_for
BitpackingMode mode = BitpackingMode::AUTO

Constructor & Destructor Documentation

◆ BitpackingState()

template<class T, class T_S = typename MakeSigned<T>::type>
duckdb::BitpackingState< T, T_S >::BitpackingState ( )
inline
395030 : compression_buffer_idx(0), total_size(0), data_ptr(nullptr) {
395031 compression_buffer_internal[0] = T(0);
395032 compression_buffer = &compression_buffer_internal[1];
395033 Reset();
395034 }
Definition duckdb.cpp:395028

Member Function Documentation

◆ Reset()

template<class T, class T_S = typename MakeSigned<T>::type>
void duckdb::BitpackingState< T, T_S >::Reset ( )
inline
395068 {
395069 minimum = NumericLimits<T>::Maximum();
395070 minimum_delta = NumericLimits<T_S>::Maximum();
395071 maximum = NumericLimits<T>::Minimum();
395072 maximum_delta = NumericLimits<T_S>::Minimum();
395073 delta_offset = 0;
395074 all_valid = true;
395075 all_invalid = true;
395076 has_valid = false;
395077 has_invalid = false;
395078 can_do_delta = false;
395079 can_do_for = false;
395080 compression_buffer_idx = 0;
395081 min_max_diff = 0;
395082 min_max_delta_diff = 0;
395083 }

◆ CalculateFORStats()

template<class T, class T_S = typename MakeSigned<T>::type>
void duckdb::BitpackingState< T, T_S >::CalculateFORStats ( )
inline
395085 {
395086 can_do_for = TrySubtractOperator::Operation(maximum, minimum, min_max_diff);
395087 }

◆ CalculateDeltaStats()

template<class T, class T_S = typename MakeSigned<T>::type>
void duckdb::BitpackingState< T, T_S >::CalculateDeltaStats ( )
inline
395089 {
395090 // TODO: currently we dont support delta compression of values above NumericLimits<T_S>::Maximum(),
395091 // we could support this with some clever substract trickery?
395092 if (maximum > static_cast<T>(NumericLimits<T_S>::Maximum())) {
395093 return;
395094 }
395095
395096 // Don't delta encoding 1 value makes no sense
395097 if (compression_buffer_idx < 2) {
395098 return;
395099 }
395100
395101 // TODO: handle NULLS here?
395102 // Currently we cannot handle nulls because we would need an additional step of patching for this.
395103 // we could for example copy the last value on a null insert. This would help a bit, but not be optimal for
395104 // large deltas since theres suddenly a zero then. Ideally we would insert a value that leads to a delta within
395105 // the current domain of deltas however we dont know that domain here yet
395106 if (!all_valid) {
395107 return;
395108 }
395109
395110 // Note: since we dont allow any values over NumericLimits<T_S>::Maximum(), all subtractions for unsigned types
395111 // are guaranteed not to overflow
395112 bool can_do_all = true;
395114 T_S bogus;
395115 can_do_all = TrySubtractOperator::Operation(static_cast<T_S>(minimum), static_cast<T_S>(maximum), bogus) &&
395116 TrySubtractOperator::Operation(static_cast<T_S>(maximum), static_cast<T_S>(minimum), bogus);
395117 }
395118
395119 // Calculate delta's
395120 // compression_buffer pointer points one element ahead of the internal buffer making the use of signed index
395121 // integer (-1) possible
395122 D_ASSERT(compression_buffer_idx <= NumericLimits<int64_t>::Maximum());
395123 if (can_do_all) {
395124 for (int64_t i = 0; i < static_cast<int64_t>(compression_buffer_idx); i++) {
395125 delta_buffer[i] = static_cast<T_S>(compression_buffer[i]) - static_cast<T_S>(compression_buffer[i - 1]);
395126 }
395127 } else {
395128 for (int64_t i = 0; i < static_cast<int64_t>(compression_buffer_idx); i++) {
395129 auto success =
395130 TrySubtractOperator::Operation(static_cast<T_S>(compression_buffer[i]),
395131 static_cast<T_S>(compression_buffer[i - 1]), delta_buffer[i]);
395132 if (!success) {
395133 return;
395134 }
395135 }
395136 }
395137
395138 can_do_delta = true;
395139
395140 for (idx_t i = 1; i < compression_buffer_idx; i++) {
395141 maximum_delta = MaxValue<T_S>(maximum_delta, delta_buffer[i]);
395142 minimum_delta = MinValue<T_S>(minimum_delta, delta_buffer[i]);
395143 }
395144
395145 // Since we can set the first value arbitrarily, we want to pick one from the current domain, note that
395146 // we will store the original first value - this offset as the delta_offset to be able to decode this again.
395147 delta_buffer[0] = minimum_delta;
395148
395149 can_do_delta = can_do_delta && TrySubtractOperator::Operation(maximum_delta, minimum_delta, min_max_delta_diff);
395150 can_do_delta = can_do_delta && TrySubtractOperator::Operation(static_cast<T_S>(compression_buffer[0]),
395151 minimum_delta, delta_offset);
395152 }

◆ SubtractFrameOfReference()

template<class T, class T_S = typename MakeSigned<T>::type>
template<class T_INNER>
void duckdb::BitpackingState< T, T_S >::SubtractFrameOfReference ( T_INNER * buffer,
T_INNER frame_of_reference )
inline
395155 {
395156 static_assert(NumericLimits<T_INNER>::IsIntegral(), "Integral type required.");
395157
395158 using T_U = typename MakeUnsigned<T_INNER>::type;
395159
395160 for (idx_t i = 0; i < compression_buffer_idx; i++) {
395161 reinterpret_cast<T_U *>(buffer)[i] -= static_cast<T_U>(frame_of_reference);
395162 }
395163 }

◆ Flush()

template<class T, class T_S = typename MakeSigned<T>::type>
template<class OP>
bool duckdb::BitpackingState< T, T_S >::Flush ( )
inline

min_max_diff is uninitialized if can_do_for isn't true

395166 {
395167 if (compression_buffer_idx == 0) {
395168 return true;
395169 }
395170
395171 if ((all_invalid || maximum == minimum) && (mode == BitpackingMode::AUTO || mode == BitpackingMode::CONSTANT)) {
395172 OP::WriteConstant(maximum, compression_buffer_idx, data_ptr, all_invalid);
395173 total_size += sizeof(T) + sizeof(bitpacking_metadata_encoded_t);
395174 return true;
395175 }
395176
395177 CalculateFORStats();
395178 CalculateDeltaStats();
395179
395180 if (can_do_delta) {
395181 if (maximum_delta == minimum_delta && mode != BitpackingMode::FOR && mode != BitpackingMode::DELTA_FOR) {
395182 // FOR needs to be T (considering hugeint is bigger than idx_t)
395183 T frame_of_reference = compression_buffer[0];
395184
395185 OP::WriteConstantDelta(maximum_delta, static_cast<T>(frame_of_reference), compression_buffer_idx,
395186 compression_buffer, compression_buffer_validity, data_ptr);
395187 total_size += sizeof(T) + sizeof(T) + sizeof(bitpacking_metadata_encoded_t);
395188 return true;
395189 }
395190
395191 // Check if delta has benefit
395193 BitpackingPrimitives::MinimumBitWidth<T, false>(static_cast<T>(min_max_delta_diff));
395195
395198
395199 if (!prefer_for && mode != BitpackingMode::FOR) {
395200 SubtractFrameOfReference(delta_buffer, minimum_delta);
395201
395202 OP::WriteDeltaFor(reinterpret_cast<T *>(delta_buffer), compression_buffer_validity,
395203 delta_required_bitwidth, static_cast<T>(minimum_delta), delta_offset,
395204 compression_buffer, compression_buffer_idx, data_ptr);
395205
395206 // FOR (frame of reference).
395207 total_size += sizeof(T);
395208 // Aligned bitpacking width.
395209 total_size += AlignValue(sizeof(bitpacking_width_t));
395210 // Delta offset.
395211 total_size += sizeof(T);
395212 // Compressed data size.
395213 total_size += BitpackingPrimitives::GetRequiredSize(compression_buffer_idx, delta_required_bitwidth);
395214
395215 return true;
395216 }
395217 }
395218
395219 if (can_do_for) {
395221 SubtractFrameOfReference(compression_buffer, minimum);
395222 OP::WriteFor(compression_buffer, compression_buffer_validity, width, minimum, compression_buffer_idx,
395223 data_ptr);
395224
395225 total_size += BitpackingPrimitives::GetRequiredSize(compression_buffer_idx, width);
395226 total_size += sizeof(T); // FOR value
395227 total_size += AlignValue(sizeof(bitpacking_width_t));
395228
395229 return true;
395230 }
395231
395232 return false;
395233 }
static T AlignValue(T n)
Align value (ceiling) (not for pointer types).
Definition duckdb.hpp:2126
Here is the call graph for this function:

◆ Update()

template<class T, class T_S = typename MakeSigned<T>::type>
template<class OP = EmptyBitpackingWriter>
bool duckdb::BitpackingState< T, T_S >::Update ( T value,
bool is_valid )
inline
395236 {
395237 compression_buffer_validity[compression_buffer_idx] = is_valid;
395238 has_valid = has_valid || is_valid;
395239 has_invalid = has_invalid || !is_valid;
395240 all_valid = all_valid && is_valid;
395241 all_invalid = all_invalid && !is_valid;
395242
395243 if (is_valid) {
395244 compression_buffer[compression_buffer_idx] = value;
395245 minimum = MinValue<T>(minimum, value);
395246 maximum = MaxValue<T>(maximum, value);
395247 }
395248
395249 compression_buffer_idx++;
395250
395251 if (compression_buffer_idx == BITPACKING_METADATA_GROUP_SIZE) {
395252 bool success = Flush<OP>();
395253 Reset();
395254 return success;
395255 }
395256 return true;
395257 }
bool Flush()
Definition duckdb.cpp:395166

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