From 5167c6ee3711a1da17e1f67a107237f4231869e9 Mon Sep 17 00:00:00 2001 From: gvolfing Date: Sun, 10 Mar 2024 19:39:30 +0100 Subject: [PATCH] Add temporary edge retrieval code --- src/storage/v2/inmemory/storage.cpp | 31 ++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/storage/v2/inmemory/storage.cpp b/src/storage/v2/inmemory/storage.cpp index f72636584..1e4a71b64 100644 --- a/src/storage/v2/inmemory/storage.cpp +++ b/src/storage/v2/inmemory/storage.cpp @@ -1428,11 +1428,32 @@ EdgesIterable InMemoryStorage::InMemoryAccessor::Edges(EdgeTypeId edge_type, Vie std::optional InMemoryStorage::InMemoryAccessor::FindEdge(Gid gid, View view) { auto *mem_storage = static_cast(storage_); - auto acc = mem_storage->edges_.access(); - auto it = acc.find(gid); - if (it == acc.end()) return std::nullopt; - // Create EdgeAccessor! - return {}; + + // TODO replace this logic once we have a proper edge struct in place. + // This should be only temporary, currently we have to do this whole + // lookup through all the vertices, since the edge struct only has a + // pointer to it's GID, it has no information whatsoever about the from + // and to vertices. + auto acc = mem_storage->vertices_.access(); + auto maybe_edge_info = std::invoke([&]() -> std::optional> { + for (auto &vertex : acc) { + for (auto &edge : vertex.out_edges) { + if (std::get<2>(edge).gid == gid) { + return std::make_tuple(std::get<2>(edge), std::get<0>(edge), &vertex, std::get<1>(edge)); + } + } + } + return std::nullopt; + }); + + if (!maybe_edge_info) { + return std::nullopt; + } + + auto &edge_info = *maybe_edge_info; + + return EdgeAccessor::Create(std::get<0>(edge_info), std::get<1>(edge_info), std::get<2>(edge_info), + std::get<3>(edge_info), storage_, &transaction_); } Transaction InMemoryStorage::CreateTransaction(