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

Public Types

using ZippedTuple = std::tuple<idx_t, idx_t>
using ZippedElements = vector<ZippedTuple>
Public Types inherited from duckdb::MergeSortTree< idx_t, idx_t >
using ElementType
using OffsetType
using Elements
using Offsets
using Level
using Tree
using RunElement
using RunElements
using Games

Public Member Functions

 WindowDistinctSortTree (WindowDistinctAggregatorGlobalState &gdastate, idx_t count)
void Build (WindowDistinctAggregatorLocalState &ldastate)
Public Member Functions inherited from duckdb::MergeSortTree< idx_t, idx_t >
 MergeSortTree (const std::less< idx_t > &cmp=std::less< idx_t >())
Elements & LowestLevel ()
Elements & Allocate (idx_t count)
void Build ()
pair< idx_t, idx_t > SelectNth (const SubFrames &frames, idx_t n) const
ElementType NthElement (idx_t i) const
void AggregateLowerBound (const idx_t lower, const idx_t upper, const idx_t needle, L aggregate) const
void Print () const

Protected Member Functions

bool TryNextRun (idx_t &level_idx, idx_t &run_idx)
void BuildRun (idx_t level_nr, idx_t i, WindowDistinctAggregatorLocalState &ldastate)
Protected Member Functions inherited from duckdb::MergeSortTree< idx_t, idx_t >
bool TryNextRun (idx_t &level_idx, idx_t &run_idx)
void BuildRun (idx_t level_idx, idx_t run_idx)
RunElement StartGames (Games &losers, const RunElements &elements, const RunElement &sentinel)
RunElement ReplayGames (Games &losers, idx_t slot_idx, const RunElement &insert_val)

Protected Attributes

WindowDistinctAggregatorGlobalState & gdastate
Protected Attributes inherited from duckdb::MergeSortTree< idx_t, idx_t >
mutex build_lock
 Parallel build machinery.
atomic< idx_t > build_level
atomic< idx_t > build_complete
idx_t build_run
idx_t build_run_length
idx_t build_num_runs

Additional Inherited Members

Public Attributes inherited from duckdb::MergeSortTree< idx_t, idx_t >
Tree tree
CompareElements cmp
Static Public Attributes inherited from duckdb::MergeSortTree< idx_t, idx_t >
static constexpr ElementType INVALID
static constexpr auto FANOUT
static constexpr auto CASCADING
Static Protected Member Functions inherited from duckdb::MergeSortTree< idx_t, idx_t >
static idx_t LowestCascadingLevel ()

Constructor & Destructor Documentation

◆ WindowDistinctSortTree()

duckdb::WindowDistinctSortTree::WindowDistinctSortTree ( WindowDistinctAggregatorGlobalState & gdastate,
idx_t count )
inline
255465 : gdastate(gdastate) {
255466 // Set up for parallel build
255467 build_level = 0;
255468 build_complete = 0;
255469 build_run = 0;
255470 build_run_length = 1;
255471 build_num_runs = count;
255472 }

Member Function Documentation

◆ Build()

void duckdb::WindowDistinctSortTree::Build ( WindowDistinctAggregatorLocalState & ldastate)
255936 {
255937 // Fan in parent levels until we are at the top
255938 // Note that we don't build the top layer as that would just be all the data.
255939 while (build_level.load() < tree.size()) {
255940 idx_t level_idx;
255941 idx_t run_idx;
255942 if (TryNextRun(level_idx, run_idx)) {
255943 BuildRun(level_idx, run_idx, ldastate);
255944 } else {
255945 std::this_thread::yield();
255946 }
255947 }
255948}
void BuildRun(idx_t level_nr, idx_t i, WindowDistinctAggregatorLocalState &ldastate)
Definition duckdb.cpp:255950
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ TryNextRun()

bool duckdb::WindowDistinctSortTree::TryNextRun ( idx_t & level_idx,
idx_t & run_idx )
protected
255896 {
255897 const auto fanout = FANOUT;
255898
255899 lock_guard<mutex> stage_guard(build_lock);
255900
255901 // Verify we are not done
255902 if (build_level >= tree.size()) {
255903 return false;
255904 }
255905
255906 // Finished with this level?
255907 if (build_complete >= build_num_runs) {
255908 auto &zipped_tree = gdastate.zipped_tree;
255909 std::swap(tree[build_level].second, zipped_tree.tree[build_level].second);
255910
255911 ++build_level;
255912 if (build_level >= tree.size()) {
255913 zipped_tree.tree.clear();
255914 return false;
255915 }
255916
255917 const auto count = LowestLevel().size();
255918 build_run_length *= fanout;
255919 build_num_runs = (count + build_run_length - 1) / build_run_length;
255920 build_run = 0;
255921 build_complete = 0;
255922 }
255923
255924 // If all runs are in flight,
255925 // yield until the next level is ready
255926 if (build_run >= build_num_runs) {
255927 return false;
255928 }
255929
255930 level_idx = build_level;
255931 run_idx = build_run++;
255932
255933 return true;
255934}
mutex build_lock
Definition duckdb.cpp:59434

◆ BuildRun()

void duckdb::WindowDistinctSortTree::BuildRun ( idx_t level_nr,
idx_t i,
WindowDistinctAggregatorLocalState & ldastate )
protected

Input data chunk, used for leaf segment aggregation

The states to update

255950 {
255951 auto &aggr = gdastate.aggr;
255952 auto &inputs = ldastate.cursor->chunk;
255953 auto &levels_flat_native = gdastate.levels_flat_native;
255954
255956 auto &leaves = ldastate.leaves;
255957 auto &sel = ldastate.sel;
255958
255959 AggregateInputData aggr_input_data(aggr.GetFunctionData(), ldastate.allocator);
255960
255962 auto &update_v = ldastate.update_v;
255963 auto updates = FlatVector::GetData<data_ptr_t>(update_v);
255964
255965 auto &source_v = ldastate.source_v;
255966 auto sources = FlatVector::GetData<data_ptr_t>(source_v);
255967 auto &target_v = ldastate.target_v;
255968 auto targets = FlatVector::GetData<data_ptr_t>(target_v);
255969
255970 auto &zipped_tree = gdastate.zipped_tree;
255971 auto &zipped_level = zipped_tree.tree[level_nr].first;
255972 auto &level = tree[level_nr].first;
255973
255974 // Reset the combine state
255975 idx_t nupdate = 0;
255976 idx_t ncombine = 0;
255977 data_ptr_t prev_state = nullptr;
255978 idx_t i = run_idx * build_run_length;
255979 auto next_limit = MinValue<idx_t>(zipped_level.size(), i + build_run_length);
255980 idx_t levels_flat_offset = level_nr * zipped_level.size() + i;
255981 for (auto j = i; j < next_limit; ++j) {
255982 // Initialise the next aggregate
255983 auto curr_state = levels_flat_native.GetStatePtr(levels_flat_offset++);
255984
255985 // Update this state (if it matches)
255986 const auto prev_idx = std::get<0>(zipped_level[j]);
255987 level[j] = prev_idx;
255988 if (prev_idx < i + 1) {
255989 const auto update_idx = std::get<1>(zipped_level[j]);
255990 if (!ldastate.cursor->RowIsVisible(update_idx)) {
255991 // Flush if we have to move the cursor
255992 // Push the updates first so they propagate
255993 leaves.Reference(inputs);
255994 leaves.Slice(sel, nupdate);
255995 aggr.function.GetStateUpdateCallback()(leaves.data.data(), aggr_input_data, leaves.ColumnCount(),
255996 update_v, nupdate);
255997 nupdate = 0;
255998
255999 // Combine the states sequentially
256000 aggr.function.GetStateCombineCallback()(source_v, target_v, aggr_input_data, ncombine);
256001 ncombine = 0;
256002
256003 // Move the update into range.
256004 ldastate.cursor->Seek(update_idx);
256005 }
256006
256007 updates[nupdate] = curr_state;
256008 // input_idx
256009 sel[nupdate] = ldastate.cursor->RowOffset(update_idx);
256010 ++nupdate;
256011 }
256012
256013 // Merge the previous state (if any)
256014 if (prev_state) {
256015 sources[ncombine] = prev_state;
256016 targets[ncombine] = curr_state;
256017 ++ncombine;
256018 }
256019 prev_state = curr_state;
256020
256021 // Flush the states if one is maxed out.
256022 if (MaxValue<idx_t>(ncombine, nupdate) >= STANDARD_VECTOR_SIZE) {
256023 // Push the updates first so they propagate
256024 leaves.Reference(inputs);
256025 leaves.Slice(sel, nupdate);
256026 aggr.function.GetStateUpdateCallback()(leaves.data.data(), aggr_input_data, leaves.ColumnCount(), update_v,
256027 nupdate);
256028 nupdate = 0;
256029
256030 // Combine the states sequentially
256031 aggr.function.GetStateCombineCallback()(source_v, target_v, aggr_input_data, ncombine);
256032 ncombine = 0;
256033 }
256034 }
256035
256036 // Flush any remaining states
256037 if (ncombine || nupdate) {
256038 // Push the updates
256039 leaves.Reference(inputs);
256040 leaves.Slice(sel, nupdate);
256041 aggr.function.GetStateUpdateCallback()(leaves.data.data(), aggr_input_data, leaves.ColumnCount(), update_v,
256042 nupdate);
256043 nupdate = 0;
256044
256045 // Combine the states sequentially
256046 aggr.function.GetStateCombineCallback()(source_v, target_v, aggr_input_data, ncombine);
256047 ncombine = 0;
256048 }
256049
256050 ++build_complete;
256051}

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