Merge pull request #632 from memgraph/MG-improve-parameters

This commit is contained in:
János Benjamin Antal 2022-11-02 14:06:30 +01:00 committed by GitHub
commit c92c795b1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 31 deletions

View File

@ -12,8 +12,8 @@
#pragma once #pragma once
#include <algorithm> #include <algorithm>
#include <unordered_map>
#include <utility> #include <utility>
#include <vector>
#include "storage/v3/property_value.hpp" #include "storage/v3/property_value.hpp"
#include "utils/logging.hpp" #include "utils/logging.hpp"
@ -32,7 +32,7 @@ struct Parameters {
* @param position Token position in query of value. * @param position Token position in query of value.
* @param value * @param value
*/ */
void Add(int position, const storage::v3::PropertyValue &value) { storage_.emplace_back(position, value); } void Add(int position, const storage::v3::PropertyValue &value) { storage_.emplace(position, value); }
/** /**
* Returns the value found for the given token position. * Returns the value found for the given token position.
@ -41,23 +41,11 @@ struct Parameters {
* @return Value for the given token position. * @return Value for the given token position.
*/ */
const storage::v3::PropertyValue &AtTokenPosition(int position) const { const storage::v3::PropertyValue &AtTokenPosition(int position) const {
auto found = std::find_if(storage_.begin(), storage_.end(), [&](const auto &a) { return a.first == position; }); auto found = storage_.find(position);
MG_ASSERT(found != storage_.end(), "Token position must be present in container"); MG_ASSERT(found != storage_.end(), "Token position must be present in container");
return found->second; return found->second;
} }
/**
* Returns the position-th stripped value. Asserts that this
* container has at least (position + 1) elements.
*
* @param position Which stripped param is sought.
* @return Token position and value for sought param.
*/
const std::pair<int, storage::v3::PropertyValue> &At(int position) const {
MG_ASSERT(position < static_cast<int>(storage_.size()), "Invalid position");
return storage_[position];
}
/** Returns the number of arguments in this container */ /** Returns the number of arguments in this container */
auto size() const { return storage_.size(); } auto size() const { return storage_.size(); }
@ -65,7 +53,7 @@ struct Parameters {
auto end() const { return storage_.end(); } auto end() const { return storage_.end(); }
private: private:
std::vector<std::pair<int, storage::v3::PropertyValue>> storage_; std::unordered_map<int, storage::v3::PropertyValue> storage_;
}; };
} // namespace memgraph::query::v2 } // namespace memgraph::query::v2

View File

@ -42,7 +42,7 @@ struct Parameters {
* @param position Token position in query of value. * @param position Token position in query of value.
* @param value * @param value
*/ */
void Add(int position, const storage::v3::PropertyValue &value) { storage_.emplace_back(position, value); } void Add(int position, const storage::v3::PropertyValue &value) { storage_.emplace(position, value); }
/** /**
* Returns the value found for the given token position. * Returns the value found for the given token position.
@ -51,23 +51,11 @@ struct Parameters {
* @return Value for the given token position. * @return Value for the given token position.
*/ */
const storage::v3::PropertyValue &AtTokenPosition(int position) const { const storage::v3::PropertyValue &AtTokenPosition(int position) const {
auto found = std::find_if(storage_.begin(), storage_.end(), [&](const auto &a) { return a.first == position; }); auto found = storage_.find(position);
MG_ASSERT(found != storage_.end(), "Token position must be present in container"); MG_ASSERT(found != storage_.end(), "Token position must be present in container");
return found->second; return found->second;
} }
/**
* Returns the position-th stripped value. Asserts that this
* container has at least (position + 1) elements.
*
* @param position Which stripped param is sought.
* @return Token position and value for sought param.
*/
const std::pair<int, storage::v3::PropertyValue> &At(int position) const {
MG_ASSERT(position < static_cast<int>(storage_.size()), "Invalid position");
return storage_[position];
}
/** Returns the number of arguments in this container */ /** Returns the number of arguments in this container */
auto size() const { return storage_.size(); } auto size() const { return storage_.size(); }
@ -75,7 +63,7 @@ struct Parameters {
auto end() const { return storage_.end(); } auto end() const { return storage_.end(); }
private: private:
std::vector<std::pair<int, storage::v3::PropertyValue>> storage_; std::unordered_map<int, storage::v3::PropertyValue> storage_;
}; };
struct EvaluationContext { struct EvaluationContext {