Skip to content

Commit

Permalink
[sssp] streamline edge relaxing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
sbeamer committed May 30, 2020
1 parent 015798b commit f28d026
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/sssp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,15 @@ void RelaxEdges(const WGraph &g, NodeID u, WeightT delta,
for (WNode wn : g.out_neigh(u)) {
WeightT old_dist = dist[wn.v];
WeightT new_dist = dist[u] + wn.w;
if (new_dist < old_dist) {
bool changed_dist = true;
while (!compare_and_swap(dist[wn.v], old_dist, new_dist)) {
old_dist = dist[wn.v];
if (old_dist <= new_dist) {
changed_dist = false;
break;
}
}
if (changed_dist) {
while (new_dist < old_dist) {
if (compare_and_swap(dist[wn.v], old_dist, new_dist)) {
size_t dest_bin = new_dist/delta;
if (dest_bin >= local_bins.size()) {
if (dest_bin >= local_bins.size())
local_bins.resize(dest_bin+1);
}
local_bins[dest_bin].push_back(wn.v);
break;
}
old_dist = dist[wn.v]; // swap failed, recheck dist update & retry
}
}
}
Expand Down

0 comments on commit f28d026

Please sign in to comment.