Skip to content

Commit

Permalink
Merge pull request #202 from vgteam/batch-delete-paths
Browse files Browse the repository at this point in the history
Actually expose the PackedGraph batch path destroy function
  • Loading branch information
jeizenga authored Jul 22, 2024
2 parents 307b18f + a2e97db commit 757896a
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 @@ -2615,6 +2615,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 @@ -2645,7 +2649,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 757896a

Please sign in to comment.