Skip to content

Commit

Permalink
plugins/LeafMetric: Simplify code with new Graph::dfs method variant
Browse files Browse the repository at this point in the history
  • Loading branch information
anlambert committed Dec 12, 2024
1 parent 83add68 commit 0329082
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions plugins/metric/LeafMetric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,19 @@ LeafMetric::LeafMetric(const PluginContext *context) : DoubleAlgorithm(context)
//=======================================================================
bool LeafMetric::run() {
result->setAllNodeValue(0);
for (auto n : reversed(dfs(graph, true))) {
double val = 1.0;
if (graph->outdeg(n) > 0) {
val = iteratorReduce(graph->getOutNodes(n), 0.0, [this](double curVal, const node m) {
return curVal + result->getNodeValue(m);
});
}
result->setNodeValue(n, val);
}
graph->dfs([](const Graph *, node) -> bool { return true; },
[this](const Graph *, node n) -> bool {
double val = 1.0;
if (graph->outdeg(n) > 0) {
val = iteratorReduce(graph->getOutNodes(n), 0.0,
[this](double curVal, const node m) {
return curVal + result->getNodeValue(m);
});
}
result->setNodeValue(n, val);
return true;
},
true);
return true;
}
//=======================================================================
Expand Down

0 comments on commit 0329082

Please sign in to comment.