From b776313c80f6180589fcfbf859aab1ee8d737d4f Mon Sep 17 00:00:00 2001 From: antoniofilipovic Date: Mon, 15 Aug 2022 17:17:19 +0200 Subject: [PATCH] add subgraphVertexAccessor constructor for mgp_edge --- src/query/procedure/mg_procedure_impl.cpp | 42 +++++++++++++++++++++-- src/query/procedure/mg_procedure_impl.hpp | 10 ++++++ 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/query/procedure/mg_procedure_impl.cpp b/src/query/procedure/mg_procedure_impl.cpp index 852729c6b..f3f0e5398 100644 --- a/src/query/procedure/mg_procedure_impl.cpp +++ b/src/query/procedure/mg_procedure_impl.cpp @@ -1941,7 +1941,19 @@ mgp_error mgp_vertex_iter_in_edges(mgp_vertex *v, mgp_memory *memory, mgp_edges_ it->in.emplace(std::move(*maybe_edges)); it->in_it.emplace(it->in->begin()); if (*it->in_it != it->in->end()) { - it->current_e.emplace(**it->in_it, v->graph, it->GetMemoryResource()); + std::visit(memgraph::utils::Overloaded{ + [&](memgraph::query::DbAccessor *impl) { + it->current_e.emplace(**it->in_it, (**it->in_it).From(), (**it->in_it).To(), v->graph, + it->GetMemoryResource()); + }, + [&](memgraph::query::SubgraphDbAccessor *impl) { + it->current_e.emplace( + **it->in_it, + memgraph::query::SubgraphVertexAccessor((**it->in_it).From(), impl->getGraph()), + memgraph::query::SubgraphVertexAccessor((**it->in_it).To(), impl->getGraph()), v->graph, + it->GetMemoryResource()); + }}, + v->graph->impl); } return it.release(); @@ -1978,7 +1990,19 @@ mgp_error mgp_vertex_iter_out_edges(mgp_vertex *v, mgp_memory *memory, mgp_edges it->out.emplace(std::move(*maybe_edges)); it->out_it.emplace(it->out->begin()); if (*it->out_it != it->out->end()) { - it->current_e.emplace(**it->out_it, v->graph, it->GetMemoryResource()); + std::visit(memgraph::utils::Overloaded{ + [&](memgraph::query::DbAccessor *impl) { + it->current_e.emplace(**it->out_it, (**it->out_it).From(), (**it->out_it).To(), v->graph, + it->GetMemoryResource()); + }, + [&](memgraph::query::SubgraphDbAccessor *impl) { + it->current_e.emplace( + **it->out_it, + memgraph::query::SubgraphVertexAccessor((**it->out_it).From(), impl->getGraph()), + memgraph::query::SubgraphVertexAccessor((**it->out_it).To(), impl->getGraph()), v->graph, + it->GetMemoryResource()); + }}, + v->graph->impl); } return it.release(); @@ -2016,7 +2040,19 @@ mgp_error mgp_edges_iterator_next(mgp_edges_iterator *it, mgp_edge **result) { it->current_e = std::nullopt; return nullptr; } - it->current_e.emplace(**impl_it, it->source_vertex.graph, it->GetMemoryResource()); + std::visit(memgraph::utils::Overloaded{ + [&](memgraph::query::DbAccessor *impl) { + it->current_e.emplace(**impl_it, (**impl_it).From(), (**impl_it).To(), + it->source_vertex.graph, it->GetMemoryResource()); + }, + [&](memgraph::query::SubgraphDbAccessor *impl) { + it->current_e.emplace( + **impl_it, memgraph::query::SubgraphVertexAccessor((**impl_it).From(), impl->getGraph()), + memgraph::query::SubgraphVertexAccessor((**impl_it).To(), impl->getGraph()), + it->source_vertex.graph, it->GetMemoryResource()); + }}, + it->source_vertex.graph->impl); + return &*it->current_e; }; if (it->in_it) { diff --git a/src/query/procedure/mg_procedure_impl.hpp b/src/query/procedure/mg_procedure_impl.hpp index da487483e..f26ed98b4 100644 --- a/src/query/procedure/mg_procedure_impl.hpp +++ b/src/query/procedure/mg_procedure_impl.hpp @@ -513,6 +513,16 @@ struct mgp_edge { memgraph::utils::MemoryResource *memory) noexcept : memory(memory), impl(impl), from(impl.From(), graph, memory), to(impl.To(), graph, memory) {} + mgp_edge(const memgraph::query::EdgeAccessor &impl, const memgraph::query::VertexAccessor &from_v, + const memgraph::query::VertexAccessor &to_v, mgp_graph *graph, + memgraph::utils::MemoryResource *memory) noexcept + : memory(memory), impl(impl), from(from_v, graph, memory), to(to_v, graph, memory) {} + + mgp_edge(const memgraph::query::EdgeAccessor &impl, const memgraph::query::SubgraphVertexAccessor &from_v, + const memgraph::query::SubgraphVertexAccessor &to_v, mgp_graph *graph, + memgraph::utils::MemoryResource *memory) noexcept + : memory(memory), impl(impl), from(from_v, graph, memory), to(to_v, graph, memory) {} + mgp_edge(const mgp_edge &other, memgraph::utils::MemoryResource *memory) noexcept : memory(memory), impl(other.impl), from(other.from, memory), to(other.to, memory) {}