diff options
| author | Marcos Magueta <maguetamarcos@gmail.com> | 2026-06-05 21:40:44 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-06-05 21:40:44 -0300 |
| commit | 5174fc25698cff33b03b5746bf1742e417988f7d (patch) | |
| tree | 232a3acdd9b458de481dbd5cbde889505168c8e8 /src/VM.cpp | |
| parent | 85ed897de3676af866cc619dc700025820c02201 (diff) | |
| download | RNT-5174fc25698cff33b03b5746bf1742e417988f7d.tar.gz RNT-5174fc25698cff33b03b5746bf1742e417988f7d.zip | |
Project C interface, reroute FOL plan enums & format
Diffstat (limited to '')
| -rw-r--r-- | src/VM.cpp | 121 |
1 files changed, 59 insertions, 62 deletions
@@ -1,102 +1,99 @@ #include "VM.h" #include "Types.h" -namespace nt -{ - VM::VM(CursorManager& cursors) : cursors_(cursors) {} +namespace nt { + VM::VM(CursorManager& cursors) : cursors_(cursors) { + } - std::vector<std::string> VM::ResolveArgs(const std::vector<PathArg>& tmpl, Tuple* from) - { + std::vector<std::string> VM::ResolveArgs(const std::vector<PathArg>& tmpl, Tuple* from) { std::vector<std::string> resolved; resolved.reserve(tmpl.size()); - for (const auto& arg : tmpl) - { - if (arg.kind == PathArg::Kind::Const) - { + for (const auto& arg : tmpl) { + if (arg.kind == PathArg::Kind::Const) { resolved.push_back(arg.name); continue; } std::string val; for (const auto& attr : from->attrs()) - if (attr.name == arg.name) { val = attr.value; break; } + if (attr.name == arg.name) { + val = attr.value; + break; + } resolved.push_back(std::move(val)); } return resolved; } - void VM::ResetInner(CursorManager::cursor* c, std::vector<std::string> args) - { - c->args = std::move(args); + void VM::ResetInner(CursorManager::cursor* c, std::vector<std::string> args) { + c->args = std::move(args); c->page.clear(); c->page_position = 0; - c->fetch_offset = 0; - c->exhausted = false; + c->fetch_offset = 0; + c->exhausted = false; } - Tuple* VM::MergeInto(PlanNode* node, Tuple* left, Tuple* right) - { + Tuple* VM::MergeInto(PlanNode* node, Tuple* left, Tuple* right) { std::vector<Attribute> merged; - for (const auto& a : left->attrs()) merged.push_back(a); - for (const auto& a : right->attrs()) merged.push_back(a); + for (const auto& a : left->attrs()) + merged.push_back(a); + for (const auto& a : right->attrs()) + merged.push_back(a); node->join_buffer.emplace(std::move(merged)); return &*node->join_buffer; } - Tuple* VM::Next(PlanNode* node) - { - if (node == nullptr) return nullptr; - - switch (node->op) - { - case PlanNode::Op::SCAN: - return cursors_.Next(node->scan_cursor); + Tuple* VM::Next(PlanNode* node) { + if (node == nullptr) + return nullptr; - case PlanNode::Op::PROJECT: - { - Tuple* next = Next(node->left); - if (next == nullptr) return nullptr; + switch (node->op) { + case Operation::FOL_OPERATION_SCAN: + return cursors_.Next(node->scan_cursor); - std::vector<Attribute> projected; - for (const auto& attr : next->attrs()) - { - if (node->project_attrs.find(attr.name) != node->project_attrs.end()) - projected.push_back(attr); - } + case Operation::FOL_OPERATION_PROJECT: { + Tuple* next = Next(node->left); + if (next == nullptr) + return nullptr; - node->project_buffer.emplace(std::move(projected)); - return &*node->project_buffer; + std::vector<Attribute> projected; + for (const auto& attr : next->attrs()) { + if (node->project_attrs.find(attr.name) != node->project_attrs.end()) + projected.push_back(attr); } - case PlanNode::Op::JOIN: - { - while (true) - { + node->project_buffer.emplace(std::move(projected)); + return &*node->project_buffer; + } + + case Operation::FOL_OPERATION_JOIN: { + while (true) { + if (node->join_left == nullptr) { + node->join_left = Next(node->left); if (node->join_left == nullptr) - { - node->join_left = Next(node->left); - if (node->join_left == nullptr) return nullptr; + return nullptr; - auto args = ResolveArgs(node->right->scan_args, node->join_left); - ResetInner(node->right->scan_cursor, std::move(args)); - } + auto args = ResolveArgs(node->right->scan_args, node->join_left); + ResetInner(node->right->scan_cursor, std::move(args)); + } - Tuple* right = Next(node->right); - if (right != nullptr) - return MergeInto(node, node->join_left, right); + Tuple* right = Next(node->right); + if (right != nullptr) + return MergeInto(node, node->join_left, right); - node->join_left = nullptr; - } + node->join_left = nullptr; } + } - case PlanNode::Op::TAKE: - { - if (node->take_count >= node->take_limit) return nullptr; - Tuple* t = Next(node->left); - if (t) ++node->take_count; - return t; - } + case Operation::FOL_OPERATION_TAKE: { + if (node->take_count >= node->take_limit) + return nullptr; + Tuple* t = Next(node->left); + if (t) + ++node->take_count; + return t; + } } return nullptr; } -} +} // namespace nt |
