From a2e97dbf58ef2dddbfac47fd8ea7b6d4f8ff3f26 Mon Sep 17 00:00:00 2001 From: Jordan Eizenga Date: Mon, 22 Jul 2024 12:31:10 -0700 Subject: [PATCH] pass non-default destroy paths through graph proxy --- bdsg/include/bdsg/internal/base_packed_graph.hpp | 7 ++++++- ...able_path_deletable_handle_graph_fragment.classfragment | 7 +++++++ bdsg/src/hash_graph.cpp | 6 +++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/bdsg/include/bdsg/internal/base_packed_graph.hpp b/bdsg/include/bdsg/internal/base_packed_graph.hpp index 39cc7020..839365de 100644 --- a/bdsg/include/bdsg/internal/base_packed_graph.hpp +++ b/bdsg/include/bdsg/internal/base_packed_graph.hpp @@ -2619,6 +2619,10 @@ template void BasePackedGraph::destroy_paths(const std::vector& paths) { std::unordered_set paths_set(paths.begin(), paths.end()); + path_handle_t first_path = as_path_handle(-1); + if (paths.size() == 1) { + first_path = paths.front(); + } PackedSet nodes_visited; @@ -2649,7 +2653,8 @@ void BasePackedGraph::destroy_paths(const std::vector& p size_t prev = 0; size_t here = path_membership_node_iv.get(node_member_idx); while (here) { - if (paths_set.count(as_path_handle(get_membership_path(here)))) { + auto path_here = as_path_handle(get_membership_path(here)); + if (paths.size() == 1 ? path_here == first_path : paths_set.count(path_here)) { // this is a membership record for a path that we're deleting if (prev == 0) { // this was the first record, set following one to be the head diff --git a/bdsg/include/bdsg/internal/graph_proxy_mutable_path_deletable_handle_graph_fragment.classfragment b/bdsg/include/bdsg/internal/graph_proxy_mutable_path_deletable_handle_graph_fragment.classfragment index 32b2ba10..292868bf 100644 --- a/bdsg/include/bdsg/internal/graph_proxy_mutable_path_deletable_handle_graph_fragment.classfragment +++ b/bdsg/include/bdsg/internal/graph_proxy_mutable_path_deletable_handle_graph_fragment.classfragment @@ -104,6 +104,13 @@ public: virtual void destroy_path(const path_handle_t& path) { this->get()->destroy_path(path); } + + /** + * Destroy the given paths. Invalidates handles to the paths and their steps. + */ + virtual void destroy_paths(const std::vector& paths) { + this->get()->destroy_paths(paths); + } /** * Create a path with the given name. The caller must ensure that no path diff --git a/bdsg/src/hash_graph.cpp b/bdsg/src/hash_graph.cpp index b9b830a9..5b85811a 100644 --- a/bdsg/src/hash_graph.cpp +++ b/bdsg/src/hash_graph.cpp @@ -603,6 +603,10 @@ namespace bdsg { for (auto path : paths) { path_ids.emplace(as_integer(path)); } + int64_t first_path = -1; + if (path_ids.size() == 1) { + first_path = *path_ids.begin(); + } unordered_set nodes_visited; for (auto path : paths) { @@ -618,7 +622,7 @@ namespace bdsg { } vector& node_occs = graph[get_id(mapping->handle)].occurrences; for (size_t i = 0; i < node_occs.size(); ) { - if (path_ids.count(node_occs[i]->path_id)) { + if (first_path != -1 ? node_occs[i]->path_id == first_path : path_ids.count(node_occs[i]->path_id)) { node_occs[i] = node_occs.back(); node_occs.pop_back(); }