Skip to content

Commit

Permalink
pass non-default destroy paths through graph proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
jeizenga committed Jul 22, 2024
1 parent 39cb4fd commit a2e97db
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
7 changes: 6 additions & 1 deletion bdsg/include/bdsg/internal/base_packed_graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2619,6 +2619,10 @@ template<typename Backend>
void BasePackedGraph<Backend>::destroy_paths(const std::vector<path_handle_t>& paths) {

std::unordered_set<path_handle_t> paths_set(paths.begin(), paths.end());
path_handle_t first_path = as_path_handle(-1);
if (paths.size() == 1) {
first_path = paths.front();
}

PackedSet<Backend> nodes_visited;

Expand Down Expand Up @@ -2649,7 +2653,8 @@ void BasePackedGraph<Backend>::destroy_paths(const std::vector<path_handle_t>& 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<path_handle_t>& paths) {
this->get()->destroy_paths(paths);
}

/**
* Create a path with the given name. The caller must ensure that no path
Expand Down
6 changes: 5 additions & 1 deletion bdsg/src/hash_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<nid_t> nodes_visited;

for (auto path : paths) {
Expand All @@ -618,7 +622,7 @@ namespace bdsg {
}
vector<path_mapping_t*>& 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();
}
Expand Down

0 comments on commit a2e97db

Please sign in to comment.