From f546e116f944c9c8cf116f1aab523fd7305992d8 Mon Sep 17 00:00:00 2001 From: Gvs Akhil Date: Thu, 8 Aug 2019 19:52:49 +0530 Subject: [PATCH 1/5] [lint] Lint fixes for binaryBreadthFirstSearch.c and binaryBreadthFirstSearch_driver.cpp --- .../binaryBreadthFirstSearch.c | 25 +++++----------- .../binaryBreadthFirstSearch_driver.cpp | 29 +++++++------------ 2 files changed, 19 insertions(+), 35 deletions(-) diff --git a/src/breadthFirstSearch/binaryBreadthFirstSearch.c b/src/breadthFirstSearch/binaryBreadthFirstSearch.c index d78986bdd4..f57b951f46 100644 --- a/src/breadthFirstSearch/binaryBreadthFirstSearch.c +++ b/src/breadthFirstSearch/binaryBreadthFirstSearch.c @@ -77,8 +77,7 @@ process( pgr_get_edges(edges_sql, &edges, &total_edges); PGR_DBG("Total %ld edges in query:", total_edges); - if (total_edges == 0) - { + if (total_edges == 0) { if (start_vidsArr) pfree(start_vidsArr); if (end_vidsArr) @@ -110,8 +109,7 @@ process( time_msg(" processing pgr_binaryBreadthFirstSearch", start_t, clock()); PGR_DBG("Returning %ld tuples", *result_count); - if (err_msg) - { + if (err_msg) { if (*result_tuples) pfree(*result_tuples); } @@ -134,8 +132,7 @@ process( pgr_SPI_finish(); } -PGDLLEXPORT Datum _pgr_binarybreadthfirstsearch(PG_FUNCTION_ARGS) -{ +PGDLLEXPORT Datum _pgr_binarybreadthfirstsearch(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; TupleDesc tuple_desc; @@ -144,8 +141,7 @@ PGDLLEXPORT Datum _pgr_binarybreadthfirstsearch(PG_FUNCTION_ARGS) size_t result_count = 0; /**************************************************************************/ - if (SRF_IS_FIRSTCALL()) - { + if (SRF_IS_FIRSTCALL()) { MemoryContext oldcontext; funcctx = SRF_FIRSTCALL_INIT(); oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); @@ -174,8 +170,7 @@ PGDLLEXPORT Datum _pgr_binarybreadthfirstsearch(PG_FUNCTION_ARGS) funcctx->max_calls = (uint32_t)result_count; #endif funcctx->user_fctx = result_tuples; - if (get_call_result_type(fcinfo, NULL, &tuple_desc) != TYPEFUNC_COMPOSITE) - { + if (get_call_result_type(fcinfo, NULL, &tuple_desc) != TYPEFUNC_COMPOSITE) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("function returning record called in context " @@ -190,8 +185,7 @@ PGDLLEXPORT Datum _pgr_binarybreadthfirstsearch(PG_FUNCTION_ARGS) tuple_desc = funcctx->tuple_desc; result_tuples = (General_path_element_t *)funcctx->user_fctx; - if (funcctx->call_cntr < funcctx->max_calls) - { + if (funcctx->call_cntr < funcctx->max_calls) { HeapTuple tuple; Datum result; Datum *values; @@ -214,8 +208,7 @@ PGDLLEXPORT Datum _pgr_binarybreadthfirstsearch(PG_FUNCTION_ARGS) nulls = palloc(numb * sizeof(bool)); size_t i; - for (i = 0; i < numb; ++i) - { + for (i = 0; i < numb; ++i) { nulls[i] = false; } @@ -233,9 +226,7 @@ PGDLLEXPORT Datum _pgr_binarybreadthfirstsearch(PG_FUNCTION_ARGS) tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); SRF_RETURN_NEXT(funcctx, result); - } - else - { + } else { /**********************************************************************/ PGR_DBG("Clean up code"); diff --git a/src/breadthFirstSearch/binaryBreadthFirstSearch_driver.cpp b/src/breadthFirstSearch/binaryBreadthFirstSearch_driver.cpp index c1052b9794..11b5e462fa 100644 --- a/src/breadthFirstSearch/binaryBreadthFirstSearch_driver.cpp +++ b/src/breadthFirstSearch/binaryBreadthFirstSearch_driver.cpp @@ -34,6 +34,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include +#include #include "breadthFirstSearch/pgr_binaryBreadthFirstSearch.hpp" @@ -46,7 +48,6 @@ pgr_binaryBreadthFirstSearch( G &graph, std::vector < int64_t > sources, std::vector < int64_t > targets) { - std::sort(sources.begin(), sources.end()); sources.erase( std::unique(sources.begin(), sources.end()), @@ -66,12 +67,11 @@ pgr_binaryBreadthFirstSearch( } const size_t MAX_UNIQUE_EDGE_COSTS = 2; -const std::string COST_ERR_MSG = - "Graph Condition Failed: Graph should have atmost two distinct non-negative edge costs! If there are exactly two distinct edge costs, one of them must equal zero!"; +const char COST_ERR_MSG[] = "Graph Condition Failed: Graph should have atmost two distinct non-negative edge costs!" + "If there are exactly two distinct edge costs, one of them must equal zero!"; template < class G > bool -costCheck(G &graph) -{ +costCheck(G &graph) { typedef typename G::E E; typedef typename G::E_i E_i; @@ -81,22 +81,17 @@ costCheck(G &graph) E_i out_end; std::set cost_set; for (boost::tie(out_i, out_end) = edges; - out_i != out_end; ++out_i) - { - + out_i != out_end; ++out_i) { e = *out_i; cost_set.insert(graph[e].cost); - if (cost_set.size() > MAX_UNIQUE_EDGE_COSTS) - { + if (cost_set.size() > MAX_UNIQUE_EDGE_COSTS) { return false; } } - if (cost_set.size() == 2) - { - if (*cost_set.begin() != 0.0) - { + if (cost_set.size() == 2) { + if (*cost_set.begin() != 0.0) { return false; } } @@ -148,12 +143,11 @@ do_pgr_binaryBreadthFirstSearch( pgrouting::DirectedGraph digraph(gType); digraph.insert_edges(data_edges, total_edges); - if(!(costCheck(digraph))){ + if (!(costCheck(digraph))) { err << COST_ERR_MSG; *err_msg = pgr_msg(err.str().c_str()); return; } - paths = pgr_binaryBreadthFirstSearch( digraph, start_vertices, @@ -164,7 +158,7 @@ do_pgr_binaryBreadthFirstSearch( pgrouting::UndirectedGraph undigraph(gType); undigraph.insert_edges(data_edges, total_edges); - if(!(costCheck(undigraph))){ + if (!(costCheck(undigraph))) { err << COST_ERR_MSG; *err_msg = pgr_msg(err.str().c_str()); return; @@ -174,7 +168,6 @@ do_pgr_binaryBreadthFirstSearch( undigraph, start_vertices, end_vertices); - } size_t count(0); From e95f003d96074070616ecd29c11091e9379fac5b Mon Sep 17 00:00:00 2001 From: Gvs Akhil Date: Thu, 8 Aug 2019 20:10:23 +0530 Subject: [PATCH 2/5] [lint] Lint fixes for breadthFirstSearch.c and breadthFirstSearch_driver.cpp --- src/breadthFirstSearch/breadthFirstSearch.c | 25 ++++++------------- .../breadthFirstSearch_driver.cpp | 5 ++-- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/breadthFirstSearch/breadthFirstSearch.c b/src/breadthFirstSearch/breadthFirstSearch.c index 40a6ae7bd3..adb0fed441 100644 --- a/src/breadthFirstSearch/breadthFirstSearch.c +++ b/src/breadthFirstSearch/breadthFirstSearch.c @@ -73,8 +73,7 @@ process( pgr_get_edges(edges_sql, &edges, &total_edges); PGR_DBG("Total %ld edges in query:", total_edges); - if (total_edges == 0) - { + if (total_edges == 0) { if (start_vidsArr) pfree(start_vidsArr); pgr_SPI_finish(); @@ -103,8 +102,7 @@ process( time_msg(" processing pgr_breadthFirstSearch", start_t, clock()); PGR_DBG("Returning %ld tuples", *result_count); - if (err_msg) - { + if (err_msg) { if (*result_tuples) pfree(*result_tuples); } @@ -125,8 +123,7 @@ process( pgr_SPI_finish(); } -PGDLLEXPORT Datum _pgr_breadthfirstsearch(PG_FUNCTION_ARGS) -{ +PGDLLEXPORT Datum _pgr_breadthfirstsearch(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; TupleDesc tuple_desc; @@ -135,8 +132,7 @@ PGDLLEXPORT Datum _pgr_breadthfirstsearch(PG_FUNCTION_ARGS) size_t result_count = 0; /**************************************************************************/ - if (SRF_IS_FIRSTCALL()) - { + if (SRF_IS_FIRSTCALL()) { MemoryContext oldcontext; funcctx = SRF_FIRSTCALL_INIT(); oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); @@ -168,8 +164,7 @@ PGDLLEXPORT Datum _pgr_breadthfirstsearch(PG_FUNCTION_ARGS) funcctx->max_calls = (uint32_t)result_count; #endif funcctx->user_fctx = result_tuples; - if (get_call_result_type(fcinfo, NULL, &tuple_desc) != TYPEFUNC_COMPOSITE) - { + if (get_call_result_type(fcinfo, NULL, &tuple_desc) != TYPEFUNC_COMPOSITE) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("function returning record called in context " @@ -184,8 +179,7 @@ PGDLLEXPORT Datum _pgr_breadthfirstsearch(PG_FUNCTION_ARGS) tuple_desc = funcctx->tuple_desc; result_tuples = (pgr_mst_rt *)funcctx->user_fctx; - if (funcctx->call_cntr < funcctx->max_calls) - { + if (funcctx->call_cntr < funcctx->max_calls) { HeapTuple tuple; Datum result; Datum *values; @@ -207,8 +201,7 @@ PGDLLEXPORT Datum _pgr_breadthfirstsearch(PG_FUNCTION_ARGS) nulls = palloc(numb * sizeof(bool)); size_t i; - for (i = 0; i < numb; ++i) - { + for (i = 0; i < numb; ++i) { nulls[i] = false; } @@ -225,9 +218,7 @@ PGDLLEXPORT Datum _pgr_breadthfirstsearch(PG_FUNCTION_ARGS) tuple = heap_form_tuple(tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); SRF_RETURN_NEXT(funcctx, result); - } - else - { + } else { /**********************************************************************/ PGR_DBG("Clean up code"); diff --git a/src/breadthFirstSearch/breadthFirstSearch_driver.cpp b/src/breadthFirstSearch/breadthFirstSearch_driver.cpp index a19317a9b4..3e89bd5acd 100644 --- a/src/breadthFirstSearch/breadthFirstSearch_driver.cpp +++ b/src/breadthFirstSearch/breadthFirstSearch_driver.cpp @@ -31,6 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include +#include #include "cpp_common/pgr_alloc.hpp" #include "cpp_common/pgr_assert.h" @@ -92,7 +93,6 @@ do_pgr_breadthFirstSearch( log << "Working with directed Graph\n"; pgrouting::DirectedGraph digraph(gType); digraph.insert_edges(data_edges, total_edges); - results = pgr_breadthFirstSearch( digraph, start_vertices, @@ -107,7 +107,6 @@ do_pgr_breadthFirstSearch( undigraph, start_vertices, max_depth); - } auto count = results.size(); @@ -123,7 +122,7 @@ do_pgr_breadthFirstSearch( (*return_tuples) = pgr_alloc(count, (*return_tuples)); log << "\nConverting a set of traversals into the tuples"; - for(size_t i = 0; i < count; i++){ + for (size_t i = 0; i < count; i++) { *((*return_tuples) + i) = results[i]; } (*return_count) = count; From 028bc0b9c95c637b65fc85499142d768ec88af32 Mon Sep 17 00:00:00 2001 From: Gvs Akhil Date: Thu, 8 Aug 2019 20:21:49 +0530 Subject: [PATCH 3/5] Typo fix --- src/breadthFirstSearch/binaryBreadthFirstSearch_driver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/breadthFirstSearch/binaryBreadthFirstSearch_driver.cpp b/src/breadthFirstSearch/binaryBreadthFirstSearch_driver.cpp index 11b5e462fa..efcfbe846b 100644 --- a/src/breadthFirstSearch/binaryBreadthFirstSearch_driver.cpp +++ b/src/breadthFirstSearch/binaryBreadthFirstSearch_driver.cpp @@ -67,7 +67,7 @@ pgr_binaryBreadthFirstSearch( } const size_t MAX_UNIQUE_EDGE_COSTS = 2; -const char COST_ERR_MSG[] = "Graph Condition Failed: Graph should have atmost two distinct non-negative edge costs!" +const char COST_ERR_MSG[] = "Graph Condition Failed: Graph should have atmost two distinct non-negative edge costs! " "If there are exactly two distinct edge costs, one of them must equal zero!"; template < class G > bool From b73305cdc446a9cb042305639296567c80574a44 Mon Sep 17 00:00:00 2001 From: Gvs Akhil Date: Thu, 8 Aug 2019 21:07:13 +0530 Subject: [PATCH 4/5] [lint] Lint fixes for pgr_binaryBreadthFirstSearch.hpp and pgr_breadthFirstSearch.hpp --- .../pgr_binaryBreadthFirstSearch.hpp | 78 +++++++------------ .../pgr_breadthFirstSearch.hpp | 24 +++--- 2 files changed, 37 insertions(+), 65 deletions(-) diff --git a/include/breadthFirstSearch/pgr_binaryBreadthFirstSearch.hpp b/include/breadthFirstSearch/pgr_binaryBreadthFirstSearch.hpp index 928a4cda6f..a0816c8121 100644 --- a/include/breadthFirstSearch/pgr_binaryBreadthFirstSearch.hpp +++ b/include/breadthFirstSearch/pgr_binaryBreadthFirstSearch.hpp @@ -21,28 +21,27 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_MST_PGR_BINARYBREADTHFIRSTSEARCH_HPP_ -#define INCLUDE_MST_PGR_BINARYBREADTHFIRSTSEARCH_HPP_ +#ifndef INCLUDE_BREADTHFIRSTSEARCH_PGR_BINARYBREADTHFIRSTSEARCH_HPP_ +#define INCLUDE_BREADTHFIRSTSEARCH_PGR_BINARYBREADTHFIRSTSEARCH_HPP_ #pragma once #include #include #include +#include +#include #include "cpp_common/basePath_SSEC.hpp" #include "cpp_common/pgr_base_graph.hpp" #include "cpp_common/pgr_assert.h" //****************************************** -namespace pgrouting -{ -namespace functions -{ +namespace pgrouting { +namespace functions { template -class Pgr_binaryBreadthFirstSearch -{ -public: +class Pgr_binaryBreadthFirstSearch { + public: typedef typename G::V V; typedef typename G::E E; typedef typename G::B_G B_G; @@ -53,18 +52,15 @@ class Pgr_binaryBreadthFirstSearch G &graph, std::vector start_vertex, std::vector end_vertex) { - std::deque paths; - for(auto source : start_vertex) { + for (auto source : start_vertex) { std::deque result_paths = one_to_many_binaryBreadthFirstSearch( graph, source, - end_vertex - ); - + end_vertex); paths.insert( - paths.begin(), + paths.begin(), std::make_move_iterator(result_paths.begin()), std::make_move_iterator(result_paths.end())); } @@ -81,20 +77,16 @@ class Pgr_binaryBreadthFirstSearch return paths; } - private: - + private: E DEFAULT_EDGE; std::deque one_to_many_binaryBreadthFirstSearch( G &graph, int64_t start_vertex, - std::vector end_vertex) - { - + std::vector end_vertex) { std::deque paths; - if (graph.has_vertex(start_vertex) == false) - { + if (graph.has_vertex(start_vertex) == false) { return paths; } @@ -108,8 +100,7 @@ class Pgr_binaryBreadthFirstSearch current_cost[bgl_start_vertex] = 0; dq.push_front(bgl_start_vertex); - while (dq.empty() == false) - { + while (dq.empty() == false) { int64_t head_vertex = dq.front(); dq.pop_front(); @@ -117,17 +108,14 @@ class Pgr_binaryBreadthFirstSearch updateVertexCosts(graph, current_cost, from_edge, dq, head_vertex); } - for (auto target_vertex : end_vertex) - { - if (graph.has_vertex(target_vertex) == false) - { + for (auto target_vertex : end_vertex) { + if (graph.has_vertex(target_vertex) == false) { continue; } int64_t bgl_target_vertex = graph.get_V(target_vertex); - if (from_edge[bgl_target_vertex] == DEFAULT_EDGE) - { + if (from_edge[bgl_target_vertex] == DEFAULT_EDGE) { continue; } @@ -144,16 +132,14 @@ class Pgr_binaryBreadthFirstSearch int64_t target, int64_t bgl_target_vertex, std::vector &from_edge, - std::vector ¤t_cost) - { + std::vector ¤t_cost) { int64_t current_node = bgl_target_vertex; Path path = Path(graph[bgl_start_vertex].id, graph[current_node].id); path.push_back({target, -1, 0, current_cost[current_node]}); - do - { + do { E e = from_edge[current_node]; auto from = graph.source(e); @@ -171,8 +157,7 @@ class Pgr_binaryBreadthFirstSearch std::vector ¤t_cost, std::vector &from_edge, std::deque &dq, - int64_t &head_vertex) - { + int64_t &head_vertex) { auto out_edges = boost::out_edges(head_vertex, graph.graph); E e; EO_i out_i; @@ -180,34 +165,27 @@ class Pgr_binaryBreadthFirstSearch V v_source, v_target; for (boost::tie(out_i, out_end) = out_edges; - out_i != out_end; ++out_i) - { - + out_i != out_end; ++out_i) { e = *out_i; v_target = graph.target(e); v_source = graph.source(e); double edge_cost = graph[e].cost; - if (std::isinf(current_cost[v_target]) or current_cost[v_source] + edge_cost < current_cost[v_target]) - { - + if (std::isinf(current_cost[v_target]) || current_cost[v_source] + edge_cost < current_cost[v_target]) { current_cost[v_target] = current_cost[v_source] + edge_cost; from_edge[v_target] = e; - if (edge_cost != 0) - { + if (edge_cost != 0) { dq.push_back(v_target); - } - else - { + } else { dq.push_front(v_target); } } } } }; -} // namespace functions -} // namespace pgrouting +} // namespace functions +} // namespace pgrouting -#endif // INCLUDE_MST_PGR_BINARYBREADTHFIRSTSEARCH_HPP_ +#endif // INCLUDE_BREADTHFIRSTSEARCH_PGR_BINARYBREADTHFIRSTSEARCH_HPP_ diff --git a/include/breadthFirstSearch/pgr_breadthFirstSearch.hpp b/include/breadthFirstSearch/pgr_breadthFirstSearch.hpp index e11b0583f5..4d9118bb29 100644 --- a/include/breadthFirstSearch/pgr_breadthFirstSearch.hpp +++ b/include/breadthFirstSearch/pgr_breadthFirstSearch.hpp @@ -21,15 +21,16 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_MST_PGR_BREADTHFIRSTSEARCH_HPP_ -#define INCLUDE_MST_PGR_BREADTHFIRSTSEARCH_HPP_ +#ifndef INCLUDE_BREADTHFIRSTSEARCH_PGR_BREADTHFIRSTSEARCH_HPP_ +#define INCLUDE_BREADTHFIRSTSEARCH_PGR_BREADTHFIRSTSEARCH_HPP_ #pragma once -#include #include #include +#include + #include "cpp_common/pgr_base_graph.hpp" //****************************************** @@ -38,7 +39,7 @@ namespace functions { template class Pgr_breadthFirstSearch { -public: + public: typedef typename G::V V; typedef typename G::E E; typedef typename G::B_G B_G; @@ -48,12 +49,10 @@ class Pgr_breadthFirstSearch { G &graph, std::vector start_vertex, int64_t depth) { - std::vector results; using bfs_visitor = visitors::Edges_order_bfs_visitor; for (auto source : start_vertex) { - std::vector visited_order; if (graph.has_vertex(source)) { @@ -65,15 +64,11 @@ class Pgr_breadthFirstSearch { auto single_source_results = get_results(visited_order, source, depth, graph); results.insert(results.end(), single_source_results.begin(), single_source_results.end()); } - } - return results; - } -private: - + private: template std::vector get_results( T order, @@ -105,9 +100,8 @@ class Pgr_breadthFirstSearch { } return results; } - }; -} // namespace functions -} // namespace pgrouting +} // namespace functions +} // namespace pgrouting -#endif // INCLUDE_MST_PGR_BREADTHFIRSTSEARCH_HPP_ +#endif // INCLUDE_BREADTHFIRSTSEARCH_PGR_BREADTHFIRSTSEARCH_HPP_ From a0ec10ff301c5e46132a1312ea24c43cf0537673 Mon Sep 17 00:00:00 2001 From: Gvs Akhil Date: Thu, 8 Aug 2019 21:09:59 +0530 Subject: [PATCH 5/5] [lint] Lint fixes for binaryBreadthFirstSearch_driver.h --- .../breadthFirstSearch/binaryBreadthFirstSearch_driver.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/drivers/breadthFirstSearch/binaryBreadthFirstSearch_driver.h b/include/drivers/breadthFirstSearch/binaryBreadthFirstSearch_driver.h index aadab2cbc0..0e6e3ca3f0 100644 --- a/include/drivers/breadthFirstSearch/binaryBreadthFirstSearch_driver.h +++ b/include/drivers/breadthFirstSearch/binaryBreadthFirstSearch_driver.h @@ -27,8 +27,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_DRIVERS_BINARYBREADTHFIRSTSEARCH_BINARYBREADTHFIRSTSEARCH_DRIVER_H_ -#define INCLUDE_DRIVERS_BINARYBREADTHFIRSTSEARCH_BINARYBREADTHFIRSTSEARCH_DRIVER_H_ +#ifndef INCLUDE_DRIVERS_BREADTHFIRSTSEARCH_BINARYBREADTHFIRSTSEARCH_DRIVER_H_ +#define INCLUDE_DRIVERS_BREADTHFIRSTSEARCH_BINARYBREADTHFIRSTSEARCH_DRIVER_H_ #pragma once /* for size-t */ @@ -75,4 +75,4 @@ extern "C" { } #endif -#endif // INCLUDE_DRIVERS_BINARYBREADTHFIRSTSEARCH_BINARYBREADTHFIRSTSEARCH_DRIVER_H_ +#endif // INCLUDE_DRIVERS_BREADTHFIRSTSEARCH_BINARYBREADTHFIRSTSEARCH_DRIVER_H_