@@ -18,6 +18,7 @@ limitations under the License.
1818
1919#pragma once
2020
21+ #include < limits>
2122#include < queue>
2223#include < unordered_set>
2324#include < vector>
@@ -49,7 +50,9 @@ template <typename Graph_t>
4950bool edge (const vertex_idx_t <Graph_t> &src, const vertex_idx_t <Graph_t> &dest, const Graph_t &graph) {
5051 static_assert (is_directed_graph_v<Graph_t>, " Graph_t must satisfy the directed_graph concept" );
5152 for (const auto &child : graph.children (src)) {
52- if (child == dest) { return true ; }
53+ if (child == dest) {
54+ return true ;
55+ }
5356 }
5457 return false ;
5558}
@@ -108,7 +111,9 @@ struct vertex_cond_iterator {
108111 vertex_cond_iterator (const Graph_t &graph_, const iterator_t &start) : graph(graph_), current_vertex(start) {
109112 while (current_vertex != graph.vertices ().end ()) {
110113 // if (cond.eval(graph, *current_vertex)) {
111- if (cond (graph, *current_vertex)) { break ; }
114+ if (cond (graph, *current_vertex)) {
115+ break ;
116+ }
112117 current_vertex++;
113118 }
114119 }
@@ -120,7 +125,9 @@ struct vertex_cond_iterator {
120125 current_vertex++;
121126
122127 while (current_vertex != graph.vertices ().end ()) {
123- if (cond (graph, *current_vertex)) { break ; }
128+ if (cond (graph, *current_vertex)) {
129+ break ;
130+ }
124131 current_vertex++;
125132 }
126133
@@ -208,7 +215,9 @@ template <typename Graph_t>
208215std::vector<vertex_idx_t <Graph_t>> source_vertices (const Graph_t &graph) {
209216 static_assert (is_directed_graph_v<Graph_t>, " Graph_t must satisfy the directed_graph concept" );
210217 std::vector<vertex_idx_t <Graph_t>> vec;
211- for (const auto &source : source_vertices_view (graph)) { vec.push_back (source); }
218+ for (const auto &source : source_vertices_view (graph)) {
219+ vec.push_back (source);
220+ }
212221 return vec;
213222}
214223
@@ -224,7 +233,9 @@ std::vector<vertex_idx_t<Graph_t>> sink_vertices(const Graph_t &graph) {
224233 static_assert (is_directed_graph_v<Graph_t>, " Graph_t must satisfy the directed_graph concept" );
225234 std::vector<vertex_idx_t <Graph_t>> vec;
226235
227- for (const auto &sink : sink_vertices_view (graph)) { vec.push_back (sink); }
236+ for (const auto &sink : sink_vertices_view (graph)) {
237+ vec.push_back (sink);
238+ }
228239 return vec;
229240}
230241
@@ -257,7 +268,9 @@ struct traversal_iterator {
257268
258269 traversal_iterator (const Graph_t &graph_, const vertex_idx_t <Graph_t> &start)
259270 : graph(graph_), adj_iter(graph_), current_vertex(start) {
260- if (graph.num_vertices () == start) { return ; }
271+ if (graph.num_vertices () == start) {
272+ return ;
273+ }
261274
262275 visited.insert (start);
263276
@@ -435,7 +448,9 @@ template <typename Graph_t>
435448std::vector<vertex_idx_t <Graph_t>> successors (const vertex_idx_t <Graph_t> &v, const Graph_t &graph) {
436449 static_assert (is_directed_graph_v<Graph_t>, " Graph_t must satisfy the directed_graph concept" );
437450 std::vector<vertex_idx_t <Graph_t>> vec;
438- for (const auto &suc : bfs_view (graph, v)) { vec.push_back (suc); }
451+ for (const auto &suc : bfs_view (graph, v)) {
452+ vec.push_back (suc);
453+ }
439454 return vec;
440455}
441456
@@ -451,7 +466,9 @@ template <typename Graph_t>
451466std::vector<vertex_idx_t <Graph_t>> ancestors (const vertex_idx_t <Graph_t> &v, const Graph_t &graph) {
452467 static_assert (is_directed_graph_v<Graph_t>, " Graph_t must satisfy the directed_graph concept" );
453468 std::vector<vertex_idx_t <Graph_t>> vec;
454- for (const auto &anc : bfs_reverse_view (graph, v)) { vec.push_back (anc); }
469+ for (const auto &anc : bfs_reverse_view (graph, v)) {
470+ vec.push_back (anc);
471+ }
455472 return vec;
456473}
457474
@@ -461,14 +478,18 @@ bool is_acyclic(const Graph_t &graph) {
461478
462479 using VertexType = vertex_idx_t <Graph_t>;
463480
464- if (graph.num_vertices () < 2 ) { return true ; }
481+ if (graph.num_vertices () < 2 ) {
482+ return true ;
483+ }
465484
466485 std::vector<VertexType> predecessors_count (graph.num_vertices (), 0 );
467486
468487 std::queue<VertexType> next;
469488
470489 // Find source nodes
471- for (const VertexType &v : source_vertices_view (graph)) { next.push (v); }
490+ for (const VertexType &v : source_vertices_view (graph)) {
491+ next.push (v);
492+ }
472493
473494 VertexType node_count = 0 ;
474495 while (!next.empty ()) {
@@ -478,7 +499,9 @@ bool is_acyclic(const Graph_t &graph) {
478499
479500 for (const VertexType ¤t : graph.children (node)) {
480501 ++predecessors_count[current];
481- if (predecessors_count[current] == graph.in_degree (current)) { next.push (current); }
502+ if (predecessors_count[current] == graph.in_degree (current)) {
503+ next.push (current);
504+ }
482505 }
483506 }
484507
@@ -491,7 +514,9 @@ bool is_connected(const Graph_t &graph) {
491514
492515 using VertexType = vertex_idx_t <Graph_t>;
493516
494- if (graph.num_vertices () < 2 ) { return true ; }
517+ if (graph.num_vertices () < 2 ) {
518+ return true ;
519+ }
495520
496521 std::unordered_set<VertexType> visited;
497522
@@ -522,11 +547,15 @@ std::size_t num_common_parents(const Graph_t &graph, vertex_idx_t<Graph_t> v1, v
522547
523548 std::unordered_set<vertex_idx_t <Graph_t>> parents;
524549 parents.reserve (graph.in_degree (v1));
525- for (const auto &par : graph.parents (v1)) { parents.emplace (par); }
550+ for (const auto &par : graph.parents (v1)) {
551+ parents.emplace (par);
552+ }
526553
527554 std::size_t num = 0 ;
528555 for (const auto &par : graph.parents (v2)) {
529- if (parents.find (par) != parents.end ()) { ++num; }
556+ if (parents.find (par) != parents.end ()) {
557+ ++num;
558+ }
530559 }
531560
532561 return num;
@@ -538,11 +567,15 @@ std::size_t num_common_children(const Graph_t &graph, vertex_idx_t<Graph_t> v1,
538567
539568 std::unordered_set<vertex_idx_t <Graph_t>> childrn;
540569 childrn.reserve (graph.out_degree (v1));
541- for (const auto &chld : graph.children (v1)) { childrn.emplace (chld); }
570+ for (const auto &chld : graph.children (v1)) {
571+ childrn.emplace (chld);
572+ }
542573
543574 std::size_t num = 0 ;
544575 for (const auto &chld : graph.children (v2)) {
545- if (childrn.find (chld) != childrn.end ()) { ++num; }
576+ if (childrn.find (chld) != childrn.end ()) {
577+ ++num;
578+ }
546579 }
547580
548581 return num;
0 commit comments