Skip to content

Commit 7d5bcdc

Browse files
committed
[lint] Lint fixes for pgr_binaryBreadthFirstSearch.hpp and pgr_breadthFirstSearch.hpp
1 parent 539b71c commit 7d5bcdc

2 files changed

Lines changed: 37 additions & 65 deletions

File tree

include/breadthFirstSearch/pgr_binaryBreadthFirstSearch.hpp

Lines changed: 28 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,27 @@ along with this program; if not, write to the Free Software
2121
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2222
********************************************************************PGR-GNU*/
2323

24-
#ifndef INCLUDE_MST_PGR_BINARYBREADTHFIRSTSEARCH_HPP_
25-
#define INCLUDE_MST_PGR_BINARYBREADTHFIRSTSEARCH_HPP_
24+
#ifndef INCLUDE_BREADTHFIRSTSEARCH_PGR_BINARYBREADTHFIRSTSEARCH_HPP_
25+
#define INCLUDE_BREADTHFIRSTSEARCH_PGR_BINARYBREADTHFIRSTSEARCH_HPP_
2626
#pragma once
2727

2828
#include <deque>
2929
#include <algorithm>
3030
#include <cmath>
31+
#include <limits>
32+
#include <vector>
3133

3234
#include "cpp_common/basePath_SSEC.hpp"
3335
#include "cpp_common/pgr_base_graph.hpp"
3436
#include "cpp_common/pgr_assert.h"
3537
//******************************************
3638

37-
namespace pgrouting
38-
{
39-
namespace functions
40-
{
39+
namespace pgrouting {
40+
namespace functions {
4141

4242
template <class G>
43-
class Pgr_binaryBreadthFirstSearch
44-
{
45-
public:
43+
class Pgr_binaryBreadthFirstSearch {
44+
public:
4645
typedef typename G::V V;
4746
typedef typename G::E E;
4847
typedef typename G::B_G B_G;
@@ -53,18 +52,15 @@ class Pgr_binaryBreadthFirstSearch
5352
G &graph,
5453
std::vector<int64_t> start_vertex,
5554
std::vector<int64_t> end_vertex) {
56-
5755
std::deque<Path> paths;
5856

59-
for(auto source : start_vertex) {
57+
for (auto source : start_vertex) {
6058
std::deque<Path> result_paths = one_to_many_binaryBreadthFirstSearch(
6159
graph,
6260
source,
63-
end_vertex
64-
);
65-
61+
end_vertex);
6662
paths.insert(
67-
paths.begin(),
63+
paths.begin(),
6864
std::make_move_iterator(result_paths.begin()),
6965
std::make_move_iterator(result_paths.end()));
7066
}
@@ -81,20 +77,16 @@ class Pgr_binaryBreadthFirstSearch
8177
return paths;
8278
}
8379

84-
private:
85-
80+
private:
8681
E DEFAULT_EDGE;
8782

8883
std::deque<Path> one_to_many_binaryBreadthFirstSearch(
8984
G &graph,
9085
int64_t start_vertex,
91-
std::vector<int64_t> end_vertex)
92-
{
93-
86+
std::vector<int64_t> end_vertex) {
9487
std::deque<Path> paths;
9588

96-
if (graph.has_vertex(start_vertex) == false)
97-
{
89+
if (graph.has_vertex(start_vertex) == false) {
9890
return paths;
9991
}
10092

@@ -108,26 +100,22 @@ class Pgr_binaryBreadthFirstSearch
108100
current_cost[bgl_start_vertex] = 0;
109101
dq.push_front(bgl_start_vertex);
110102

111-
while (dq.empty() == false)
112-
{
103+
while (dq.empty() == false) {
113104
int64_t head_vertex = dq.front();
114105

115106
dq.pop_front();
116107

117108
updateVertexCosts(graph, current_cost, from_edge, dq, head_vertex);
118109
}
119110

120-
for (auto target_vertex : end_vertex)
121-
{
122-
if (graph.has_vertex(target_vertex) == false)
123-
{
111+
for (auto target_vertex : end_vertex) {
112+
if (graph.has_vertex(target_vertex) == false) {
124113
continue;
125114
}
126115

127116
int64_t bgl_target_vertex = graph.get_V(target_vertex);
128117

129-
if (from_edge[bgl_target_vertex] == DEFAULT_EDGE)
130-
{
118+
if (from_edge[bgl_target_vertex] == DEFAULT_EDGE) {
131119
continue;
132120
}
133121

@@ -144,16 +132,14 @@ class Pgr_binaryBreadthFirstSearch
144132
int64_t target,
145133
int64_t bgl_target_vertex,
146134
std::vector<E> &from_edge,
147-
std::vector<double> &current_cost)
148-
{
135+
std::vector<double> &current_cost) {
149136
int64_t current_node = bgl_target_vertex;
150137

151138
Path path = Path(graph[bgl_start_vertex].id, graph[current_node].id);
152139

153140
path.push_back({target, -1, 0, current_cost[current_node]});
154141

155-
do
156-
{
142+
do {
157143
E e = from_edge[current_node];
158144
auto from = graph.source(e);
159145

@@ -171,43 +157,35 @@ class Pgr_binaryBreadthFirstSearch
171157
std::vector<double> &current_cost,
172158
std::vector<E> &from_edge,
173159
std::deque<int64_t> &dq,
174-
int64_t &head_vertex)
175-
{
160+
int64_t &head_vertex) {
176161
auto out_edges = boost::out_edges(head_vertex, graph.graph);
177162
E e;
178163
EO_i out_i;
179164
EO_i out_end;
180165
V v_source, v_target;
181166

182167
for (boost::tie(out_i, out_end) = out_edges;
183-
out_i != out_end; ++out_i)
184-
{
185-
168+
out_i != out_end; ++out_i) {
186169
e = *out_i;
187170
v_target = graph.target(e);
188171
v_source = graph.source(e);
189172
double edge_cost = graph[e].cost;
190173

191-
if (std::isinf(current_cost[v_target]) or current_cost[v_source] + edge_cost < current_cost[v_target])
192-
{
193-
174+
if (std::isinf(current_cost[v_target]) || current_cost[v_source] + edge_cost < current_cost[v_target]) {
194175
current_cost[v_target] = current_cost[v_source] + edge_cost;
195176

196177
from_edge[v_target] = e;
197178

198-
if (edge_cost != 0)
199-
{
179+
if (edge_cost != 0) {
200180
dq.push_back(v_target);
201-
}
202-
else
203-
{
181+
} else {
204182
dq.push_front(v_target);
205183
}
206184
}
207185
}
208186
}
209187
};
210-
} // namespace functions
211-
} // namespace pgrouting
188+
} // namespace functions
189+
} // namespace pgrouting
212190

213-
#endif // INCLUDE_MST_PGR_BINARYBREADTHFIRSTSEARCH_HPP_
191+
#endif // INCLUDE_BREADTHFIRSTSEARCH_PGR_BINARYBREADTHFIRSTSEARCH_HPP_

include/breadthFirstSearch/pgr_breadthFirstSearch.hpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@ along with this program; if not, write to the Free Software
2121
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2222
********************************************************************PGR-GNU*/
2323

24-
#ifndef INCLUDE_MST_PGR_BREADTHFIRSTSEARCH_HPP_
25-
#define INCLUDE_MST_PGR_BREADTHFIRSTSEARCH_HPP_
24+
#ifndef INCLUDE_BREADTHFIRSTSEARCH_PGR_BREADTHFIRSTSEARCH_HPP_
25+
#define INCLUDE_BREADTHFIRSTSEARCH_PGR_BREADTHFIRSTSEARCH_HPP_
2626
#pragma once
2727

28-
#include <vector>
2928

3029
#include <visitors/edges_order_bfs_visitor.hpp>
3130
#include <boost/graph/breadth_first_search.hpp>
3231

32+
#include <vector>
33+
3334
#include "cpp_common/pgr_base_graph.hpp"
3435
//******************************************
3536

@@ -38,7 +39,7 @@ namespace functions {
3839

3940
template <class G>
4041
class Pgr_breadthFirstSearch {
41-
public:
42+
public:
4243
typedef typename G::V V;
4344
typedef typename G::E E;
4445
typedef typename G::B_G B_G;
@@ -48,12 +49,10 @@ class Pgr_breadthFirstSearch {
4849
G &graph,
4950
std::vector<int64_t> start_vertex,
5051
int64_t depth) {
51-
5252
std::vector<pgr_mst_rt> results;
5353
using bfs_visitor = visitors::Edges_order_bfs_visitor<E>;
5454

5555
for (auto source : start_vertex) {
56-
5756
std::vector<E> visited_order;
5857

5958
if (graph.has_vertex(source)) {
@@ -65,15 +64,11 @@ class Pgr_breadthFirstSearch {
6564
auto single_source_results = get_results(visited_order, source, depth, graph);
6665
results.insert(results.end(), single_source_results.begin(), single_source_results.end());
6766
}
68-
6967
}
70-
7168
return results;
72-
7369
}
7470

75-
private:
76-
71+
private:
7772
template <typename T>
7873
std::vector<pgr_mst_rt> get_results(
7974
T order,
@@ -105,9 +100,8 @@ class Pgr_breadthFirstSearch {
105100
}
106101
return results;
107102
}
108-
109103
};
110-
} // namespace functions
111-
} // namespace pgrouting
104+
} // namespace functions
105+
} // namespace pgrouting
112106

113-
#endif // INCLUDE_MST_PGR_BREADTHFIRSTSEARCH_HPP_
107+
#endif // INCLUDE_BREADTHFIRSTSEARCH_PGR_BREADTHFIRSTSEARCH_HPP_

0 commit comments

Comments
 (0)