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

Public Member Functions

 Prefix (const ART &art, const Node ptr_p, const bool is_mutable=false, const bool set_in_memory=false)
 Prefix (FixedSizeAllocator &allocator, const Node ptr_p, const idx_t count)

Static Public Member Functions

static uint8_t GetByte (const ART &art, const Node &node, const uint8_t pos)
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.
static void Concat (ART &art, Node &parent, Node &node4, const Node child, uint8_t byte, const GateStatus node4_status, const GateStatus status)
 Concatenates parent -> prev_node4 -> child.
static void Reduce (ART &art, Node &node, const idx_t pos)
static GateStatus Split (ART &art, reference< Node > &node, Node &child, const uint8_t pos)

Public Attributes

data_ptr_t data
Node * ptr
bool in_memory

Static Public Attributes

static constexpr NType PREFIX = NType::PREFIX
static constexpr uint8_t ROW_ID_SIZE = sizeof(row_t)
static constexpr uint8_t ROW_ID_COUNT = ROW_ID_SIZE - 1
static constexpr uint8_t DEPRECATED_COUNT = 15
static constexpr uint8_t METADATA_SIZE = sizeof(Node) + 1

Private Member Functions

Prefix Append (ART &art, const uint8_t byte)
void Append (ART &art, Node other)
Prefix TransformToDeprecatedAppend (ART &art, FixedSizeAllocator &allocator, uint8_t byte)

Static Private Member Functions

static Prefix NewInternal (ART &art, Node &node, const data_ptr_t data, const uint8_t count, const idx_t offset)
static Prefix GetTail (ART &art, const Node &node)
static void ConcatInternal (ART &art, Node &parent, Node &node4, const Node child, uint8_t byte, const GateStatus status)
static void ConcatNode4WasGate (ART &art, Node &node4, const Node child, uint8_t byte)
static void ConcatChildIsGate (ART &art, Node &parent, Node &node4, const Node child, uint8_t byte)
static void ConcatOutsideGate (ART &art, Node &parent, Node &node4, const Node child, uint8_t byte)
template<class F, class NODE>
static void Iterator (ART &art, reference< NODE > &ref, const bool exit_gate, const bool is_mutable, F &&lambda)

Detailed Description

Prefix is a wrapper class to access a prefix. The prefix contains up to the ART's prefix size bytes and an additional byte for the count. It also contains a Node pointer to a child node.

Constructor & Destructor Documentation

◆ Prefix() [1/2]

duckdb::Prefix::Prefix ( const ART & art,
const Node ptr_p,
const bool is_mutable = false,
const bool set_in_memory = false )
155436 {
155437 if (!set_in_memory) {
155438 data = Node::GetAllocator(art, PREFIX).Get(ptr_p, is_mutable);
155439 } else {
155440 data = Node::GetAllocator(art, PREFIX).GetIfLoaded(ptr_p);
155441 if (!data) {
155442 ptr = nullptr;
155443 in_memory = false;
155444 return;
155445 }
155446 }
155447 ptr = reinterpret_cast<Node *>(data + art.PrefixCount() + 1);
155448 in_memory = true;
155449}
unsafe_optional_ptr< T > GetIfLoaded(const IndexPointer ptr)
Definition duckdb.cpp:11742
unsafe_optional_ptr< T > Get(const IndexPointer ptr, const bool dirty=true)
Definition duckdb.cpp:11710
static FixedSizeAllocator & GetAllocator(const ART &art, const NType type)
Get a reference to the allocator.
Definition duckdb.cpp:154663

◆ Prefix() [2/2]

duckdb::Prefix::Prefix ( FixedSizeAllocator & allocator,
const Node ptr_p,
const idx_t count )
155451 {
155452 data = allocator.Get(ptr_p, true);
155453 ptr = reinterpret_cast<Node *>(data + count + 1);
155454 in_memory = true;
155455}

Member Function Documentation

◆ GetByte()

uint8_t duckdb::Prefix::GetByte ( const ART & art,
const Node & node,
const uint8_t pos )
static
155457 {
155458 D_ASSERT(node.GetType() == PREFIX);
155459 Prefix prefix(art, node);
155460 return prefix.data[pos];
155461}

◆ New()

void duckdb::Prefix::New ( ART & art,
reference< Node > & ref,
const ARTKey & key,
const idx_t depth,
idx_t count )
static

Get a new list of prefix nodes. The node reference holds the child of the last prefix node.

155477 {
155478 idx_t offset = 0;
155479
155480 while (count) {
155481 auto min = MinValue(UnsafeNumericCast<idx_t>(art.PrefixCount()), count);
155482 auto this_count = UnsafeNumericCast<uint8_t>(min);
155483 auto prefix = NewInternal(art, ref, key.data, this_count, offset + depth);
155484
155485 ref = *prefix.ptr;
155486 offset += this_count;
155487 count -= this_count;
155488 }
155489}
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:

◆ Concat()

void duckdb::Prefix::Concat ( ART & art,
Node & parent,
Node & node4,
const Node child,
uint8_t byte,
const GateStatus node4_status,
const GateStatus status )
static

Concatenates parent -> prev_node4 -> child.

155492 {
155493 // We have four situations from which we enter here:
155494 // 1: PREFIX (parent) - Node4 (prev_node4) - PREFIX (child) - INLINED_LEAF, or
155495 // 2: PREFIX (parent) - Node4 (prev_node4) - INLINED_LEAF (child), or
155496 // 3: Node (parent) - Node4 (prev_node4) - PREFIX (child) - INLINED_LEAF, or
155497 // 4: Node (parent) - Node4 (prev_node4) - INLINED_LEAF (child).
155498
155499 D_ASSERT(!parent.IsAnyLeaf());
155500 D_ASSERT(child.HasMetadata());
155501
155502 // The Node4 was a gate.
155503 if (node4_status == GateStatus::GATE_SET) {
155504 D_ASSERT(parent.GetGateStatus() == GateStatus::GATE_NOT_SET);
155505 D_ASSERT(child.GetGateStatus() == GateStatus::GATE_NOT_SET);
155506 ConcatNode4WasGate(art, node4, child, byte);
155507 return;
155508 }
155509
155510 // The child is a gate.
155511 if (child.GetGateStatus() == GateStatus::GATE_SET) {
155512 D_ASSERT(node4_status == GateStatus::GATE_NOT_SET);
155513 ConcatChildIsGate(art, parent, node4, child, byte);
155514 return;
155515 }
155516 ConcatInternal(art, parent, node4, child, byte, status);
155517}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Reduce()

void duckdb::Prefix::Reduce ( ART & art,
Node & node,
const idx_t pos )
static

Removes up to pos bytes from the prefix. Shifts all subsequent bytes by pos. Frees empty nodes.

155519 {
155520 D_ASSERT(node.HasMetadata());
155521 D_ASSERT(pos < art.PrefixCount());
155522
155523 // We always reduce by at least one byte,
155524 // thus, if the prefix was a gate, it no longer is.
155525 node.SetGateStatus(GateStatus::GATE_NOT_SET);
155526
155527 Prefix prefix(art, node);
155528 if (pos == idx_t(prefix.data[art.PrefixCount()] - 1)) {
155529 auto next = *prefix.ptr;
155530 Node::FreeNode(art, node);
155531 node = next;
155532 return;
155533 }
155534
155535 // FIXME: Copy into new prefix (chain) instead of shifting.
155536 for (idx_t i = 0; i < art.PrefixCount() - pos - 1; i++) {
155537 prefix.data[i] = prefix.data[pos + i + 1];
155538 }
155539
155540 prefix.data[art.PrefixCount()] -= pos + 1;
155541 prefix.Append(art, *prefix.ptr);
155542}
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:

◆ Split()

GateStatus duckdb::Prefix::Split ( ART & art,
reference< Node > & node,
Node & child,
const uint8_t pos )
static

Splits the prefix at pos. node references the node that replaces the split byte. child references the remaining node after the split. Returns GATE_SET, if a gate node was freed, else GATE_NOT_SET. If it returns GATE_SET, then the caller must set the gate for the node replacing the split byte, after its creation.

155544 {
155545 D_ASSERT(node.get().HasMetadata());
155546
155547 Prefix prefix(art, node, true);
155548
155549 // The split is at the last prefix byte, and the prefix is full.
155550 // We decrease the count and return.
155551 // We get:
155552 // [this prefix minus its last byte] ->
155553 // [new node at split byte] ->
155554 // [child at split byte: prefix.ptr].
155555 if (pos + 1 == art.PrefixCount()) {
155556 prefix.data[art.PrefixCount()]--;
155557 node = *prefix.ptr;
155558 child = *prefix.ptr;
155559 return GateStatus::GATE_NOT_SET;
155560 }
155561
155562 if (pos + 1 < prefix.data[art.PrefixCount()]) {
155563 // The split is not at the last prefix byte.
155564 // We get:
155565 // [this prefix minus split byte, minus remaining bytes] ->
155566 // [new node at split byte] ->
155567 // [child with remaining bytes, and possibly remaining prefix nodes].
155568
155569 // Create a new prefix and
155570 // 1. copy the remaining bytes of this prefix.
155571 // 2. append remaining prefix nodes.
155572 auto new_prefix = NewInternal(art, child, nullptr, 0, 0);
155573 new_prefix.data[art.PrefixCount()] = prefix.data[art.PrefixCount()] - pos - 1;
155574 memcpy(new_prefix.data, prefix.data + pos + 1, new_prefix.data[art.PrefixCount()]);
155575
155576 if (prefix.ptr->GetType() == PREFIX && prefix.ptr->GetGateStatus() == GateStatus::GATE_NOT_SET) {
155577 new_prefix.Append(art, *prefix.ptr);
155578 } else {
155579 *new_prefix.ptr = *prefix.ptr;
155580 }
155581
155582 } else {
155583 D_ASSERT(pos + 1 == prefix.data[art.PrefixCount()]);
155584 // The split is at the last prefix byte, but the prefix is not full.
155585 // There are no other bytes or prefixes after the split.
155586 // We get:
155587 // [this prefix minus split byte (can be its only byte, then we free it)] ->
155588 // [new node at split byte] ->
155589 // [child at split byte: prefix.ptr].
155590 child = *prefix.ptr;
155591 }
155592
155593 // Set the new count of this node (can be empty).
155594 prefix.data[art.PrefixCount()] = pos;
155595
155596 // No bytes left before the split, free this node.
155597 if (pos == 0) {
155598 auto old_status = node.get().GetGateStatus();
155599 Node::FreeNode(art, node);
155600 return old_status;
155601 }
155602
155603 // There are bytes left before the split.
155604 // The subsequent node replaces the split byte.
155605 node = *prefix.ptr;
155606 return GateStatus::GATE_NOT_SET;
155607}
Here is the call graph for this function:

◆ NewInternal()

Prefix duckdb::Prefix::NewInternal ( ART & art,
Node & node,
const data_ptr_t data,
const uint8_t count,
const idx_t offset )
staticprivate
155463 {
155464 node = Node::GetAllocator(art, PREFIX).New();
155465 node.SetMetadata(static_cast<uint8_t>(PREFIX));
155466
155467 Prefix prefix(art, node, true);
155468 prefix.data[art.PrefixCount()] = count;
155469 if (data) {
155470 D_ASSERT(count);
155471 memcpy(prefix.data, data + offset, count);
155472 }
155473 prefix.ptr->Clear();
155474 return prefix;
155475}
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
::uint8_t uint8_t

◆ GetTail()

Prefix duckdb::Prefix::GetTail ( ART & art,
const Node & node )
staticprivate
155641 {
155642 Prefix prefix(art, node, true);
155643 while (prefix.ptr->GetType() == PREFIX) {
155644 prefix = Prefix(art, *prefix.ptr, true);
155645 }
155646 return prefix;
155647}

◆ ConcatInternal()

void duckdb::Prefix::ConcatInternal ( ART & art,
Node & parent,
Node & node4,
const Node child,
uint8_t byte,
const GateStatus status )
staticprivate
155650 {
155651 if (child.GetType() == NType::LEAF_INLINED) {
155652 if (status == GateStatus::GATE_SET) {
155653 if (parent.GetType() == NType::PREFIX) {
155654 // The parent only contained the Node4, so we can now inline 'all the way up',
155655 // and the gate is no longer nested.
155656 while (parent.GetType() == NType::PREFIX) {
155657 Prefix prefix(art, parent, true);
155658 auto temp = *prefix.ptr;
155659 Node::FreeNode(art, parent);
155660 parent = temp;
155661 }
155662 parent = child;
155663 return;
155664 }
155665 // The parent is any node inside the gate.
155666 // Inside gates, inlined row IDs are not prefixed,
155667 // so we directly inline into the previous Node4.
155668 node4 = child;
155669 return;
155670 }
155671
155672 // Not inside a gate.
155673 if (parent.GetType() == NType::PREFIX) {
155674 // Append the byte to the prefix, and then inline the child.
155675 auto tail = GetTail(art, parent);
155676 tail = tail.Append(art, byte);
155677 *tail.ptr = child;
155678 return;
155679 }
155680
155681 auto prefix = NewInternal(art, node4, &byte, 1, 0);
155682 *prefix.ptr = child;
155683 return;
155684 }
155685
155686 // The child is not inlined.
155687 if (parent.GetType() == NType::PREFIX) {
155688 // Append the byte to the prefix.
155689 auto tail = GetTail(art, parent);
155690 tail = tail.Append(art, byte);
155691
155692 // Append the child to the prefix.
155693 if (child.GetType() == NType::PREFIX) {
155694 tail.Append(art, child);
155695 return;
155696 }
155697 *tail.ptr = child;
155698 return;
155699 }
155700
155701 // The child is not inlined, and the parent is not a prefix.
155702 auto prefix = NewInternal(art, node4, &byte, 1, 0);
155703 if (child.GetType() == NType::PREFIX) {
155704 prefix.Append(art, child);
155705 return;
155706 }
155707 *prefix.ptr = child;
155708}

◆ ConcatNode4WasGate()

void duckdb::Prefix::ConcatNode4WasGate ( ART & art,
Node & node4,
const Node child,
uint8_t byte )
staticprivate
155710 {
155711 D_ASSERT(child.HasMetadata());
155712
155713 if (child.GetType() == NType::LEAF_INLINED) {
155714 // Inside gates, inlined row IDs are not prefixed.
155715 // The child is inlined, so we inline into the previous Node4.
155716 // There is no longer a nested leaf.
155717 node4 = child;
155718 return;
155719 }
155720
155721 if (child.GetType() == PREFIX) {
155722 // At least one more row ID in this gate and the child is a prefix.
155723 // We create a new prefix of length one containing the remaining byte.
155724 // Then, we append the child prefix.
155725 auto prefix = NewInternal(art, node4, &byte, 1, 0);
155726 prefix.ptr->Clear();
155727 prefix.Append(art, child);
155728 node4.SetGateStatus(GateStatus::GATE_SET);
155729 return;
155730 }
155731 // At least one more row ID in this gate and the child is not a prefix.
155732 // We create a new prefix of length one containing the remaining byte.
155733 // then, we append the child.
155734 auto prefix = NewInternal(art, node4, &byte, 1, 0);
155735 *prefix.ptr = child;
155736 node4.SetGateStatus(GateStatus::GATE_SET);
155737}

◆ ConcatChildIsGate()

void duckdb::Prefix::ConcatChildIsGate ( ART & art,
Node & parent,
Node & node4,
const Node child,
uint8_t byte )
staticprivate
155739 {
155740 if (parent.GetType() != PREFIX) {
155741 // Create a new prefix at the former position of the Node4,
155742 // and point it to the gate.
155743 auto prefix = NewInternal(art, node4, &byte, 1, 0);
155744 *prefix.ptr = child;
155745 return;
155746 }
155747
155748 // The parent is a prefix (chain), so we need to append the byte to its tail.
155749 auto tail = GetTail(art, parent);
155750 tail = tail.Append(art, byte);
155751 *tail.ptr = child;
155752}

◆ Append() [1/2]

Prefix duckdb::Prefix::Append ( ART & art,
const uint8_t byte )
private
155609 {
155610 if (data[art.PrefixCount()] != art.PrefixCount()) {
155611 data[data[art.PrefixCount()]] = byte;
155612 data[art.PrefixCount()]++;
155613 return *this;
155614 }
155615
155616 auto prefix = NewInternal(art, *ptr, nullptr, 0, 0);
155617 return prefix.Append(art, byte);
155618}

◆ Append() [2/2]

void duckdb::Prefix::Append ( ART & art,
Node other )
private
155620 {
155621 D_ASSERT(other.HasMetadata());
155622
155623 Prefix prefix = *this;
155624 while (other.GetType() == PREFIX) {
155625 if (other.GetGateStatus() == GateStatus::GATE_SET) {
155626 *prefix.ptr = other;
155627 return;
155628 }
155629
155630 Prefix other_prefix(art, other, true);
155631 for (idx_t i = 0; i < other_prefix.data[art.PrefixCount()]; i++) {
155632 prefix = prefix.Append(art, other_prefix.data[i]);
155633 }
155634
155635 *prefix.ptr = *other_prefix.ptr;
155636 Node::FreeNode(art, other);
155637 other = *prefix.ptr;
155638 }
155639}

◆ TransformToDeprecatedAppend()

Prefix duckdb::Prefix::TransformToDeprecatedAppend ( ART & art,
FixedSizeAllocator & allocator,
uint8_t byte )
private
155754 {
155755 if (data[DEPRECATED_COUNT] != DEPRECATED_COUNT) {
155756 data[data[DEPRECATED_COUNT]] = byte;
155757 data[DEPRECATED_COUNT]++;
155758 return *this;
155759 }
155760
155761 *ptr = allocator.New();
155762 ptr->SetMetadata(static_cast<uint8_t>(PREFIX));
155763 Prefix prefix(allocator, *ptr, DEPRECATED_COUNT);
155764 return prefix.TransformToDeprecatedAppend(art, allocator, byte);
155765}

◆ Iterator()

template<class F, class NODE>
void duckdb::Prefix::Iterator ( ART & art,
reference< NODE > & ref,
const bool exit_gate,
const bool is_mutable,
F && lambda )
inlinestaticprivate
57913 {
57914 while (ref.get().HasMetadata() && ref.get().GetType() == PREFIX) {
57915 Prefix prefix(art, ref, is_mutable);
57916 lambda(prefix);
57917
57918 ref = *prefix.ptr;
57919 if (exit_gate && ref.get().GetGateStatus() == GateStatus::GATE_SET) {
57920 break;
57921 }
57922 }
57923 }

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