Skip to content

Commit

Permalink
allow thread safe use of add_paths_to_graph (i_wt select limitation)
Browse files Browse the repository at this point in the history
Per caching in sdsl-lite: simongog/sdsl-lite#263.

This allows the calling context to decide whether or not to use the
add_paths_to_graph functionality that is often not necessary and is also not
thread safe.
  • Loading branch information
ekg committed Oct 6, 2015
1 parent 39ff8c9 commit 9b71d37
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
12 changes: 9 additions & 3 deletions xg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ void XG::neighborhood(int64_t id, size_t steps, Graph& g) const {
expand_context(g, steps);
}

void XG::expand_context(Graph& g, size_t steps) const {
void XG::expand_context(Graph& g, size_t steps, bool add_paths) const {
map<int64_t, Node*> nodes;
map<pair<Side, Side>, Edge*> edges;
set<int64_t> to_visit;
Expand Down Expand Up @@ -1088,7 +1088,9 @@ void XG::expand_context(Graph& g, size_t steps) const {
*np = node(t);
}
}
add_paths_to_graph(nodes, g);
if (add_paths) {
add_paths_to_graph(nodes, g);
}
}


Expand Down Expand Up @@ -1231,7 +1233,11 @@ size_t XG::node_position_in_path(int64_t id, const string& name) const {
cerr << "warning: path " << name << " contains a loop" << endl;
}
auto& path = *paths[path_rank(name)-1];
return path.positions[path.ids.select(1, id_to_rank(id))];
auto rank = id_to_rank(id);
size_t node_rank_in_path;
#pragma omp critical (path_ids)
node_rank_in_path = path.ids.select(1, rank);
return path.positions[node_rank_in_path];
}

int64_t XG::node_at_path_position(const string& name, size_t pos) const {
Expand Down
5 changes: 4 additions & 1 deletion xg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ class XG {
void neighborhood(int64_t id, size_t steps, Graph& g) const;
//void for_path_range(string& name, int64_t start, int64_t stop, function<void(Node)> lambda);
void get_path_range(string& name, int64_t start, int64_t stop, Graph& g) const;
void expand_context(Graph& g, size_t steps) const;
// basic method to query regions of the graph
// add_paths flag allows turning off the (potentially costly, and thread-locking) addition of paths
// when these are not necessary
void expand_context(Graph& g, size_t steps, bool add_paths = true) const;
void get_connected_nodes(Graph& g) const;
void get_id_range(int64_t id1, int64_t id2, Graph& g) const;

Expand Down

0 comments on commit 9b71d37

Please sign in to comment.