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

Classes

struct  NodeEntry

Public Member Functions

 ARTBuilder (ArenaAllocator &arena, ART &art, const unsafe_vector< ARTKey > &keys, const unsafe_vector< ARTKey > &row_ids)
void Init (Node &node, const idx_t end)
 Initialize the ART builder by passing a reference to the root node.
ARTConflictType Build ()
 Build the ART starting at the first entry in the stack.

Private Attributes

ArenaAllocator & arena
 The arena holds any temporary memory allocated during the Build phase.
ART & art
 The ART holding the node memory.
const unsafe_vector< ARTKey > & keys
 The keys to build the ART from.
const unsafe_vector< ARTKey > & row_ids
 The row IDs matching the keys.
stack< NodeEntry > s
 The stack. While merging, NodeEntry elements are pushed onto of the stack.

Constructor & Destructor Documentation

◆ ARTBuilder()

duckdb::ARTBuilder::ARTBuilder ( ArenaAllocator & arena,
ART & art,
const unsafe_vector< ARTKey > & keys,
const unsafe_vector< ARTKey > & row_ids )
inline
150334 }
const unsafe_vector< ARTKey > & row_ids
The row IDs matching the keys.
Definition duckdb.cpp:150363
ArenaAllocator & arena
The arena holds any temporary memory allocated during the Build phase.
Definition duckdb.cpp:150357
const unsafe_vector< ARTKey > & keys
The keys to build the ART from.
Definition duckdb.cpp:150361
ART & art
The ART holding the node memory.
Definition duckdb.cpp:150359

Member Function Documentation

◆ Init()

void duckdb::ARTBuilder::Init ( Node & node,
const idx_t end )
inline

Initialize the ART builder by passing a reference to the root node.

150338 {
150339 s.emplace(node, 0, end, 0);
150340 }
stack< NodeEntry > s
The stack. While merging, NodeEntry elements are pushed onto of the stack.
Definition duckdb.cpp:150365
Here is the caller graph for this function:

◆ Build()

ARTConflictType duckdb::ARTBuilder::Build ( )

Build the ART starting at the first entry in the stack.

152660 {
152661 while (!s.empty()) {
152662 // Copy the entry so we can pop it.
152663 auto entry = s.top();
152664 s.pop();
152665
152666 D_ASSERT(entry.start < keys.size());
152667 D_ASSERT(entry.end < keys.size());
152668 D_ASSERT(entry.start <= entry.end);
152669
152670 auto &start = keys[entry.start];
152671 auto &end = keys[entry.end];
152672 D_ASSERT(start.len != 0);
152673
152674 // Increment the depth until we reach a leaf or find a mismatching byte.
152675 auto prefix_depth = entry.depth;
152676 while (start.len != entry.depth && start.ByteMatches(end, entry.depth)) {
152677 entry.depth++;
152678 }
152679
152680 // True, if we reached a leaf: all bytes of start_key and end_key match.
152681 if (start.len == entry.depth) {
152682 // Get the number of row IDs in the leaf.
152683 auto row_id_count = entry.end - entry.start + 1;
152684 if (art.IsUnique() && row_id_count != 1) {
152685 return ARTConflictType::CONSTRAINT;
152686 }
152687
152688 reference<Node> ref(entry.node);
152689 auto count = UnsafeNumericCast<idx_t>(start.len - prefix_depth);
152690 Prefix::New(art, ref, start, prefix_depth, count);
152691
152692 // Inline the row ID.
152693 if (row_id_count == 1) {
152694 Leaf::New(ref, row_ids[entry.start].GetRowId());
152695 continue;
152696 }
152697
152698 // Loop and insert the row IDs.
152699 // We cannot iterate into the nested leaf with the builder
152700 // because row IDs are not sorted.
152701 for (idx_t i = entry.start; i < entry.start + row_id_count; i++) {
152702 ARTOperator::Insert(arena, art, ref, row_ids[i], 0, row_ids[i], GateStatus::GATE_SET, DeleteIndexInfo(),
152703 IndexAppendMode::DEFAULT);
152704 }
152705 ref.get().SetGateStatus(GateStatus::GATE_SET);
152706 continue;
152707 }
152708
152709 // Create the prefix. Returns early, if the prefix_length is zero.
152710 reference<Node> ref(entry.node);
152711 auto prefix_length = entry.depth - prefix_depth;
152712 Prefix::New(art, ref, start, prefix_depth, prefix_length);
152713
152714 vector<idx_t> child_offsets;
152715 child_offsets.emplace_back(entry.start);
152716 for (idx_t i = entry.start + 1; i <= entry.end; i++) {
152717 if (keys[i - 1].data[entry.depth] != keys[i].data[entry.depth]) {
152718 child_offsets.emplace_back(i);
152719 }
152720 }
152721
152722 // Create a new node containing the children.
152723 Node::New(art, ref, Node::GetNodeType(child_offsets.size()));
152724 auto start_offset = child_offsets[0];
152725 for (idx_t i = 1; i <= child_offsets.size(); i++) {
152726 auto child_byte = keys[start_offset].data[entry.depth];
152727 // FIXME: Improve performance by either returning a reference to the child directly,
152728 // FIXME: or by calling InsertChild after processing the child (at the end of the stack loop).
152729 Node::InsertChild(art, ref, child_byte);
152730 auto child = ref.get().Node::GetChildMutable(art, child_byte, true);
152731 auto end_offset = i != child_offsets.size() ? child_offsets[i] - 1 : entry.end;
152732 s.emplace(*child, start_offset, end_offset, entry.depth + 1);
152733 start_offset = end_offset + 1;
152734 }
152735 }
152736
152737 // We exhausted the stack.
152738 return ARTConflictType::NO_CONFLICT;
152739}
static ARTConflictType Insert(ArenaAllocator &arena, ART &art, Node &node, const ARTKey &key, idx_t depth, const ARTKey &row_id, GateStatus status, DeleteIndexInfo delete_index_info, const IndexAppendMode append_mode)
Definition duckdb.cpp:150573
static void New(Node &node, const row_t row_id)
Inline a row ID into a node pointer.
Definition duckdb.cpp:154285
static void New(ART &art, Node &node, const NType type)
Get a new pointer to a node and initialize it.
Definition duckdb.cpp:154594
static NType GetNodeType(const idx_t count)
Returns the node type for a count.
Definition duckdb.cpp:154879
static void InsertChild(ART &art, Node &node, const uint8_t byte, const Node child=Node())
Insert the child at byte.
Definition duckdb.cpp:154714
static void New(ART &art, reference< Node > &ref, const ARTKey &key, const idx_t depth, idx_t count)
Get a new list of prefix nodes. The node reference holds the child of the last prefix node.
Definition duckdb.cpp:155477
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
Here is the call graph for this function:
Here is the caller graph for this function:

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