File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -75,9 +75,28 @@ class CycleDetector
75
75
V const * m_firstCycleVertex = nullptr ;
76
76
};
77
77
78
+ /* *
79
+ * Generic breadth first search.
80
+ *
81
+ * Example: Gather all nodes in the graph starting at ``root``:
82
+ *
83
+ * std::set<Node> allNodes = BreadthFirstSearch<Node>{{root}}.run([](Node const& _node, auto&& _addChild) {
84
+ * // Potentially process ``_node``.
85
+ * for(Node const& _child: _node.children())
86
+ * // Potentially filter the children to be visited.
87
+ * _addChild(_child);
88
+ * }).visited;
89
+ *
90
+ * Note that the order of the traversal is *non-deterministic* (the children are stored in a std::set of pointers).
91
+ */
78
92
template <typename V>
79
93
struct BreadthFirstSearch
80
94
{
95
+ // / Runs the breadth first search. The verticesToTraverse member of the struct needs to be initialized.
96
+ // / @param _forEachChild should be a generic lambda expression (or an object of a class type with an
97
+ // / analog templated call operator) of the form [...](Node const& _node, auto&& _addChild) { ... }
98
+ // / that is called for each visited node and is supposd to call _addChild(childNode) for every
99
+ // / child node of _node.
81
100
template <typename ForEachChild>
82
101
BreadthFirstSearch& run (ForEachChild&& _forEachChild)
83
102
{
You can’t perform that action at this time.
0 commit comments