Use Symbol to get frame value

Summary:
Since we always use the symbol position to read from frame, it's more
convenient for `Frame::operator[]` to accept `Symbol` instead of `int`.

Reviewers: florijan, mislav.bradac, buda

Reviewed By: florijan, buda

Differential Revision: https://phabricator.memgraph.io/D129
This commit is contained in:
Teon Banek 2017-03-15 15:18:42 +01:00
parent 74991c8289
commit ffd399906a
4 changed files with 8 additions and 11 deletions

View File

@ -86,7 +86,7 @@ class Engine {
while (cursor->Pull(frame, symbol_table)) {
std::vector<TypedValue> values;
for (auto &symbol : symbols)
values.emplace_back(frame[symbol.position_]);
values.emplace_back(frame[symbol]);
stream.Result(values);
}

View File

@ -14,8 +14,8 @@ class Frame {
public:
Frame(int size) : size_(size), elems_(size_) {}
auto &operator[](int pos) { return elems_[pos]; }
const auto &operator[](int pos) const { return elems_[pos]; }
auto &operator[](const Symbol &symbol) { return elems_[symbol.position_]; }
const auto &operator[](const Symbol &symbol) const { return elems_[symbol.position_]; }
private:
int size_;
@ -45,11 +45,11 @@ class ExpressionEvaluator : public TreeVisitorBase {
void PostVisit(NamedExpression &named_expression) override {
auto symbol = symbol_table_[named_expression];
frame_[symbol.position_] = PopBack();
frame_[symbol] = PopBack();
}
void Visit(Identifier &ident) override {
result_stack_.push_back(frame_[symbol_table_[ident].position_]);
result_stack_.push_back(frame_[symbol_table_[ident]]);
}
void PostVisit(PropertyLookup &property_lookup) override {

View File

@ -41,8 +41,7 @@ class ScanAll : public LogicalOperator {
bool Pull(Frame& frame, SymbolTable& symbol_table) override {
if (vertices_it_ == vertices_.end()) return false;
frame[symbol_table[*self_.node_atom->identifier_].position_] =
*vertices_it_++;
frame[symbol_table[*self_.node_atom->identifier_]] = *vertices_it_++;
return true;
}
@ -80,8 +79,7 @@ class NodeFilter : public LogicalOperator {
bool Pull(Frame& frame, SymbolTable& symbol_table) override {
while (input_cursor_->Pull(frame, symbol_table)) {
const VertexAccessor& vertex =
frame[self_.input_symbol_.position_].Value<VertexAccessor>();
const auto &vertex = frame[self_.input_symbol_].Value<VertexAccessor>();
if (VertexPasses(vertex, frame, symbol_table)) return true;
}
return false;
@ -105,7 +103,6 @@ class NodeFilter : public LogicalOperator {
!comparison_result.Value<bool>())
return false;
}
return true;
}
};

View File

@ -46,7 +46,7 @@ auto CollectProduce(std::shared_ptr<Produce> produce, SymbolTable &symbol_table,
auto cursor = produce->MakeCursor(db_accessor);
while (cursor->Pull(frame, symbol_table)) {
std::vector<TypedValue> values;
for (auto &symbol : symbols) values.emplace_back(frame[symbol.position_]);
for (auto &symbol : symbols) values.emplace_back(frame[symbol]);
stream.Result(values);
}