diff --git a/src/query/v2/parameters.hpp b/src/query/v2/parameters.hpp index 1e2f0744f..7f4ac0b31 100644 --- a/src/query/v2/parameters.hpp +++ b/src/query/v2/parameters.hpp @@ -12,8 +12,8 @@ #pragma once #include <algorithm> +#include <unordered_map> #include <utility> -#include <vector> #include "storage/v3/property_value.hpp" #include "utils/logging.hpp" @@ -32,7 +32,7 @@ struct Parameters { * @param position Token position in query of 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. @@ -41,23 +41,11 @@ struct Parameters { * @return Value for the given token position. */ 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"); 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 */ auto size() const { return storage_.size(); } @@ -65,7 +53,7 @@ struct Parameters { auto end() const { return storage_.end(); } private: - std::vector<std::pair<int, storage::v3::PropertyValue>> storage_; + std::unordered_map<int, storage::v3::PropertyValue> storage_; }; } // namespace memgraph::query::v2 diff --git a/src/storage/v3/bindings/eval.hpp b/src/storage/v3/bindings/eval.hpp index 38b5aae87..7f93bb79c 100644 --- a/src/storage/v3/bindings/eval.hpp +++ b/src/storage/v3/bindings/eval.hpp @@ -42,7 +42,7 @@ struct Parameters { * @param position Token position in query of 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. @@ -51,23 +51,11 @@ struct Parameters { * @return Value for the given token position. */ 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"); 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 */ auto size() const { return storage_.size(); } @@ -75,7 +63,7 @@ struct Parameters { auto end() const { return storage_.end(); } private: - std::vector<std::pair<int, storage::v3::PropertyValue>> storage_; + std::unordered_map<int, storage::v3::PropertyValue> storage_; }; struct EvaluationContext {