Skip to content

Commit ec9c6e4

Browse files
committed
Using get_tuples for Path_rt instead of Path::collapse_paths
1 parent 20fef7d commit ec9c6e4

13 files changed

Lines changed: 68 additions & 173 deletions

src/astar/astar_driver.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
3939

4040
#include "cpp_common/combinations.hpp"
4141
#include "cpp_common/pgdata_getters.hpp"
42-
#include "cpp_common/alloc.hpp"
42+
#include "cpp_common/to_postgres.hpp"
4343
#include "cpp_common/assert.hpp"
4444

4545
#include "cpp_common/edge_xy_t.hpp"
@@ -60,7 +60,6 @@ void pgr_do_astar(
6060
Path_rt **return_tuples, size_t *return_count,
6161
char** log_msg, char** notice_msg, char** err_msg) {
6262
using pgrouting::Path;
63-
using pgrouting::pgr_alloc;
6463
using pgrouting::to_pg_msg;
6564
using pgrouting::pgr_free;
6665
using pgrouting::utilities::get_combinations;
@@ -77,6 +76,8 @@ void pgr_do_astar(
7776
pgassert(!(*return_tuples));
7877
pgassert(*return_count == 0);
7978

79+
using pgrouting::to_postgres::get_tuples;
80+
8081
(*return_tuples) = nullptr;
8182
(*return_count) = 0;
8283

@@ -121,20 +122,13 @@ void pgr_do_astar(
121122
}
122123
}
123124

124-
size_t count(0);
125-
count = count_tuples(paths);
125+
(*return_count) = get_tuples(paths, (*return_tuples));
126126

127-
if (count == 0) {
128-
(*return_tuples) = nullptr;
129-
(*return_count) = 0;
130-
notice << "No paths found\n";
131-
*log_msg = to_pg_msg(notice);
127+
if (*return_count == 0) {
128+
*log_msg = to_pg_msg("No paths found");
132129
return;
133130
}
134131

135-
(*return_tuples) = pgr_alloc(count, (*return_tuples));
136-
(*return_count) = (collapse_paths(return_tuples, paths));
137-
138132
*log_msg = to_pg_msg(log);
139133
*notice_msg = to_pg_msg(notice);
140134
} catch (AssertFailedException &except) {

src/bdAstar/bdAstar_driver.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
4040

4141
#include "cpp_common/combinations.hpp"
4242
#include "cpp_common/pgdata_getters.hpp"
43-
#include "cpp_common/alloc.hpp"
43+
#include "cpp_common/to_postgres.hpp"
4444
#include "cpp_common/assert.hpp"
4545

4646
#include "cpp_common/edge_xy_t.hpp"
@@ -61,7 +61,6 @@ void pgr_do_bdAstar(
6161
Path_rt **return_tuples, size_t *return_count,
6262
char** log_msg, char** notice_msg, char** err_msg) {
6363
using pgrouting::Path;
64-
using pgrouting::pgr_alloc;
6564
using pgrouting::to_pg_msg;
6665
using pgrouting::pgr_free;
6766
using pgrouting::utilities::get_combinations;
@@ -78,6 +77,8 @@ void pgr_do_bdAstar(
7877
pgassert(!(*return_tuples));
7978
pgassert(*return_count == 0);
8079

80+
using pgrouting::to_postgres::get_tuples;
81+
8182
hint = combinations_sql;
8283
auto combinations = get_combinations(combinations_sql, starts, ends, true);
8384
hint = nullptr;
@@ -111,20 +112,13 @@ void pgr_do_bdAstar(
111112
paths = pgrouting::algorithms::bdastar(graph, combinations, heuristic, factor, epsilon, only_cost);
112113
}
113114

114-
size_t count(0);
115-
count = count_tuples(paths);
115+
(*return_count) = get_tuples(paths, (*return_tuples));
116116

117-
if (count == 0) {
118-
(*return_tuples) = nullptr;
119-
(*return_count) = 0;
120-
notice << "No paths found\n";
121-
*log_msg = to_pg_msg(notice);
117+
if (*return_count == 0) {
118+
*log_msg = to_pg_msg("No paths found");
122119
return;
123120
}
124121

125-
(*return_tuples) = pgr_alloc(count, (*return_tuples));
126-
(*return_count) = (collapse_paths(return_tuples, paths));
127-
128122
*log_msg = to_pg_msg(log);
129123
*notice_msg = to_pg_msg(notice);
130124
} catch (AssertFailedException &except) {

src/bdDijkstra/bdDijkstra_driver.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
4040

4141
#include "cpp_common/combinations.hpp"
4242
#include "cpp_common/pgdata_getters.hpp"
43-
#include "cpp_common/alloc.hpp"
43+
#include "cpp_common/to_postgres.hpp"
4444
#include "cpp_common/assert.hpp"
4545
#include "cpp_common/base_graph.hpp"
4646
#include "bdDijkstra/bdDijkstra.hpp"
@@ -94,7 +94,6 @@ pgr_do_bdDijkstra(
9494
char **notice_msg,
9595
char **err_msg) {
9696
using pgrouting::Path;
97-
using pgrouting::pgr_alloc;
9897
using pgrouting::to_pg_msg;
9998
using pgrouting::pgr_free;
10099
using pgrouting::utilities::get_combinations;
@@ -111,6 +110,8 @@ pgr_do_bdDijkstra(
111110
pgassert(!(*return_tuples));
112111
pgassert(*return_count == 0);
113112

113+
using pgrouting::to_postgres::get_tuples;
114+
114115
hint = combinations_sql;
115116
auto combinations = get_combinations(combinations_sql, starts, ends, true);
116117
hint = nullptr;
@@ -145,19 +146,13 @@ pgr_do_bdDijkstra(
145146
paths = pgr_bdDijkstra(graph, combinations, only_cost);
146147
}
147148

148-
auto count = count_tuples(paths);
149+
(*return_count) = get_tuples(paths, (*return_tuples));
149150

150-
if (count == 0) {
151-
(*return_tuples) = NULL;
152-
(*return_count) = 0;
153-
notice << "No paths found";
154-
*log_msg = to_pg_msg(notice);
151+
if (*return_count == 0) {
152+
*log_msg = to_pg_msg("No paths found");
155153
return;
156154
}
157155

158-
(*return_tuples) = pgr_alloc(count, (*return_tuples));
159-
(*return_count) = (collapse_paths(return_tuples, paths));
160-
161156
*log_msg = to_pg_msg(log);
162157
*notice_msg = to_pg_msg(notice);
163158
} catch (AssertFailedException &except) {

src/bellman_ford/bellman_ford_driver.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
4141

4242
#include "cpp_common/combinations.hpp"
4343
#include "cpp_common/pgdata_getters.hpp"
44-
#include "cpp_common/alloc.hpp"
44+
#include "cpp_common/to_postgres.hpp"
4545
#include "cpp_common/assert.hpp"
4646

4747
#include "c_types/ii_t_rt.h"
@@ -78,7 +78,6 @@ pgr_do_bellman_ford(
7878
char ** notice_msg,
7979
char ** err_msg) {
8080
using pgrouting::Path;
81-
using pgrouting::pgr_alloc;
8281
using pgrouting::to_pg_msg;
8382
using pgrouting::pgr_free;
8483
using pgrouting::utilities::get_combinations;
@@ -96,6 +95,7 @@ pgr_do_bellman_ford(
9695
pgassert(!(*return_tuples));
9796
pgassert(*return_count == 0);
9897

98+
using pgrouting::to_postgres::get_tuples;
9999

100100

101101
hint = combinations_sql;
@@ -129,20 +129,13 @@ pgr_do_bellman_ford(
129129
paths = bellman_ford(undigraph, combinations, only_cost);
130130
}
131131

132-
size_t count(0);
133-
count = count_tuples(paths);
132+
(*return_count) = get_tuples(paths, (*return_tuples));
134133

135-
if (count == 0) {
136-
(*return_tuples) = NULL;
137-
(*return_count) = 0;
138-
notice << "No paths found";
139-
*log_msg = to_pg_msg(notice);
134+
if (*return_count == 0) {
135+
*log_msg = to_pg_msg("No paths found");
140136
return;
141137
}
142138

143-
(*return_tuples) = pgr_alloc(count, (*return_tuples));
144-
(*return_count) = (collapse_paths(return_tuples, paths));
145-
146139
*log_msg = to_pg_msg(log);
147140
*notice_msg = to_pg_msg(notice);
148141
} catch (AssertFailedException &except) {

src/bellman_ford/edwardMoore_driver.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
4444
#include "cpp_common/pgdata_getters.hpp"
4545
#include "cpp_common/path.hpp"
4646
#include "cpp_common/base_graph.hpp"
47-
#include "cpp_common/alloc.hpp"
47+
#include "cpp_common/to_postgres.hpp"
4848
#include "cpp_common/assert.hpp"
4949

5050
#include "c_types/ii_t_rt.h"
@@ -78,7 +78,6 @@ pgr_do_edwardMoore(
7878
char ** notice_msg,
7979
char ** err_msg) {
8080
using pgrouting::Path;
81-
using pgrouting::pgr_alloc;
8281
using pgrouting::to_pg_msg;
8382
using pgrouting::pgr_free;
8483
using pgrouting::utilities::get_combinations;
@@ -96,6 +95,7 @@ pgr_do_edwardMoore(
9695
pgassert(!(*return_tuples));
9796
pgassert(*return_count == 0);
9897

98+
using pgrouting::to_postgres::get_tuples;
9999

100100

101101
hint = combinations_sql;
@@ -129,20 +129,13 @@ pgr_do_edwardMoore(
129129
paths = edwardMoore(undigraph, combinations);
130130
}
131131

132-
size_t count(0);
133-
count = count_tuples(paths);
132+
(*return_count) = get_tuples(paths, (*return_tuples));
134133

135-
if (count == 0) {
136-
(*return_tuples) = NULL;
137-
(*return_count) = 0;
138-
notice << "No paths found";
139-
*log_msg = to_pg_msg(notice);
134+
if (*return_count == 0) {
135+
*log_msg = to_pg_msg("No paths found");
140136
return;
141137
}
142138

143-
(*return_tuples) = pgr_alloc(count, (*return_tuples));
144-
(*return_count) = (collapse_paths(return_tuples, paths));
145-
146139
*log_msg = to_pg_msg(log);
147140
*notice_msg = to_pg_msg(notice);
148141
} catch (AssertFailedException &except) {

src/breadthFirstSearch/binaryBreadthFirstSearch_driver.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
4242

4343
#include "cpp_common/combinations.hpp"
4444
#include "cpp_common/pgdata_getters.hpp"
45-
#include "cpp_common/alloc.hpp"
45+
#include "cpp_common/to_postgres.hpp"
4646
#include "cpp_common/assert.hpp"
4747

4848
namespace {
@@ -135,7 +135,6 @@ pgr_do_binaryBreadthFirstSearch(
135135
char ** notice_msg,
136136
char ** err_msg) {
137137
using pgrouting::Path;
138-
using pgrouting::pgr_alloc;
139138
using pgrouting::to_pg_msg;
140139
using pgrouting::pgr_free;
141140
using pgrouting::utilities::get_combinations;
@@ -155,6 +154,7 @@ pgr_do_binaryBreadthFirstSearch(
155154
pgassert(!(*return_tuples));
156155
pgassert(*return_count == 0);
157156

157+
using pgrouting::to_postgres::get_tuples;
158158

159159

160160
hint = combinations_sql;
@@ -202,22 +202,13 @@ pgr_do_binaryBreadthFirstSearch(
202202
paths = binaryBreadthFirstSearch(undigraph, combinations);
203203
}
204204

205-
size_t count(0);
206-
count = count_tuples(paths);
205+
(*return_count) = get_tuples(paths, (*return_tuples));
207206

208-
if (count == 0) {
209-
(*return_tuples) = NULL;
210-
(*return_count) = 0;
211-
notice <<
212-
"No paths found";
213-
*log_msg = to_pg_msg(notice);
207+
if (*return_count == 0) {
208+
*log_msg = to_pg_msg("No paths found");
214209
return;
215210
}
216211

217-
(*return_tuples) = pgr_alloc(count, (*return_tuples));
218-
log << "\nConverting a set of paths into the tuples";
219-
(*return_count) = (collapse_paths(return_tuples, paths));
220-
221212
*log_msg = to_pg_msg(log);
222213
*notice_msg = to_pg_msg(notice);
223214
} catch (AssertFailedException &except) {

src/common/path.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -282,18 +282,6 @@ Path::sort_by_node_agg_cost() {
282282
*/
283283

284284

285-
size_t
286-
collapse_paths(
287-
Path_rt **ret_path,
288-
const std::deque< Path > &paths) {
289-
size_t sequence = 0;
290-
for (const Path &path : paths) {
291-
if (path.path.size() > 0) {
292-
path.generate_postgres_data(ret_path, sequence);
293-
}
294-
}
295-
return sequence;
296-
}
297285

298286
/*
299287
* sort the paths by size from greater to smaller

src/dagShortestPath/dagShortestPath_driver.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
4141

4242
#include "cpp_common/combinations.hpp"
4343
#include "cpp_common/pgdata_getters.hpp"
44-
#include "cpp_common/alloc.hpp"
44+
#include "cpp_common/to_postgres.hpp"
4545
#include "cpp_common/assert.hpp"
4646

4747
namespace {
@@ -75,7 +75,6 @@ pgr_do_dagShortestPath(
7575
char **notice_msg,
7676
char **err_msg) {
7777
using pgrouting::Path;
78-
using pgrouting::pgr_alloc;
7978
using pgrouting::to_pg_msg;
8079
using pgrouting::pgr_free;
8180
using pgrouting::utilities::get_combinations;
@@ -94,6 +93,8 @@ pgr_do_dagShortestPath(
9493
pgassert(!(*return_tuples));
9594
pgassert(*return_count == 0);
9695

96+
using pgrouting::to_postgres::get_tuples;
97+
9798
hint = combinations_sql;
9899
auto combinations = get_combinations(combinations_sql, starts, ends, normal);
99100
hint = nullptr;
@@ -121,18 +122,13 @@ pgr_do_dagShortestPath(
121122
graph.insert_edges(edges);
122123
paths = pgr_dagShortestPath(graph, combinations, only_cost);
123124

124-
auto count = count_tuples(paths);
125+
(*return_count) = get_tuples(paths, (*return_tuples));
125126

126-
if (count == 0) {
127-
(*return_tuples) = NULL;
128-
(*return_count) = 0;
127+
if (*return_count == 0) {
129128
*log_msg = to_pg_msg("No paths found");
130129
return;
131130
}
132131

133-
(*return_tuples) = pgr_alloc(count, (*return_tuples));
134-
(*return_count) = (collapse_paths(return_tuples, paths));
135-
136132
*log_msg = to_pg_msg(log);
137133
*notice_msg = to_pg_msg(notice);
138134
} catch (AssertFailedException &except) {

0 commit comments

Comments
 (0)