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::BinaryAggregateHeap< K, V, K_COMPARATOR > Class Template Reference

Public Member Functions

 BinaryAggregateHeap (ArenaAllocator &allocator, idx_t capacity_p)
void Initialize (ArenaAllocator &allocator, const idx_t capacity_p)
bool IsEmpty () const
idx_t Size () const
idx_t Capacity () const
void Insert (ArenaAllocator &allocator, const K &key, const V &value)
void Insert (ArenaAllocator &allocator, const BinaryAggregateHeap &other)
STORAGE_TYPE * SortAndGetHeap ()

Static Public Member Functions

static const V & GetValue (const STORAGE_TYPE &slot)

Private Types

using STORAGE_TYPE = pair<HeapEntry<K>, HeapEntry<V>>

Private Member Functions

void Grow (ArenaAllocator &allocator)

Static Private Member Functions

static bool Compare (const STORAGE_TYPE &left, const STORAGE_TYPE &right)

Private Attributes

idx_t capacity = 0
idx_t allocated_capacity = 0
STORAGE_TYPE * heap = nullptr
idx_t size = 0

Constructor & Destructor Documentation

◆ BinaryAggregateHeap()

template<class K, class V, class K_COMPARATOR>
duckdb::BinaryAggregateHeap< K, V, K_COMPARATOR >::BinaryAggregateHeap ( ArenaAllocator & allocator,
idx_t capacity_p )
inline
209945 {
209946 Initialize(allocator, capacity_p);
209947 }
Definition duckdb.cpp:209939

Member Function Documentation

◆ Initialize()

template<class K, class V, class K_COMPARATOR>
void duckdb::BinaryAggregateHeap< K, V, K_COMPARATOR >::Initialize ( ArenaAllocator & allocator,
const idx_t capacity_p )
inline
209949 {
209950 capacity = capacity_p;
209951 allocated_capacity = 0;
209952 heap = nullptr;
209953 size = 0;
209954 }

◆ IsEmpty()

template<class K, class V, class K_COMPARATOR>
bool duckdb::BinaryAggregateHeap< K, V, K_COMPARATOR >::IsEmpty ( ) const
inline
209956 {
209957 return size == 0;
209958 }

◆ Size()

template<class K, class V, class K_COMPARATOR>
idx_t duckdb::BinaryAggregateHeap< K, V, K_COMPARATOR >::Size ( ) const
inline
209959 {
209960 return size;
209961 }

◆ Capacity()

template<class K, class V, class K_COMPARATOR>
idx_t duckdb::BinaryAggregateHeap< K, V, K_COMPARATOR >::Capacity ( ) const
inline
209962 {
209963 return capacity;
209964 }

◆ Insert() [1/2]

template<class K, class V, class K_COMPARATOR>
void duckdb::BinaryAggregateHeap< K, V, K_COMPARATOR >::Insert ( ArenaAllocator & allocator,
const K & key,
const V & value )
inline
209966 {
209967 D_ASSERT(capacity != 0); // must be initialized
209968
209969 // If the heap is not full, insert the value into a new slot
209970 if (size < capacity) {
209971 if (size == allocated_capacity) {
209972 Grow(allocator);
209973 }
209974 heap[size].first.Assign(allocator, key);
209975 heap[size].second.Assign(allocator, value);
209976 size++;
209977 std::push_heap(heap, heap + size, Compare);
209978 }
209979 // If the heap is full, check if the value is greater than the smallest value in the heap
209980 // If it is, assign the new value to the slot and re-heapify
209981 else if (K_COMPARATOR::Operation(key, heap[0].first.value)) {
209982 std::pop_heap(heap, heap + size, Compare);
209983 heap[size - 1].first.Assign(allocator, key);
209984 heap[size - 1].second.Assign(allocator, value);
209985 std::push_heap(heap, heap + size, Compare);
209986 }
209987 D_ASSERT(std::is_heap(heap, heap + size, Compare));
209988 }

◆ Insert() [2/2]

template<class K, class V, class K_COMPARATOR>
void duckdb::BinaryAggregateHeap< K, V, K_COMPARATOR >::Insert ( ArenaAllocator & allocator,
const BinaryAggregateHeap< K, V, K_COMPARATOR > & other )
inline
209990 {
209991 for (idx_t slot = 0; slot < other.Size(); slot++) {
209992 Insert(allocator, other.heap[slot].first.value, other.heap[slot].second.value);
209993 }
209994 }

◆ SortAndGetHeap()

template<class K, class V, class K_COMPARATOR>
STORAGE_TYPE * duckdb::BinaryAggregateHeap< K, V, K_COMPARATOR >::SortAndGetHeap ( )
inline
209996 {
209997 std::sort_heap(heap, heap + size, Compare);
209998 return heap;
209999 }

◆ GetValue()

template<class K, class V, class K_COMPARATOR>
const V & duckdb::BinaryAggregateHeap< K, V, K_COMPARATOR >::GetValue ( const STORAGE_TYPE & slot)
inlinestatic
210001 {
210002 return slot.second.value;
210003 }

◆ Grow()

template<class K, class V, class K_COMPARATOR>
void duckdb::BinaryAggregateHeap< K, V, K_COMPARATOR >::Grow ( ArenaAllocator & allocator)
inlineprivate
210006 {
210007 D_ASSERT(allocated_capacity < capacity);
210008 const auto old_allocated_capacity = allocated_capacity;
210009 if (allocated_capacity == 0) {
210010 allocated_capacity = 1;
210011 } else if (allocated_capacity > capacity / 2) {
210012 allocated_capacity = capacity;
210013 } else {
210014 allocated_capacity *= 2;
210015 }
210016
210017 const auto old_size = old_allocated_capacity * sizeof(STORAGE_TYPE);
210018 const auto new_size = allocated_capacity * sizeof(STORAGE_TYPE);
210019 auto ptr = heap ? allocator.ReallocateAligned(reinterpret_cast<data_ptr_t>(heap), old_size, new_size)
210020 : allocator.AllocateAligned(new_size);
210022 heap = reinterpret_cast<STORAGE_TYPE *>(ptr);
210023 }

◆ Compare()

template<class K, class V, class K_COMPARATOR>
bool duckdb::BinaryAggregateHeap< K, V, K_COMPARATOR >::Compare ( const STORAGE_TYPE & left,
const STORAGE_TYPE & right )
inlinestaticprivate
210025 {
210026 return K_COMPARATOR::Operation(left.first.value, right.first.value);
210027 }

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