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

Public Member Functions

 Leaf (const Leaf &)=delete
Leaf & operator= (const Leaf &)=delete
void DeprecatedVerifyAllocations (ART &art, unordered_map< uint8_t, idx_t > &node_counts) const
 Count the number of leaves.

Static Public Member Functions

static void New (Node &node, const row_t row_id)
 Inline a row ID into a node pointer.
static void MergeInlined (ArenaAllocator &arena, ART &art, Node &left, Node &right, GateStatus status, idx_t depth)
 Merge two inlined leaf nodes.
static void TransformToNested (ART &art, Node &node)
 Transforms a deprecated leaf to a nested leaf.
static void TransformToDeprecated (ART &art, Node &node)
 Transforms a nested leaf to a deprecated leaf.
static void DeprecatedFree (ART &art, Node &node)
 Frees the linked list of leaves.
static bool DeprecatedGetRowIds (ART &art, const Node &node, set< row_t > &row_ids, const idx_t max_count)
static void DeprecatedVacuum (ART &art, Node &node)
 Vacuums the linked list of leaves.
static void DeprecatedVerify (ART &art, const Node &node)
 Traverses and verifies the linked list of leaves.
static string DeprecatedToString (ART &art, const Node &node, const ToStringOptions &options)

Static Public Attributes

static constexpr NType LEAF = NType::LEAF
static constexpr NType INLINED = NType::LEAF_INLINED
static constexpr uint8_t LEAF_SIZE = 4

Private Attributes

uint8_t count
row_t row_ids [LEAF_SIZE]
Node ptr

Detailed Description

There are three types of leaves.

  1. LEAF_INLINED: Inlines a row ID in a Node pointer.
  2. LEAF: Deprecated. A list of Leaf nodes containing row IDs.
  3. Nested leaves indicated by gate nodes. If an ART key contains multiple row IDs, then we use the row IDs as keys and create a nested ART behind the gate node. As row IDs are always unique, these nested ARTs never contain duplicates themselves.

Member Function Documentation

◆ New()

void duckdb::Leaf::New ( Node & node,
const row_t row_id )
static

Inline a row ID into a node pointer.

154285 {
154286 D_ASSERT(row_id < MAX_ROW_ID_LOCAL);
154287 node.Clear();
154288 node.SetMetadata(static_cast<uint8_t>(INLINED));
154289 node.SetRowId(row_id);
154290}
::uint8_t uint8_t
const row_t MAX_ROW_ID_LOCAL
Transaction-local row IDs start at MAX_ROW_ID.
Definition duckdb.cpp:50302
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MergeInlined()

void duckdb::Leaf::MergeInlined ( ArenaAllocator & arena,
ART & art,
Node & left,
Node & right,
GateStatus status,
idx_t depth )
static

Merge two inlined leaf nodes.

154292 {
154293 D_ASSERT(left.GetType() == NType::LEAF_INLINED);
154294 D_ASSERT(right.GetType() == NType::LEAF_INLINED);
154295
154296 status = status == GateStatus::GATE_NOT_SET ? GateStatus::GATE_SET : GateStatus::GATE_NOT_SET;
154297 if (status == GateStatus::GATE_SET) {
154298 // Case 1: We are outside a nested leaf,
154299 // so we create a nested leaf.
154300 depth = 0;
154301 }
154302 // Otherwise, case 2: we are in a nested leaf with two 'compressed' prefixes.
154303 // A 'compressed prefix' is an inlined leaf that could've been expanded to
154304 // a prefix with an inlined leaf as its only child.
154305
154306 // Get the corresponding row IDs and their ART keys.
154307 auto left_row_id = left.GetRowId();
154308 auto right_row_id = right.GetRowId();
154309 auto left_key = ARTKey::CreateARTKey<row_t>(arena, left_row_id);
154310 auto right_key = ARTKey::CreateARTKey<row_t>(arena, right_row_id);
154311
154312 auto pos = left_key.GetMismatchPos(right_key, depth);
154313
154314 left.Clear();
154315 reference<Node> node(left);
154316 if (pos != depth) {
154317 // The row IDs share a prefix.
154318 Prefix::New(art, node, left_key, depth, pos - depth);
154319 }
154320
154321 auto left_byte = left_key.data[pos];
154322 auto right_byte = right_key.data[pos];
154323
154324 if (pos == Prefix::ROW_ID_COUNT) {
154325 // The row IDs differ on the last byte.
154326 Node7Leaf::New(art, node);
154327 Node7Leaf::InsertByte(art, node, left_byte);
154328 Node7Leaf::InsertByte(art, node, right_byte);
154329 left.SetGateStatus(status);
154330 return;
154331 }
154332
154333 // Create and insert the (compressed) children.
154334 // We inline directly into the node, instead of creating prefixes
154335 // with a single inlined leaf as their child.
154336 Node4::New(art, node);
154337
154338 Node left_child;
154339 Leaf::New(left_child, left_row_id);
154340 Node4::InsertChild(art, node, left_byte, left_child);
154341
154342 Node right_child;
154343 Leaf::New(right_child, right_row_id);
154344 Node4::InsertChild(art, node, right_byte, right_child);
154345
154346 left.SetGateStatus(status);
154347}
static NodeHandle< BaseLeaf > New(ART &art, Node &node)
Definition duckdb.cpp:150900
static NodeHandle< BaseNode > New(ART &art, Node &node)
Definition duckdb.cpp:57961
static void New(Node &node, const row_t row_id)
Inline a row ID into a node pointer.
Definition duckdb.cpp:154285
static void InsertChild(ART &art, Node &node, const uint8_t byte, const Node child)
Insert a child at byte.
Definition duckdb.cpp:153682
static void InsertByte(ART &art, Node &node, const uint8_t byte)
Insert a byte.
Definition duckdb.cpp:153489
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
double depth(InputArray R, InputArray t, InputArray X)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TransformToNested()

void duckdb::Leaf::TransformToNested ( ART & art,
Node & node )
static

Transforms a deprecated leaf to a nested leaf.

154349 {
154350 D_ASSERT(node.GetType() == LEAF);
154351
154352 ArenaAllocator arena(Allocator::Get(art.db));
154353 Node root = Node();
154354
154355 // Move all row IDs into the nested leaf.
154356 reference<const Node> leaf_ref(node);
154357 while (leaf_ref.get().HasMetadata()) {
154358 auto &leaf = Node::Ref<const Leaf>(art, leaf_ref, LEAF);
154359 for (uint8_t i = 0; i < leaf.count; i++) {
154360 auto row_id = ARTKey::CreateARTKey<row_t>(arena, leaf.row_ids[i]);
154361 auto conflict_type = ARTOperator::Insert(arena, art, root, row_id, 0, row_id, GateStatus::GATE_SET,
154362 DeleteIndexInfo(), IndexAppendMode::INSERT_DUPLICATES);
154363 if (conflict_type != ARTConflictType::NO_CONFLICT) {
154364 throw InternalException("invalid conflict type in Leaf::TransformToNested");
154365 }
154366 }
154367 leaf_ref = leaf.ptr;
154368 }
154369
154370 root.SetGateStatus(GateStatus::GATE_SET);
154371 DeprecatedFree(art, node);
154372 node = root;
154373}
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 DeprecatedFree(ART &art, Node &node)
Frees the linked list of leaves.
Definition duckdb.cpp:154420
static NODE & Ref(const ART &art, const Node ptr, const NType type)
Get a reference to a node.
Definition duckdb.cpp:11976
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TransformToDeprecated()

void duckdb::Leaf::TransformToDeprecated ( ART & art,
Node & node )
static

Transforms a nested leaf to a deprecated leaf.

154375 {
154376 D_ASSERT(node.GetGateStatus() == GateStatus::GATE_SET || node.GetType() == LEAF);
154377
154378 // Early-out, if we never transformed this leaf.
154379 if (node.GetGateStatus() == GateStatus::GATE_NOT_SET) {
154380 return;
154381 }
154382
154383 // Collect all row IDs and free the nested leaf.
154384 set<row_t> row_ids;
154385 Iterator it(art);
154386 it.FindMinimum(node);
154387 ARTKey empty_key = ARTKey();
154388 RowIdSetOutput output(row_ids, NumericLimits<row_t>().Maximum());
154389 it.Scan(empty_key, output, false);
154390 Node::FreeTree(art, node);
154391 D_ASSERT(row_ids.size() > 1);
154392
154393 // Create the deprecated leaves.
154394 idx_t remaining = row_ids.size();
154395 auto row_ids_it = row_ids.begin();
154396 reference<Node> ref(node);
154397 while (remaining) {
154398 ref.get() = Node::GetAllocator(art, LEAF).New();
154399 ref.get().SetMetadata(static_cast<uint8_t>(LEAF));
154400
154401 auto &leaf = Node::Ref<Leaf>(art, ref, LEAF);
154402 auto min = MinValue(UnsafeNumericCast<idx_t>(LEAF_SIZE), remaining);
154403 leaf.count = UnsafeNumericCast<uint8_t>(min);
154404
154405 for (uint8_t i = 0; i < leaf.count; i++) {
154406 leaf.row_ids[i] = *row_ids_it;
154407 row_ids_it++;
154408 }
154409 remaining -= leaf.count;
154410
154411 ref = leaf.ptr;
154412 leaf.ptr.Clear();
154413 }
154414}
IndexPointer New()
Get a new IndexPointer to a segment, might cause a new buffer allocation.
Definition duckdb.cpp:156189
void SetMetadata(const uint8_t metadata)
Set metadata (Bits 56-63).
Definition duckdb.hpp:22544
static FixedSizeAllocator & GetAllocator(const ART &art, const NType type)
Get a reference to the allocator.
Definition duckdb.cpp:154663
static void FreeTree(ART &art, Node &node)
Free the node and its children.
Definition duckdb.cpp:154628
static softfloat min()
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:

◆ DeprecatedFree()

void duckdb::Leaf::DeprecatedFree ( ART & art,
Node & node )
static

Frees the linked list of leaves.

154420 {
154421 D_ASSERT(node.GetType() == LEAF);
154422 Node next;
154423 while (node.HasMetadata()) {
154424 next = Node::Ref<Leaf>(art, node, LEAF).ptr;
154425 Node::FreeNode(art, node);
154426 node = next;
154427 }
154428 node.Clear();
154429}
static void FreeNode(ART &art, Node &node)
Free the node.
Definition duckdb.cpp:154622
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DeprecatedGetRowIds()

bool duckdb::Leaf::DeprecatedGetRowIds ( ART & art,
const Node & node,
set< row_t > & row_ids,
const idx_t max_count )
static

Fills the row_ids vector with the row IDs of this linked list of leaves. Never pushes more than max_count row IDs.

154431 {
154432 D_ASSERT(node.GetType() == LEAF);
154433
154434 reference<const Node> ref(node);
154435 while (ref.get().HasMetadata()) {
154436 auto &leaf = Node::Ref<const Leaf>(art, ref, LEAF);
154437 if (row_ids.size() + leaf.count > max_count) {
154438 return false;
154439 }
154440 for (uint8_t i = 0; i < leaf.count; i++) {
154441 row_ids.insert(leaf.row_ids[i]);
154442 }
154443 ref = leaf.ptr;
154444 }
154445 return true;
154446}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DeprecatedVacuum()

void duckdb::Leaf::DeprecatedVacuum ( ART & art,
Node & node )
static

Vacuums the linked list of leaves.

154448 {
154449 D_ASSERT(node.HasMetadata());
154450 D_ASSERT(node.GetType() == LEAF);
154451
154452 auto &allocator = Node::GetAllocator(art, LEAF);
154453 reference<Node> ref(node);
154454 while (ref.get().HasMetadata()) {
154455 if (allocator.NeedsVacuum(ref)) {
154456 ref.get() = allocator.VacuumPointer(ref);
154457 ref.get().SetMetadata(static_cast<uint8_t>(LEAF));
154458 }
154459 auto &leaf = Node::Ref<Leaf>(art, ref, LEAF);
154460 ref = leaf.ptr;
154461 }
154462}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DeprecatedVerify()

void duckdb::Leaf::DeprecatedVerify ( ART & art,
const Node & node )
static

Traverses and verifies the linked list of leaves.

154492 {
154493 D_ASSERT(node.GetType() == LEAF);
154494
154495 reference<const Node> ref(node);
154496
154497 while (ref.get().HasMetadata()) {
154498 auto &leaf = Node::Ref<const Leaf>(art, ref, LEAF);
154499 D_ASSERT(leaf.count <= LEAF_SIZE);
154500 ref = leaf.ptr;
154501 }
154502}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DeprecatedVerifyAllocations()

void duckdb::Leaf::DeprecatedVerifyAllocations ( ART & art,
unordered_map< uint8_t, idx_t > & node_counts ) const

Count the number of leaves.

154504 {
154505 auto idx = Node::GetAllocatorIdx(LEAF);
154506 node_counts[idx]++;
154507
154508 reference<const Node> ref(ptr);
154509 while (ref.get().HasMetadata()) {
154510 auto &leaf = Node::Ref<const Leaf>(art, ref, LEAF);
154511 node_counts[idx]++;
154512 ref = leaf.ptr;
154513 }
154514}
static uint8_t GetAllocatorIdx(const NType type)
Get the index of a node type's allocator.
Definition duckdb.cpp:154667
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DeprecatedToString()

string duckdb::Leaf::DeprecatedToString ( ART & art,
const Node & node,
const ToStringOptions & options )
static

Return string representation of the linked list of leaves. If print_deprecated_leaves is false, returns "[deprecated leaves]" with proper indentation.

154464 {
154465 auto indent = [](string &str, const idx_t n) {
154466 str.append(n, ' ');
154467 };
154468 string str = "";
154469
154470 if (!options.print_deprecated_leaves) {
154471 indent(str, options.indent_level);
154472 str += "[deprecated leaves]\n";
154473 return str;
154474 }
154475
154476 reference<const Node> ref(node);
154477
154478 while (ref.get().HasMetadata()) {
154479 auto &leaf = Node::Ref<const Leaf>(art, ref, LEAF);
154480 indent(str, options.indent_level);
154481 str += "Leaf [count: " + to_string(leaf.count) + ", row IDs: ";
154482 for (uint8_t i = 0; i < leaf.count; i++) {
154483 str += to_string(leaf.row_ids[i]) + "-";
154484 }
154485 str += "]\n";
154486 ref = leaf.ptr;
154487 }
154488
154489 return str;
154490}
std::string to_string(const T &value)
Definition duckdb.cpp:19425
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: