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::AlpRDCompressionState< T > Struct Template Reference
Inheritance diagram for duckdb::AlpRDCompressionState< T >:
Collaboration diagram for duckdb::AlpRDCompressionState< T >:

Public Types

using EXACT_TYPE = typename FloatingToExact<T>::TYPE

Public Member Functions

 AlpRDCompressionState (ColumnDataCheckpointData &checkpoint_data, AlpRDAnalyzeState< T > *analyze_state)
idx_t UsedSpace () const
bool HasEnoughSpace (idx_t vector_size)
void ResetVector ()
void CreateEmptySegment ()
void CompressVector ()
void FlushCompressedVector ()
void FlushUncompressedVector ()
 Uncompressed mode.
void FlushSegment ()
void Finalize ()
void Append (UnifiedVectorFormat &vdata, idx_t count)
Public Member Functions inherited from duckdb::CompressionState
 CompressionState (const CompressionInfo &info)
template<class TARGET>
TARGET & Cast ()
template<class TARGET>
const TARGET & Cast () const

Public Attributes

ColumnDataCheckpointData & checkpoint_data
const CompressionFunction & function
unique_ptr< ColumnSegment > current_segment
BufferHandle handle
idx_t vector_idx = 0
idx_t nulls_idx = 0
idx_t vectors_flushed = 0
idx_t data_bytes_used = 0
data_ptr_t data_ptr
data_ptr_t metadata_ptr
uint32_t actual_dictionary_size_bytes
uint32_t next_vector_byte_index_start
EXACT_TYPE input_vector [AlpRDConstants::ALP_VECTOR_SIZE]
uint16_t vector_null_positions [AlpRDConstants::ALP_VECTOR_SIZE]
alp::AlpRDCompressionData< T, false > compression_data
Public Attributes inherited from duckdb::CompressionState
CompressionInfo info

Constructor & Destructor Documentation

◆ AlpRDCompressionState()

template<class T>
duckdb::AlpRDCompressionState< T >::AlpRDCompressionState ( ColumnDataCheckpointData & checkpoint_data,
AlpRDAnalyzeState< T > * analyze_state )
inline

State variables from the analyze step that are needed for compression

394333 : CompressionState(analyze_state->info), checkpoint_data(checkpoint_data),
394334 function(checkpoint_data.GetCompressionFunction(CompressionType::COMPRESSION_ALPRD)) {
394336 compression_data.left_parts_dict_map = std::move(analyze_state->compression_data.left_parts_dict_map);
394337 compression_data.left_bit_width = analyze_state->compression_data.left_bit_width;
394338 compression_data.right_bit_width = analyze_state->compression_data.right_bit_width;
394339 compression_data.actual_dictionary_size = analyze_state->compression_data.actual_dictionary_size;
394340 actual_dictionary_size_bytes =
394341 compression_data.actual_dictionary_size * AlpRDConstants::DICTIONARY_ELEMENT_SIZE;
394342 next_vector_byte_index_start = AlpRDConstants::HEADER_SIZE + actual_dictionary_size_bytes;
394343 memcpy((void *)compression_data.left_parts_dict, (void *)analyze_state->compression_data.left_parts_dict,
394344 actual_dictionary_size_bytes);
394345 CreateEmptySegment();
394346 }
Definition duckdb.cpp:394328

Member Function Documentation

◆ UsedSpace()

template<class T>
idx_t duckdb::AlpRDCompressionState< T >::UsedSpace ( ) const
inline

[Pointer to metadata + right bitwidth] + Dictionary Size + Bytes already used in the segment

394370 {
394372 return AlpRDConstants::HEADER_SIZE + actual_dictionary_size_bytes + data_bytes_used;
394373 }
Here is the caller graph for this function:

◆ HasEnoughSpace()

template<class T>
bool duckdb::AlpRDCompressionState< T >::HasEnoughSpace ( idx_t vector_size)
inline

If [start of block + used space + required space] is more than whats left (current position of metadata pointer - the size of a new metadata pointer)

394375 {
394378 if ((handle.Ptr() + AlignValue(UsedSpace() + vector_size)) >=
394379 (metadata_ptr - AlpRDConstants::METADATA_POINTER_SIZE)) {
394380 return false;
394381 }
394382 return true;
394383 }
idx_t UsedSpace() const
Definition duckdb.cpp:394370
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ResetVector()

template<class T>
void duckdb::AlpRDCompressionState< T >::ResetVector ( )
inline
394385 {
394386 compression_data.Reset();
394387 }

◆ CreateEmptySegment()

template<class T>
void duckdb::AlpRDCompressionState< T >::CreateEmptySegment ( )
inline
394389 {
394390 auto &db = checkpoint_data.GetDatabase();
394391 auto &type = checkpoint_data.GetType();
394392
394393 auto compressed_segment =
394394 ColumnSegment::CreateTransientSegment(db, function, type, info.GetBlockSize(), info.GetBlockManager());
394395 current_segment = std::move(compressed_segment);
394396
394398 handle = buffer_manager.Pin(current_segment->block);
394399
394400 // The pointer to the start of the compressed data.
394401 data_ptr = handle.Ptr() + current_segment->GetBlockOffset() + AlpRDConstants::HEADER_SIZE +
394402 actual_dictionary_size_bytes;
394403 // The pointer to the start of the metadata.
394404 metadata_ptr = handle.Ptr() + current_segment->GetBlockOffset() + info.GetBlockSize();
394405 next_vector_byte_index_start = AlpRDConstants::HEADER_SIZE + actual_dictionary_size_bytes;
394406 }

◆ CompressVector()

template<class T>
void duckdb::AlpRDCompressionState< T >::CompressVector ( )
inline

Check if the compressed vector fits on current segment

At least there is one valid value in the vector

394408 {
394409 if (nulls_idx) {
394410 alp::AlpUtils::FindAndReplaceNullsInVector<EXACT_TYPE>(input_vector, vector_null_positions, vector_idx,
394411 nulls_idx);
394412 }
394413 alp::AlpRDCompression<T, false>::Compress(input_vector, vector_idx, compression_data);
394414
394415 const idx_t uncompressed_size = AlpConstants::EXCEPTIONS_COUNT_SIZE + sizeof(EXACT_TYPE) * vector_idx;
394416 const idx_t compressed_size = compression_data.RequiredSpace();
394417
394418 const auto storage_version = checkpoint_data.GetStorageManager().GetStorageVersion();
394420
394422
394424 if (!HasEnoughSpace(vector_size)) {
394425 FlushSegment();
394426 CreateEmptySegment();
394427 }
394428 if (nulls_idx) {
394429 current_segment->stats.statistics.SetHasNullFast();
394430 }
394431 if (vector_idx != nulls_idx) {
394432 current_segment->stats.statistics.SetHasNoNullFast();
394433 for (idx_t i = 0; i < vector_idx; i++) {
394435 current_segment->stats.statistics.UpdateNumericStats<T>(floating_point_value);
394436 }
394437 }
394438 current_segment->count += vector_idx;
394439
394440 if (should_compress) {
394441 FlushCompressedVector();
394442 } else {
394444 }
394445 }
void FlushSegment()
Definition duckdb.cpp:394507
bool HasEnoughSpace(idx_t vector_size)
Definition duckdb.cpp:394375
void FlushUncompressedVector()
Uncompressed mode.
Definition duckdb.cpp:394484
static void Compress(const EXACT_TYPE *input_vector, idx_t n_values, CompressionData &compression_data)
Definition duckdb.cpp:394082
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FlushCompressedVector()

template<class T>
void duckdb::AlpRDCompressionState< T >::FlushCompressedVector ( )
inline
394448 {
394449 Store<uint16_t>(compression_data.exceptions_count, data_ptr);
394451
394452 memcpy((void *)data_ptr, (void *)compression_data.left_parts_encoded, compression_data.left_bit_packed_size);
394453 data_ptr += compression_data.left_bit_packed_size;
394454
394455 memcpy((void *)data_ptr, (void *)compression_data.right_parts_encoded, compression_data.right_bit_packed_size);
394456 data_ptr += compression_data.right_bit_packed_size;
394457
394458 if (compression_data.exceptions_count > 0) {
394459 memcpy((void *)data_ptr, (void *)compression_data.exceptions,
394460 AlpRDConstants::EXCEPTION_SIZE * compression_data.exceptions_count);
394461 data_ptr += AlpRDConstants::EXCEPTION_SIZE * compression_data.exceptions_count;
394462 memcpy((void *)data_ptr, (void *)compression_data.exceptions_positions,
394463 AlpRDConstants::EXCEPTION_POSITION_SIZE * compression_data.exceptions_count);
394464 data_ptr += AlpRDConstants::EXCEPTION_POSITION_SIZE * compression_data.exceptions_count;
394465 }
394466
394467 data_bytes_used += compression_data.left_bit_packed_size + compression_data.right_bit_packed_size +
394468 (compression_data.exceptions_count *
394471
394472 // Write pointer to the vector data (metadata)
394474 Store<uint32_t>(next_vector_byte_index_start, metadata_ptr);
394475 next_vector_byte_index_start = NumericCast<uint32_t>(UsedSpace());
394476
394477 vectors_flushed++;
394478 vector_idx = 0;
394479 nulls_idx = 0;
394480 ResetVector();
394481 }

◆ FlushUncompressedVector()

template<class T>
void duckdb::AlpRDCompressionState< T >::FlushUncompressedVector ( )
inline

Uncompressed mode.

394484 {
394485 // Store a sentinel value, signaling the coming data is stored uncompressed.
394487 Store<uint16_t>(sentinel, data_ptr);
394489
394490 // Store uncompressed data
394491 memcpy(data_ptr, input_vector, sizeof(EXACT_TYPE) * vector_idx);
394492 data_ptr += sizeof(EXACT_TYPE) * vector_idx;
394493
394494 data_bytes_used += AlpConstants::EXCEPTIONS_COUNT_SIZE + (sizeof(EXACT_TYPE) * vector_idx);
394495
394496 // Write pointer to the vector data (metadata)
394498 Store<uint32_t>(next_vector_byte_index_start, metadata_ptr);
394499 next_vector_byte_index_start = NumericCast<uint32_t>(UsedSpace());
394500
394501 vectors_flushed++;
394502 vector_idx = 0;
394503 nulls_idx = 0;
394504 ResetVector();
394505 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FlushSegment()

template<class T>
void duckdb::AlpRDCompressionState< T >::FlushSegment ( )
inline

We compact the block if the space used is less than a threshold

394507 {
394508 auto &checkpoint_state = checkpoint_data.GetCheckpointState();
394509 auto dataptr = handle.Ptr();
394510
394512
394513 // Verify that the metadata_ptr is not smaller than the space used by the data
394514 D_ASSERT(dataptr + metadata_offset <= metadata_ptr);
394515
394516 auto bytes_used_by_metadata = UnsafeNumericCast<idx_t>(dataptr + info.GetBlockSize() - metadata_ptr);
394517
394518 // Initially the total segment size is the size of the block
394519 auto total_segment_size = info.GetBlockSize();
394520
394522 const auto used_space_percentage =
394523 static_cast<float>(metadata_offset + bytes_used_by_metadata) / static_cast<float>(total_segment_size);
394525#ifdef DEBUG
394528 memcpy((void *)&verify_bytes, metadata_ptr, 4);
394529#endif
394531#ifdef DEBUG
394534#endif
394536 }
394537
394538 // Store the offset to the end of metadata (to be used as a backwards pointer in decoding)
394541
394542 // Store the right bw for the segment
394543 Store<uint8_t>(compression_data.right_bit_width, dataptr);
394545
394546 // Store the left bw for the segment
394547 Store<uint8_t>(compression_data.left_bit_width, dataptr);
394549
394550 // Store the actual number of elements on the dictionary of the segment
394551 Store<uint8_t>(compression_data.actual_dictionary_size, dataptr);
394553
394554 // Store the Dictionary
394555 memcpy((void *)dataptr, (void *)compression_data.left_parts_dict, actual_dictionary_size_bytes);
394556
394558 data_bytes_used = 0;
394559 vectors_flushed = 0;
394560 }
static T AlignValue(T n)
Align value (ceiling) (not for pointer types).
Definition duckdb.hpp:2126
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Finalize()

template<class T>
void duckdb::AlpRDCompressionState< T >::Finalize ( )
inline
394562 {
394563 if (vector_idx != 0) {
394564 CompressVector();
394565 }
394566 FlushSegment();
394567 current_segment.reset();
394568 }
void CompressVector()
Definition duckdb.cpp:394408

◆ Append()

template<class T>
void duckdb::AlpRDCompressionState< T >::Append ( UnifiedVectorFormat & vdata,
idx_t count )
inline

We optimize a loop when there are no null

We resolve null values with a predicated comparison

394570 {
394573 idx_t offset_in_data = 0;
394574 while (values_left_in_data > 0) {
394575 // We calculate until which value in data we must go to fill the input_vector
394576 // to avoid checking if input_vector is filled in each iteration
394579 if (vdata.validity.AllValid()) {
394580 for (idx_t i = 0; i < values_to_fill_alp_input; i++) {
394581 auto idx = vdata.sel->get_index(offset_in_data + i);
394583 input_vector[vector_idx + i] = value;
394584 }
394585 } else {
394586 for (idx_t i = 0; i < values_to_fill_alp_input; i++) {
394587 auto idx = vdata.sel->get_index(offset_in_data + i);
394589 bool is_null = !vdata.validity.RowIsValid(idx);
394591 vector_null_positions[nulls_idx] = UnsafeNumericCast<uint16_t>(vector_idx + i);
394592 nulls_idx += is_null;
394593 input_vector[vector_idx + i] = value;
394594 }
394595 }
394598 vector_idx += values_to_fill_alp_input;
394599 // We still need this check since we could have an incomplete input_vector at the end of data
394600 if (vector_idx == AlpConstants::ALP_VECTOR_SIZE) {
394601 CompressVector();
394602 D_ASSERT(vector_idx == 0);
394603 }
394604 }
394605 }
Here is the call graph for this function:

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