add impl of vertices iterator

This commit is contained in:
antoniofilipovic 2022-08-11 14:04:02 +02:00
parent d373365710
commit 259d774539
3 changed files with 25 additions and 4 deletions

View File

@ -49,7 +49,6 @@ namespace memgraph::query {
class VertexAccessor;
class Graph;
class VerticesIterable;
class EdgeAccessor final {
public:
@ -196,8 +195,9 @@ inline bool EdgeAccessor::IsCycle() const { return To() == From(); }
class SubgraphVertexAccessor final {
public:
query::VertexAccessor impl_;
query::Graph *graph_;
explicit SubgraphVertexAccessor(query::VertexAccessor impl) : impl_(impl) {}
explicit SubgraphVertexAccessor(query::VertexAccessor impl, query::Graph *graph_) : impl_(impl), graph_(graph_) {}
bool operator==(const SubgraphVertexAccessor &v) const noexcept {
static_assert(noexcept(impl_ == v.impl_));
@ -529,6 +529,8 @@ class SubgraphDbAccessor final {
// todo antoniofilipovic change to return SubgraphVertexAccessor && add check that vertex exists in subgraph
return db_accessor_->FindVertex(gid, view);
}
query::Graph *getGraph() { return graph_; }
};
// class SubgraphEdgeAccessor final {

View File

@ -2444,7 +2444,18 @@ mgp_error mgp_vertices_iterator_next(mgp_vertices_iterator *it, mgp_vertex **res
return nullptr;
}
memgraph::utils::OnScopeExit clean_up([it] { it->current_v = std::nullopt; });
it->current_v.emplace(*it->current_it, it->graph, it->GetMemoryResource());
std::visit(memgraph::utils::Overloaded{[it](memgraph::query::DbAccessor *impl) {
it->current_v.emplace(*it->current_it, it->graph,
it->GetMemoryResource());
;
},
[it](memgraph::query::SubgraphDbAccessor *impl) {
it->current_v.emplace(memgraph::query::SubgraphVertexAccessor(
*it->current_it, impl->getGraph()),
it->graph, it->GetMemoryResource());
}},
it->graph->impl);
clean_up.Disable();
return &*it->current_v;
},

View File

@ -734,7 +734,15 @@ struct mgp_vertices_iterator {
graph->impl)),
current_it(vertices.begin()) {
if (current_it != vertices.end()) {
current_v.emplace(*current_it, graph, memory);
std::visit(memgraph::utils::Overloaded{[this, graph, memory](memgraph::query::DbAccessor *impl) {
current_v.emplace(*current_it, graph, memory);
},
[this, graph, memory](memgraph::query::SubgraphDbAccessor *impl) {
current_v.emplace(memgraph::query::SubgraphVertexAccessor(
*current_it, impl->getGraph()),
graph, memory);
}},
graph->impl);
}
}