Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actually expose the PackedGraph batch path destroy function #202

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading