Skip to content

Commit 1ebb6e6

Browse files
committed
Using get_tuples for MST_rt instead of Path::collapse_paths
1 parent 615a9a2 commit 1ebb6e6

2 files changed

Lines changed: 17 additions & 26 deletions

File tree

src/driving_distance/driving_distance_driver.cpp

Lines changed: 7 additions & 10 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
#include "dijkstra/drivingDist.hpp"
4040

4141
#include "c_types/mst_rt.h"
42-
#include "cpp_common/alloc.hpp"
42+
#include "cpp_common/to_postgres.hpp"
4343
#include "cpp_common/assert.hpp"
4444

4545

@@ -74,6 +74,8 @@ pgr_do_drivingDistance(
7474
pgassert(*return_count == 0);
7575
pgassert((*return_tuples) == NULL);
7676

77+
using pgrouting::to_postgres::get_tuples;
78+
7779
auto roots = get_intSet(starts);
7880

7981
hint = edges_sql;
@@ -99,18 +101,14 @@ pgr_do_drivingDistance(
99101
paths = drivingDistance(undigraph, roots, distance, equiCostFlag, depths, true);
100102
}
101103

102-
size_t count(count_tuples(paths));
104+
*return_count = get_tuples(paths, *return_tuples);
103105

104-
if (count == 0) {
105-
log << "\nNo return values were found";
106-
*notice_msg = to_pg_msg(log);
106+
if (*return_count == 0) {
107+
*log_msg = to_pg_msg("No paths found");
107108
return;
108109
}
109110

110-
*return_tuples = pgr_alloc(count, (*return_tuples));
111-
*return_count = collapse_paths(return_tuples, paths);
112-
113-
for (size_t i = 0; i < count; i++) {
111+
for (size_t i = 0; i < *return_count; i++) {
114112
auto row = (*return_tuples)[i];
115113
/* given the depth assign the correct depth */
116114
int64_t depth = -1;
@@ -122,7 +120,6 @@ pgr_do_drivingDistance(
122120
}
123121
(*return_tuples)[i].depth = depth;
124122
}
125-
(*return_count) = count;
126123

127124
*log_msg = to_pg_msg(log);
128125
*notice_msg = to_pg_msg(notice);

src/driving_distance/driving_distance_withPoints_driver.cpp

Lines changed: 10 additions & 16 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 "withPoints/withPoints.hpp"
4545
#include "c_types/mst_rt.h"
4646
#include "cpp_common/combinations.hpp"
47-
#include "cpp_common/alloc.hpp"
47+
#include "cpp_common/to_postgres.hpp"
4848

4949

5050
void
@@ -66,7 +66,6 @@ pgr_do_withPointsDD(
6666
char** notice_msg,
6767
char** err_msg) {
6868
using pgrouting::Path;
69-
using pgrouting::pgr_alloc;
7069
using pgrouting::to_pg_msg;
7170
using pgrouting::pgr_free;
7271
using pgrouting::pgget::get_intSet;
@@ -87,6 +86,8 @@ pgr_do_withPointsDD(
8786
pgassert(!(*return_tuples));
8887
pgassert(*return_count == 0);
8988

89+
using pgrouting::to_postgres::get_tuples;
90+
9091
auto roots = get_intSet(starts);
9192

9293
hint = points_sql;
@@ -141,21 +142,14 @@ pgr_do_withPointsDD(
141142
}
142143

143144

144-
auto count(count_tuples(paths));
145-
145+
*return_count = get_tuples(paths, *return_tuples);
146146

147-
if (count == 0) {
148-
(*return_tuples) = NULL;
149-
(*return_count) = 0;
150-
notice << "No paths found";
151-
*log_msg = to_pg_msg(notice);
147+
if (*return_count == 0) {
148+
*log_msg = to_pg_msg("No paths found");
152149
return;
153150
}
154151

155-
(*return_tuples) = pgr_alloc(count, (*return_tuples));
156-
(*return_count) = (collapse_paths(return_tuples, paths));
157-
158-
for (size_t i = 0; i < count; i++) {
152+
for (size_t i = 0; i < *return_count; i++) {
159153
auto row = (*return_tuples)[i];
160154
/* given the depth assign the correct depth */
161155
int64_t depth = -1;
@@ -169,11 +163,11 @@ pgr_do_withPointsDD(
169163
}
170164

171165
/* sort to get depths in order*/
172-
std::sort((*return_tuples), (*return_tuples) + count,
166+
std::sort((*return_tuples), (*return_tuples) + *return_count,
173167
[](const MST_rt &l, const MST_rt &r) {return l.agg_cost < r.agg_cost;});
174-
std::stable_sort((*return_tuples), (*return_tuples) + count,
168+
std::stable_sort((*return_tuples), (*return_tuples) + *return_count,
175169
[](const MST_rt &l, const MST_rt &r) {return l.depth < r.depth;});
176-
std::stable_sort((*return_tuples), (*return_tuples) + count,
170+
std::stable_sort((*return_tuples), (*return_tuples) + *return_count,
177171
[](const MST_rt &l, const MST_rt &r) {return l.from_v < r.from_v;});
178172

179173
*log_msg = to_pg_msg(log);

0 commit comments

Comments
 (0)