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

Classes

struct  ResumeScanState

Public Member Functions

 Iterator (ART &art)
template<typename Output>
ARTScanResult Scan (const ARTKey &upper_bound, Output &output, bool equal)
void FindMinimum (const Node &node)
 Finds the minimum (leaf) of the current subtree.
bool LowerBound (const Node &node, const ARTKey &key, const bool equal)
uint8_t GetNestedDepth () const
 Returns the nested depth.

Public Attributes

IteratorKey current_key
 Holds the current key leading down to the top node on the stack.

Static Public Attributes

static constexpr uint8_t ROW_ID_SIZE = sizeof(row_t)

Private Member Functions

bool Next ()
void PopNode ()
 Pop the top node from the stack of iterator entries and adjust the current key.

Private Attributes

ART & art
 The ART.
stack< IteratorEntry > nodes
 Stack of nodes from the root to the currently active node.
Node last_leaf = Node()
 Last visited leaf node.
uint8_t row_id [ROW_ID_SIZE]
 Holds the row ID of nested leaves.
GateStatus status
 True, if we passed a gate.
uint8_t nested_depth = 0
 Depth in a nested leaf.
bool entered_nested_leaf = false
 True, if we entered a nested leaf to retrieve the next node.
ResumeScanState resume_state

Constructor & Destructor Documentation

◆ Iterator()

duckdb::Iterator::Iterator ( ART & art)
inlineexplicit
59095: art(art), status(GateStatus::GATE_NOT_SET) {};
GateStatus status
True, if we passed a gate.
Definition duckdb.cpp:59126
ART & art
The ART.
Definition duckdb.cpp:59118

Member Function Documentation

◆ Scan()

template<typename Output>
template ARTScanResult duckdb::Iterator::Scan< KeyRowIdOutput > ( const ARTKey & upper_bound,
Output & output,
bool equal )

Templated scan implementation. Output policy defines how results are emitted. Returns COMPLETED if scan finished, PAUSED if stopped due to output capacity.

153983 {
153984 bool has_next;
153985 do {
153986 // An empty upper bound indicates that no upper bound exists.
153987 if (!upper_bound.Empty()) {
153988 if (status == GateStatus::GATE_NOT_SET || entered_nested_leaf) {
153989 if (current_key.GreaterThan(upper_bound, equal, nested_depth)) {
153990 return ARTScanResult::COMPLETED;
153991 }
153992 }
153993 }
153994
153995 // Set the current key in the output policy.
153996 D_ASSERT(current_key.Size() >= nested_depth);
153997 auto key_len = current_key.Size() - nested_depth;
153998 output.SetKey(current_key, key_len);
153999
154000 switch (last_leaf.GetType()) {
154001 case NType::LEAF_INLINED: {
154002 if (output.IsFull()) {
154003 return ARTScanResult::PAUSED;
154004 }
154005 output.Add(last_leaf.GetRowId());
154006 break;
154007 }
154008 case NType::LEAF: {
154009 D_ASSERT(nested_depth == 0);
154010 if (!resume_state.has_cached_row_ids) {
154011 resume_state.cached_row_ids.clear();
154012 Leaf::DeprecatedGetRowIds(art, last_leaf, resume_state.cached_row_ids, NumericLimits<idx_t>::Maximum());
154013 resume_state.cached_row_ids_it = resume_state.cached_row_ids.begin();
154014 resume_state.has_cached_row_ids = true;
154015 }
154016 // Try to output the next entry in the deprecated leaf chain.
154017 while (resume_state.cached_row_ids_it != resume_state.cached_row_ids.end()) {
154018 if (output.IsFull()) {
154019 // If we pause here, then scanning will resume at cached_row_ids_it.
154020 return ARTScanResult::PAUSED;
154021 }
154022 output.Add(*resume_state.cached_row_ids_it);
154023 ++resume_state.cached_row_ids_it;
154024 }
154025 resume_state.has_cached_row_ids = false;
154026 break;
154027 }
154028 case NType::NODE_7_LEAF:
154029 case NType::NODE_15_LEAF:
154030 case NType::NODE_256_LEAF: {
154031 // If we haven't traversed this leaf yet, set nested_started to true (allows us to pick up iteration again
154032 // in case we fill the output with capacity.
154033 if (!resume_state.nested_started) {
154034 resume_state.nested_byte = 0;
154035 resume_state.nested_started = true;
154036 }
154037 // Try to output the next inlined leaf.
154038 while (last_leaf.GetNextByte(art, resume_state.nested_byte)) {
154039 if (output.IsFull()) {
154040 // If we pause here, then scanning will resume at nested_byte in the current leaf.
154041 return ARTScanResult::PAUSED;
154042 }
154043 row_id[ROW_ID_SIZE - 1] = resume_state.nested_byte;
154044 ARTKey rid_key(&row_id[0], ROW_ID_SIZE);
154045 output.Add(rid_key.GetRowId());
154046
154047 if (resume_state.nested_byte == NumericLimits<uint8_t>::Maximum()) {
154048 break;
154049 }
154050 resume_state.nested_byte++;
154051 }
154052 resume_state.nested_started = false;
154053 break;
154054 }
154055 default:
154056 throw InternalException("Invalid leaf type for index scan.");
154057 }
154058
154059 entered_nested_leaf = false;
154060 has_next = Next();
154061 } while (has_next);
154062 return ARTScanResult::COMPLETED;
154063}
uint8_t nested_depth
Depth in a nested leaf.
Definition duckdb.cpp:59128
Node last_leaf
Last visited leaf node.
Definition duckdb.cpp:59122
bool entered_nested_leaf
True, if we entered a nested leaf to retrieve the next node.
Definition duckdb.cpp:59130
bool Next()
Definition duckdb.cpp:154201
uint8_t row_id[ROW_ID_SIZE]
Holds the row ID of nested leaves.
Definition duckdb.cpp:59124
IteratorKey current_key
Holds the current key leading down to the top node on the stack.
Definition duckdb.cpp:59097
static bool DeprecatedGetRowIds(ART &art, const Node &node, set< row_t > &row_ids, const idx_t max_count)
Definition duckdb.cpp:154431
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindMinimum()

void duckdb::Iterator::FindMinimum ( const Node & node)

Finds the minimum (leaf) of the current subtree.

154069 {
154070 reference<const Node> ref(node);
154071
154072 while (ref.get().HasMetadata()) {
154073 // Found the minimum.
154074 if (ref.get().IsAnyLeaf()) {
154075 last_leaf = ref.get();
154076 return;
154077 }
154078
154079 // We are passing a gate node.
154080 if (ref.get().GetGateStatus() == GateStatus::GATE_SET) {
154081 D_ASSERT(status == GateStatus::GATE_NOT_SET);
154082 status = GateStatus::GATE_SET;
154083 entered_nested_leaf = true;
154084 nested_depth = 0;
154085 }
154086
154087 // Traverse the prefix.
154088 if (ref.get().GetType() == NType::PREFIX) {
154089 Prefix prefix(art, ref.get());
154090 for (idx_t i = 0; i < prefix.data[art.PrefixCount()]; i++) {
154091 current_key.Push(prefix.data[i]);
154092 if (status == GateStatus::GATE_SET) {
154093 row_id[nested_depth] = prefix.data[i];
154094 nested_depth++;
154095 D_ASSERT(nested_depth < Prefix::ROW_ID_SIZE);
154096 }
154097 }
154098 nodes.emplace(ref.get(), 0);
154099 ref = *prefix.ptr;
154100 continue;
154101 }
154102
154103 // Go to the leftmost entry in the current node.
154104 uint8_t byte = 0;
154105 auto next = ref.get().GetNextChild(art, byte);
154106 D_ASSERT(next);
154107
154108 // Move to the leftmost node.
154109 current_key.Push(byte);
154110 if (status == GateStatus::GATE_SET) {
154111 row_id[nested_depth] = byte;
154112 nested_depth++;
154113 D_ASSERT(nested_depth < Prefix::ROW_ID_SIZE);
154114 }
154115 nodes.emplace(ref.get(), byte);
154116 ref = *next;
154117 }
154118 // Should always have a node with metadata.
154119 throw InternalException("ART Iterator::FindMinimum: Reached node without metadata");
154120}
stack< IteratorEntry > nodes
Stack of nodes from the root to the currently active node.
Definition duckdb.cpp:59120
::uint8_t uint8_t
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
Here is the caller graph for this function:

◆ LowerBound()

bool duckdb::Iterator::LowerBound ( const Node & node,
const ARTKey & key,
const bool equal )

Finds the lower bound of the ART and adds the nodes to the stack. Returns false, if the lower bound exceeds the maximum value of the ART.

154122 {
154123 reference<const Node> ref(node);
154124 idx_t depth = 0;
154125
154126 while (ref.get().HasMetadata()) {
154127 // We found any leaf node, or a gate.
154128 if (ref.get().IsAnyLeaf() || ref.get().GetGateStatus() == GateStatus::GATE_SET) {
154129 D_ASSERT(status == GateStatus::GATE_NOT_SET);
154130 D_ASSERT(current_key.Size() == key.len);
154131 if (!equal && current_key.Contains(key)) {
154132 return Next();
154133 }
154134
154135 if (ref.get().GetGateStatus() == GateStatus::GATE_SET) {
154136 FindMinimum(ref.get());
154137 } else {
154138 last_leaf = ref.get();
154139 }
154140 return true;
154141 }
154142
154143 D_ASSERT(ref.get().GetGateStatus() == GateStatus::GATE_NOT_SET);
154144 if (ref.get().GetType() != NType::PREFIX) {
154145 auto next_byte = key[depth];
154146 auto child = ref.get().GetNextChild(art, next_byte);
154147
154148 // The key is greater than any key in this subtree.
154149 if (!child) {
154150 return Next();
154151 }
154152
154153 current_key.Push(next_byte);
154154 nodes.emplace(ref.get(), next_byte);
154155
154156 // We return the minimum because all keys are greater than the lower bound.
154157 if (next_byte > key[depth]) {
154158 FindMinimum(*child);
154159 return true;
154160 }
154161
154162 // Move to the child and increment depth.
154163 ref = *child;
154164 depth++;
154165 continue;
154166 }
154167
154168 // Push back all prefix bytes.
154169 Prefix prefix(art, ref.get());
154170 for (idx_t i = 0; i < prefix.data[art.PrefixCount()]; i++) {
154171 current_key.Push(prefix.data[i]);
154172 }
154173 nodes.emplace(ref.get(), 0);
154174
154175 // We compare the prefix bytes with the key bytes.
154176 for (idx_t i = 0; i < prefix.data[art.PrefixCount()]; i++) {
154177 // We found a prefix byte that is less than its corresponding key byte.
154178 // I.e., the subsequent node is lesser than the key. Thus, the next node
154179 // is the lower bound.
154180 if (prefix.data[i] < key[depth + i]) {
154181 return Next();
154182 }
154183
154184 // We found a prefix byte that is greater than its corresponding key byte.
154185 // I.e., the subsequent node is greater than the key. Thus, the minimum is
154186 // the lower bound.
154187 if (prefix.data[i] > key[depth + i]) {
154188 FindMinimum(*prefix.ptr);
154189 return true;
154190 }
154191 }
154192
154193 // The prefix matches the key. Move to the child and update depth.
154194 depth += prefix.data[art.PrefixCount()];
154195 ref = *prefix.ptr;
154196 }
154197 // Should always have a node with metadata.
154198 throw InternalException("ART Iterator::LowerBound: Reached node without metadata");
154199}
void FindMinimum(const Node &node)
Finds the minimum (leaf) of the current subtree.
Definition duckdb.cpp:154069
double depth(InputArray R, InputArray t, InputArray X)
Here is the call graph for this function:

◆ GetNestedDepth()

uint8_t duckdb::Iterator::GetNestedDepth ( ) const
inline

Returns the nested depth.

59112 {
59113 return nested_depth;
59114 }

◆ Next()

bool duckdb::Iterator::Next ( )
private

Goes to the next leaf in the ART and sets it as last_leaf, returns false if there is no next leaf.

154201 {
154202 while (!nodes.empty()) {
154203 auto &top = nodes.top();
154204 D_ASSERT(!top.node.IsAnyLeaf());
154205
154206 if (top.node.GetType() == NType::PREFIX) {
154207 PopNode();
154208 continue;
154209 }
154210
154211 if (top.byte == NumericLimits<uint8_t>::Maximum()) {
154212 // No more children of this node.
154213 // Move up the tree by popping the key byte of the current node.
154214 PopNode();
154215 continue;
154216 }
154217
154218 top.byte++;
154219 auto next_node = top.node.GetNextChild(art, top.byte);
154220 if (!next_node) {
154221 // No more children of this node.
154222 // Move up the tree by popping the key byte of the current node.
154223 PopNode();
154224 continue;
154225 }
154226
154227 current_key.Pop(1);
154228 current_key.Push(top.byte);
154229 if (status == GateStatus::GATE_SET) {
154230 row_id[nested_depth - 1] = top.byte;
154231 }
154232
154233 FindMinimum(*next_node);
154234 return true;
154235 }
154236 return false;
154237}
void PopNode()
Pop the top node from the stack of iterator entries and adjust the current key.
Definition duckdb.cpp:154239
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PopNode()

void duckdb::Iterator::PopNode ( )
private

Pop the top node from the stack of iterator entries and adjust the current key.

154239 {
154240 auto gate_status = nodes.top().node.GetGateStatus();
154241
154242 // Pop the byte and the node.
154243 if (nodes.top().node.GetType() != NType::PREFIX) {
154244 current_key.Pop(1);
154245 if (status == GateStatus::GATE_SET) {
154246 nested_depth--;
154247 D_ASSERT(nested_depth < Prefix::ROW_ID_SIZE);
154248 }
154249
154250 } else {
154251 // Pop all prefix bytes and the node.
154252 Prefix prefix(art, nodes.top().node);
154253 auto prefix_byte_count = prefix.data[art.PrefixCount()];
154254 current_key.Pop(prefix_byte_count);
154255
154256 if (status == GateStatus::GATE_SET) {
154257 nested_depth -= prefix_byte_count;
154258 D_ASSERT(nested_depth < Prefix::ROW_ID_SIZE);
154259 }
154260 }
154261 nodes.pop();
154262
154263 // We are popping a gate node.
154264 if (gate_status == GateStatus::GATE_SET) {
154265 D_ASSERT(status == GateStatus::GATE_SET);
154266 status = GateStatus::GATE_NOT_SET;
154267 }
154268}
Here is the caller graph for this function:

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