Skip to content

Commit c20342d

Browse files
committed
[withPoints] Reading data on C++ code
1 parent 15ab32d commit c20342d

File tree

6 files changed

+161
-294
lines changed

6 files changed

+161
-294
lines changed

include/drivers/withPoints/withPointsVia_driver.h

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,26 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2929
#define INCLUDE_DRIVERS_WITHPOINTS_WITHPOINTSVIA_DRIVER_H_
3030
#pragma once
3131

32+
#ifdef __cplusplus
33+
extern "C" {
34+
#endif
35+
36+
#include <postgres.h>
37+
#include <utils/array.h>
38+
39+
#ifdef __cplusplus
40+
}
41+
#endif
42+
43+
#include "cpp_common/undefPostgresDefine.hpp"
44+
3245
#ifdef __cplusplus
3346
# include <cstdint>
3447
# include <cstddef>
35-
using Point_on_edge_t = struct Point_on_edge_t;
36-
using Edge_t = struct Edge_t;
3748
using Routes_t = struct Routes_t;
3849
#else
3950
# include <stddef.h>
4051
# include <stdint.h>
41-
typedef struct Point_on_edge_t Point_on_edge_t;
42-
typedef struct Edge_t Edge_t;
4352
typedef struct Routes_t Routes_t;
4453
#endif
4554

@@ -50,25 +59,18 @@ extern "C" {
5059

5160
/** @brief Process pgr_withPointsVia */
5261
void
53-
do_withPointsVia(
54-
Edge_t*, size_t, // edges
55-
Point_on_edge_t *, size_t, // Points
56-
Edge_t*, size_t, // edges of points
57-
int64_t *, size_t, // via vertices
58-
59-
bool, // directed
60-
61-
char, // driving_side
62-
bool, // details
63-
64-
bool, // strict
65-
bool, // U_turn_on_edge,
66-
67-
Routes_t**, size_t*, // results
68-
69-
char**, // log
70-
char**, // notice
71-
char**); // error
62+
pgr_do_withPointsVia(
63+
char*,
64+
char*,
65+
char*,
66+
ArrayType*,
67+
68+
bool,
69+
char,
70+
bool, bool, bool,
71+
72+
Routes_t**, size_t*,
73+
char**, char**, char**);
7274

7375
#ifdef __cplusplus
7476
}

include/drivers/withPoints/withPoints_driver.h

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*PGR-GNU*****************************************************************
2-
File: many_to_many_withPoints_driver.h
2+
File: withPoints_driver.h
33
44
Copyright (c) 2015 pgRouting developers
55
@@ -30,58 +30,45 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
3030
#define INCLUDE_DRIVERS_WITHPOINTS_WITHPOINTS_DRIVER_H_
3131
#pragma once
3232

33-
/* for size-t */
33+
34+
#ifdef __cplusplus
35+
extern "C" {
36+
#endif
37+
38+
#include <postgres.h>
39+
#include <utils/array.h>
40+
41+
#ifdef __cplusplus
42+
}
43+
#endif
44+
45+
#include "cpp_common/undefPostgresDefine.hpp"
46+
3447
#ifdef __cplusplus
3548
# include <cstddef>
3649
# include <cstdint>
37-
using Point_on_edge_t = struct Point_on_edge_t;
38-
using Edge_t = struct Edge_t;
3950
using Path_rt = struct Path_rt;
40-
using II_t_rt = struct II_t_rt;
4151
#else
4252
# include <stddef.h>
4353
# include <stdint.h>
44-
typedef struct Point_on_edge_t Point_on_edge_t;
45-
typedef struct Edge_t Edge_t;
4654
typedef struct Path_rt Path_rt;
47-
typedef struct II_t_rt II_t_rt;
4855
#endif
4956

5057
#ifdef __cplusplus
5158
extern "C" {
5259
#endif
5360

54-
void do_pgr_withPoints(
55-
Edge_t *edges,
56-
size_t total_edges,
57-
58-
Point_on_edge_t *points,
59-
size_t total_points,
60-
61-
Edge_t *edges_of_points,
62-
size_t total_edges_of_points,
63-
64-
II_t_rt *combinations,
65-
size_t total_combinations,
66-
67-
int64_t *start_pidsArr,
68-
size_t size_start_pidsArr,
69-
70-
int64_t *end_pidsArr,
71-
size_t size_end_pidsArr,
72-
61+
void pgr_do_withPoints(
62+
char*,
63+
char*,
64+
char*,
65+
char*,
66+
ArrayType*, ArrayType*,
7367

74-
char driving_side,
75-
bool details,
76-
bool directed,
77-
bool only_cost,
78-
bool normal,
68+
char, bool, bool, bool, bool,
7969

80-
Path_rt **return_tuples,
81-
size_t *return_count,
82-
char** log_msg,
83-
char** notice_msg,
84-
char** err_msg);
70+
Path_rt**, size_t*,
71+
char**, char**, char**);
8572

8673
#ifdef __cplusplus
8774
}

src/withPoints/withPoints.c

Lines changed: 7 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
3131
#include "c_common/postgres_connection.h"
3232

3333
#include "c_types/path_rt.h"
34-
#include "c_types/point_on_edge_t.h"
3534
#include "c_common/debug_macro.h"
3635
#include "c_common/e_report.h"
3736
#include "c_common/time_msg.h"
38-
39-
#include "c_common/trsp_pgget.h"
4037
#include "drivers/withPoints/get_new_queries.h"
4138
#include "drivers/withPoints/withPoints_driver.h"
4239

@@ -69,26 +66,6 @@ process(
6966
char* notice_msg = NULL;
7067
char* err_msg = NULL;
7168

72-
size_t size_start_pidsArr = 0;
73-
int64_t* start_pidsArr = NULL;
74-
75-
size_t size_end_pidsArr = 0;
76-
int64_t* end_pidsArr = NULL;
77-
78-
II_t_rt *combinations = NULL;
79-
size_t total_combinations = 0;
80-
81-
Point_on_edge_t *points = NULL;
82-
size_t total_points = 0;
83-
pgr_get_points(points_sql, &points, &total_points, &err_msg);
84-
throw_error(err_msg, points_sql);
85-
86-
#ifndef NDEBUG
87-
size_t i;
88-
for (i = 0; i< total_points; i++) {
89-
PGR_DBG("%ld ", points[i].pid);
90-
}
91-
#endif
9269
char *edges_of_points_query = NULL;
9370
char *edges_no_points_query = NULL;
9471
get_new_queries(
@@ -97,61 +74,13 @@ process(
9774
&edges_no_points_query);
9875

9976

100-
Edge_t *edges_of_points = NULL;
101-
size_t total_edges_of_points = 0;
102-
103-
Edge_t *edges = NULL;
104-
size_t total_edges = 0;
105-
106-
if (normal) {
107-
pgr_get_edges(edges_of_points_query, &edges_of_points, &total_edges_of_points, true, false, &err_msg);
108-
throw_error(err_msg, edges_of_points_query);
109-
pgr_get_edges(edges_no_points_query, &edges, &total_edges, true, false, &err_msg);
110-
throw_error(err_msg, edges_no_points_query);
111-
112-
if (starts && ends) {
113-
start_pidsArr = pgr_get_bigIntArray(&size_start_pidsArr, starts, false, &err_msg);
114-
throw_error(err_msg, "While getting start vids");
115-
end_pidsArr = pgr_get_bigIntArray(&size_end_pidsArr, ends, false, &err_msg);
116-
throw_error(err_msg, "While getting end vids");
117-
} else if (combinations_sql) {
118-
pgr_get_combinations(combinations_sql, &combinations, &total_combinations, &err_msg);
119-
throw_error(err_msg, combinations_sql);
120-
}
121-
} else {
122-
pgr_get_edges(edges_of_points_query, &edges_of_points, &total_edges_of_points, false, false, &err_msg);
123-
throw_error(err_msg, edges_of_points_query);
124-
pgr_get_edges(edges_no_points_query, &edges, &total_edges, false, false, &err_msg);
125-
throw_error(err_msg, edges_no_points_query);
126-
127-
end_pidsArr = pgr_get_bigIntArray(&size_end_pidsArr, starts, false, &err_msg);
128-
throw_error(err_msg, "While getting start vids");
129-
start_pidsArr = pgr_get_bigIntArray(&size_start_pidsArr, ends, false, &err_msg);
130-
throw_error(err_msg, "While getting end vids");
131-
}
132-
133-
134-
pfree(edges_of_points_query);
135-
pfree(edges_no_points_query);
136-
edges_of_points_query = NULL;
137-
edges_no_points_query = NULL;
138-
139-
if ((total_edges + total_edges_of_points) == 0) {
140-
pgr_SPI_finish();
141-
return;
142-
}
143-
14477
clock_t start_t = clock();
145-
146-
do_pgr_withPoints(
147-
edges, total_edges,
148-
points, total_points,
149-
edges_of_points, total_edges_of_points,
150-
151-
combinations, total_combinations,
152-
153-
start_pidsArr, size_start_pidsArr,
154-
end_pidsArr, size_end_pidsArr,
78+
pgr_do_withPoints(
79+
edges_no_points_query,
80+
points_sql,
81+
edges_of_points_query,
82+
combinations_sql,
83+
starts, ends,
15584

15685
driving_side[0],
15786
details,
@@ -178,16 +107,10 @@ process(
178107

179108
pgr_global_report(log_msg, notice_msg, err_msg);
180109

181-
#if 0
182110
if (log_msg) pfree(log_msg);
183111
if (notice_msg) pfree(notice_msg);
184112
if (err_msg) pfree(err_msg);
185-
if (edges) pfree(edges);
186-
if (points) pfree(points);
187-
if (edges_of_points) pfree(edges_of_points);
188-
if (start_pidsArr) pfree(start_pidsArr);
189-
if (end_pidsArr) pfree(end_pidsArr);
190-
#endif
113+
191114
pgr_SPI_finish();
192115
}
193116

@@ -199,10 +122,8 @@ _pgr_withpoints(PG_FUNCTION_ARGS) {
199122
FuncCallContext *funcctx;
200123
TupleDesc tuple_desc;
201124

202-
/**********************************************************************/
203125
Path_rt *result_tuples = 0;
204126
size_t result_count = 0;
205-
/**********************************************************************/
206127

207128
if (SRF_IS_FIRSTCALL()) {
208129
MemoryContext oldcontext;
@@ -249,8 +170,6 @@ _pgr_withpoints(PG_FUNCTION_ARGS) {
249170
&result_count);
250171
}
251172

252-
/**********************************************************************/
253-
254173
funcctx->max_calls = result_count;
255174

256175
funcctx->user_fctx = result_tuples;
@@ -275,15 +194,6 @@ _pgr_withpoints(PG_FUNCTION_ARGS) {
275194
Datum *values;
276195
bool* nulls;
277196

278-
/**********************************************************************/
279-
// OUT seq BIGINT,
280-
// OUT path_seq,
281-
// OUT node BIGINT,
282-
// OUT edge BIGINT,
283-
// OUT cost FLOAT,
284-
// OUT agg_cost FLOAT)
285-
286-
287197
values = palloc(8 * sizeof(Datum));
288198
nulls = palloc(8 * sizeof(bool));
289199

@@ -301,7 +211,6 @@ _pgr_withpoints(PG_FUNCTION_ARGS) {
301211
values[5] = Int64GetDatum(result_tuples[funcctx->call_cntr].edge);
302212
values[6] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost);
303213
values[7] = Float8GetDatum(result_tuples[funcctx->call_cntr].agg_cost);
304-
/**********************************************************************/
305214

306215
tuple = heap_form_tuple(tuple_desc, values, nulls);
307216
result = HeapTupleGetDatum(tuple);
@@ -310,4 +219,3 @@ _pgr_withpoints(PG_FUNCTION_ARGS) {
310219
SRF_RETURN_DONE(funcctx);
311220
}
312221
}
313-

0 commit comments

Comments
 (0)