diff --git a/src/query/db_accessor.hpp b/src/query/db_accessor.hpp index f2e3b7448..10211d889 100644 --- a/src/query/db_accessor.hpp +++ b/src/query/db_accessor.hpp @@ -48,8 +48,8 @@ namespace memgraph::query { class VertexAccessor; - class Graph; +class VerticesIterable; class EdgeAccessor final { public: @@ -236,24 +236,49 @@ class SubgraphVertexAccessor final { return impl_.SetProperty(key, value); } }; +} // namespace memgraph::query + +namespace std { + +template <> +struct hash { + size_t operator()(const memgraph::query::VertexAccessor &v) const { return std::hash{}(v.impl_); } +}; + +template <> +struct hash { + size_t operator()(const memgraph::query::EdgeAccessor &e) const { return std::hash{}(e.impl_); } +}; + +} // namespace std + +namespace memgraph::query { class VerticesIterable final { enum class Type { VERTEX, SUBGRAPH_VERTEX }; - storage::VerticesIterable iterable_; + std::variant, + std::equal_to, utils::Allocator>> + iterable_; Type type_; public: class Iterator final { - storage::VerticesIterable::Iterator it_; + std::variant, std::equal_to, + utils::Allocator>::iterator> + it_; Type type_; public: explicit Iterator(storage::VerticesIterable::Iterator it, Type type_) : it_(it), type_(type_) {} - // explicit Iterator(utils::pmr::unordered_set>::iterator it, Type type_) : it_(it), type_(type_) {} + explicit Iterator(std::unordered_set, std::equal_to, + utils::Allocator>::iterator it, + Type type_) + : it_(it), type_(type_) {} VertexAccessor operator*() const { - return VertexAccessor(*it_); + return std::visit(memgraph::utils::Overloaded{[](auto it_) { return VertexAccessor(*it_); }}, it_); // switch (type_) { // case Type::VERTEX: { // return VertexAccessor(*it_); @@ -265,7 +290,8 @@ class VerticesIterable final { } Iterator &operator++() { - ++it_; + //++it_; + std::visit(memgraph::utils::Overloaded{[](auto it_) { ++it_; }}, it_); return *this; } @@ -275,22 +301,22 @@ class VerticesIterable final { }; explicit VerticesIterable(storage::VerticesIterable iterable) : iterable_(std::move(iterable)), type_(Type::VERTEX) {} - // explicit VerticesIterable(utils::pmr::unordered_set> vertices) : iterable_(vertices), - // type_(Type::SUBGRAPH_VERTEX) {} + explicit VerticesIterable(std::unordered_set, std::equal_to, + utils::Allocator> + vertices) + : iterable_(vertices), type_(Type::SUBGRAPH_VERTEX) {} Iterator begin() { - return Iterator(iterable_.begin(), type_); - // return std::visit(memgraph::utils::Overloaded{ - // [](auto &iterable_){return Iterator(iterable_.begin(), type_);} - // }, iterable_); + // return Iterator(iterable_.begin(), type_); + return std::visit( + memgraph::utils::Overloaded{[this](auto &iterable_) { return Iterator(iterable_.begin(), type_); }}, iterable_); } Iterator end() { - return Iterator(iterable_.end(), type_); + // return Iterator(iterable_.end(), type_); - // return std::visit(memgraph::utils::Overloaded{ - // [](auto &iterable_){return Iterator(iterable_.end(), type_);} - // }, iterable_); + return std::visit(memgraph::utils::Overloaded{[this](auto &iterable_) { return Iterator(iterable_.end(), type_); }}, + iterable_); } }; @@ -550,17 +576,3 @@ class SubgraphDbAccessor final { // }; } // namespace memgraph::query - -namespace std { - -template <> -struct hash { - size_t operator()(const memgraph::query::VertexAccessor &v) const { return std::hash{}(v.impl_); } -}; - -template <> -struct hash { - size_t operator()(const memgraph::query::EdgeAccessor &e) const { return std::hash{}(e.impl_); } -}; - -} // namespace std diff --git a/src/query/procedure/mg_procedure_impl.hpp b/src/query/procedure/mg_procedure_impl.hpp index 83d95b72c..136d5851e 100644 --- a/src/query/procedure/mg_procedure_impl.hpp +++ b/src/query/procedure/mg_procedure_impl.hpp @@ -455,6 +455,13 @@ struct mgp_vertex { mgp_vertex(mgp_vertex &&other) noexcept : memory(other.memory), impl(other.impl), graph(other.graph) {} + memgraph::query::VertexAccessor getImpl() const { + return std::visit( + memgraph::utils::Overloaded{[](memgraph::query::VertexAccessor impl) { return impl; }, + [](memgraph::query::SubgraphVertexAccessor impl) { return impl.impl_; }}, + this->impl); + } + /// Copy construction without memgraph::utils::MemoryResource is not allowed. mgp_vertex(const mgp_vertex &) = delete; @@ -723,11 +730,8 @@ struct mgp_vertices_iterator { mgp_vertices_iterator(mgp_graph *graph, memgraph::utils::MemoryResource *memory) : memory(memory), graph(graph), - vertices( - std::visit(memgraph::utils::Overloaded{ - [graph](memgraph::query::DbAccessor *impl) { return impl->Vertices(graph->view); }, - [graph](memgraph::query::SubgraphDbAccessor *impl) { return impl->Vertices(graph->view); }}, - graph->impl)), + vertices(std::visit(memgraph::utils::Overloaded{[graph](auto *impl) { return impl->Vertices(graph->view); }}, + graph->impl)), current_it(vertices.begin()) { if (current_it != vertices.end()) { current_v.emplace(*current_it, graph, memory);