File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -458,6 +458,34 @@ void grapht<N>::visit_reachable(node_indext src)
458
458
nodes[index].visited = true ;
459
459
}
460
460
461
+ // / Add to `set` nodes that are reachable from `set`
462
+ // / \param set: set of source nodes, must be a container with an
463
+ // / `insert(const value_type&)` method.
464
+ // / \param for_each_successor: function which given a node `n` and a function
465
+ // / `f`, applies `f` on all successors of `n`.
466
+ template <class Container , typename nodet = typename Container::value_type>
467
+ void get_reachable (
468
+ Container &set,
469
+ const std::function<void (
470
+ const typename Container::value_type &,
471
+ const std::function<void (const typename Container::value_type &)> &)>
472
+ &for_each_successor)
473
+ {
474
+ std::vector<nodet> stack;
475
+ for (const auto &elt : set)
476
+ stack.push_back (elt);
477
+
478
+ while (!stack.empty ())
479
+ {
480
+ auto n = stack.back ();
481
+ stack.pop_back ();
482
+ for_each_successor (n, [&](const nodet &node) { // NOLINT
483
+ if (set.insert (node).second )
484
+ stack.push_back (node);
485
+ });
486
+ }
487
+ }
488
+
461
489
template <class N >
462
490
std::vector<typename N::node_indext>
463
491
grapht<N>::get_reachable(node_indext src, bool forwards) const
You can’t perform that action at this time.
0 commit comments