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::WindowSegmentTreeLocalState Class Reference
Inheritance diagram for duckdb::WindowSegmentTreeLocalState:
Collaboration diagram for duckdb::WindowSegmentTreeLocalState:

Public Member Functions

 WindowSegmentTreeLocalState (ExecutionContext &context)
void Finalize (ExecutionContext &context, WindowAggregatorGlobalState &gastate, CollectionPtr collection) override
void Evaluate (ExecutionContext &context, const WindowSegmentTreeGlobalState &gsink, const DataChunk &bounds, Vector &result, idx_t count, idx_t row_idx)
Public Member Functions inherited from duckdb::WindowAggregatorLocalState
 WindowAggregatorLocalState (ExecutionContext &context)
void Sink (ExecutionContext &context, WindowAggregatorGlobalState &gastate, DataChunk &sink_chunk, DataChunk &coll_chunk, idx_t row_idx)
Public Member Functions inherited from duckdb::LocalSinkState
template<class TARGET>
TARGET & Cast ()
template<class TARGET>
const TARGET & Cast () const

Public Attributes

unique_ptr< WindowSegmentTreePart > part
 The left (default) segment tree part.
unique_ptr< WindowSegmentTreePart > right_part
 The right segment tree part (for EXCLUDE).
Public Attributes inherited from duckdb::WindowAggregatorLocalState
ArenaAllocator allocator
 Global allocator.
unique_ptr< WindowCursor > cursor
 The state used for reading the collection.
Public Attributes inherited from duckdb::LocalSinkState
SourcePartitionInfo partition_info
 Source partition info.

Additional Inherited Members

Public Types inherited from duckdb::WindowAggregatorLocalState
using CollectionPtr = optional_ptr<WindowCollection>
Static Public Member Functions inherited from duckdb::WindowAggregatorLocalState
static void InitSubFrames (SubFrames &frames, const WindowExcludeMode exclude_mode)

Constructor & Destructor Documentation

◆ WindowSegmentTreeLocalState()

duckdb::WindowSegmentTreeLocalState::WindowSegmentTreeLocalState ( ExecutionContext & context)
inlineexplicit
257683 : WindowAggregatorLocalState(context) {
257684 }

Member Function Documentation

◆ Finalize()

void duckdb::WindowSegmentTreeLocalState::Finalize ( ExecutionContext & context,
WindowAggregatorGlobalState & gastate,
CollectionPtr collection )
overridevirtual

Reimplemented from duckdb::WindowAggregatorLocalState.

257886 {
257887 WindowAggregatorLocalState::Finalize(context, gastate, collection);
257888
257889 // Single part for constructing the tree
257890 auto &gstate = gastate.Cast<WindowSegmentTreeGlobalState>();
257891 auto cursor = make_uniq<WindowCursor>(*collection, gastate.aggregator.child_idx);
257892 const auto leaf_count = collection->size();
257893 auto &filter_mask = gstate.filter_mask;
257894 WindowSegmentTreePart gtstate(allocator, gastate.aggr, std::move(cursor), filter_mask);
257895
257896 auto &levels_flat_native = gstate.levels_flat_native;
257897 const auto &levels_flat_start = gstate.levels_flat_start;
257898 // iterate over the levels of the segment tree
257899 for (;;) {
257900 const idx_t level_current = gstate.build_level.load();
257901 if (level_current >= levels_flat_start.size()) {
257902 break;
257903 }
257904
257905 // level 0 is data itself
257906 const auto level_size =
257907 (level_current == 0 ? leaf_count : levels_flat_start[level_current] - levels_flat_start[level_current - 1]);
257908 if (level_size <= 1) {
257909 break;
257910 }
257911 const idx_t build_count = (level_size + gstate.TREE_FANOUT - 1) / gstate.TREE_FANOUT;
257912
257913 // Build the next fan-in
257914 const idx_t build_idx = (*gstate.build_started).at(level_current)++;
257915 if (build_idx >= build_count) {
257916 // Nothing left at this level, so wait until other threads are done.
257917 // Since we are only building TREE_FANOUT values at a time, this will be quick.
257918 while (level_current == gstate.build_level.load()) {
257919 std::this_thread::sleep_for(std::chrono::milliseconds(1));
257920 }
257921 continue;
257922 }
257923
257924 // compute the aggregate for this entry in the segment tree
257925 const idx_t pos = build_idx * gstate.TREE_FANOUT;
257926 const idx_t levels_flat_offset = levels_flat_start[level_current] + build_idx;
257927 auto state_ptr = levels_flat_native.GetStatePtr(levels_flat_offset);
257928 gtstate.WindowSegmentValue(gstate, level_current, pos, MinValue(level_size, pos + gstate.TREE_FANOUT),
257929 state_ptr);
257930 gtstate.FlushStates(level_current > 0);
257931
257932 // If that was the last one, mark the level as complete.
257933 const idx_t build_complete = ++(*gstate.build_completed).at(level_current);
257934 if (build_complete == build_count) {
257935 gstate.build_level++;
257936 continue;
257937 }
257938 }
257939}
ArenaAllocator allocator
Global allocator.
Definition duckdb.cpp:164091
unique_ptr< WindowCursor > cursor
The state used for reading the collection.
Definition duckdb.cpp:164094
T & at(int idx, std::vector< T > &items)
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ Evaluate()

void duckdb::WindowSegmentTreeLocalState::Evaluate ( ExecutionContext & context,
const WindowSegmentTreeGlobalState & gsink,
const DataChunk & bounds,
Vector & result,
idx_t count,
idx_t row_idx )
257949 {
257950 auto window_begin = FlatVector::GetData<const idx_t>(bounds.data[FRAME_BEGIN]);
257951 auto window_end = FlatVector::GetData<const idx_t>(bounds.data[FRAME_END]);
257952 auto peer_begin = FlatVector::GetData<const idx_t>(bounds.data[PEER_BEGIN]);
257953 auto peer_end = FlatVector::GetData<const idx_t>(bounds.data[PEER_END]);
257954
257955 if (!part) {
257956 part = make_uniq<WindowSegmentTreePart>(allocator, gtstate.aggr, cursor->Copy(), gtstate.filter_mask);
257957 }
257958
257959 if (gtstate.aggregator.exclude_mode != WindowExcludeMode::NO_OTHER) {
257960 // If we exclude the current row, then both left and right need to contain it.
257961 const bool exclude_current = gtstate.aggregator.exclude_mode == WindowExcludeMode::CURRENT_ROW;
257962
257963 // 1. evaluate the tree left of the excluded part
257964 auto middle = exclude_current ? peer_end : peer_begin;
257965 part->Evaluate(gtstate, window_begin, middle, window_end, result, count, row_idx, WindowSegmentTreePart::LEFT);
257966
257967 // 2. set up a second state for the right of the excluded part
257968 if (!right_part) {
257969 right_part = part->Copy();
257970 }
257971
257972 // 3. evaluate the tree right of the excluded part
257973 middle = exclude_current ? peer_begin : peer_end;
257974 right_part->Evaluate(gtstate, middle, window_end, window_begin, result, count, row_idx,
257975 WindowSegmentTreePart::RIGHT);
257976
257977 // 4. combine the buffer state into the Segment Tree State
257978 part->Combine(*right_part, count);
257979 } else {
257980 part->Evaluate(gtstate, window_begin, window_end, nullptr, result, count, row_idx, WindowSegmentTreePart::FULL);
257981 }
257982
257983 part->Finalize(result, count);
257984}
vector< Vector > data
The vectors owned by the DataChunk.
Definition duckdb.hpp:11445
unique_ptr< WindowSegmentTreePart > part
The left (default) segment tree part.
Definition duckdb.cpp:257690
unique_ptr< WindowSegmentTreePart > right_part
The right segment tree part (for EXCLUDE).
Definition duckdb.cpp:257692

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