@@ -31,75 +31,15 @@ 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_common/debug_macro.h"
35- #include "c_common/e_report.h"
36- #include "c_common/time_msg.h"
37- #include "c_common/check_parameters.h"
38- #include "drivers/astar/astar_driver.h"
34+ #include "process/astar_process.h"
3935
4036PGDLLEXPORT Datum _pgr_astar (PG_FUNCTION_ARGS );
4137PG_FUNCTION_INFO_V1 (_pgr_astar );
4238
43- static
44- void
45- process (char * edges_sql ,
46- char * combinations_sql ,
47- ArrayType * starts ,
48- ArrayType * ends ,
49- bool directed ,
50- int heuristic ,
51- double factor ,
52- double epsilon ,
53- bool only_cost ,
54- bool normal ,
55- Path_rt * * result_tuples ,
56- size_t * result_count ) {
57- check_parameters (heuristic , factor , epsilon );
58-
59- pgr_SPI_connect ();
60- char * log_msg = NULL ;
61- char * notice_msg = NULL ;
62- char * err_msg = NULL ;
63-
64- clock_t start_t = clock ();
65- pgr_do_astar (
66- edges_sql ,
67- combinations_sql ,
68- starts ,
69- ends ,
70-
71- directed ,
72- heuristic ,
73- factor ,
74- epsilon ,
75- only_cost ,
76- normal ,
77- result_tuples , result_count ,
78- & log_msg ,
79- & notice_msg ,
80- & err_msg );
81-
82- if (only_cost ) {
83- time_msg ("processing pgr_astarCost" , start_t , clock ());
84- } else {
85- time_msg ("processing pgr_astar" , start_t , clock ());
86- }
87-
88- if (err_msg && (* result_tuples )) {
89- pfree (* result_tuples );
90- (* result_tuples ) = NULL ;
91- (* result_count ) = 0 ;
92- }
9339
94- pgr_global_report (& log_msg , & notice_msg , & err_msg );
95-
96- pgr_SPI_finish ();
97- }
98-
99- PGDLLEXPORT Datum
100- _pgr_astar (PG_FUNCTION_ARGS ) {
40+ PGDLLEXPORT Datum _pgr_astar (PG_FUNCTION_ARGS ) {
10141 FuncCallContext * funcctx ;
102- TupleDesc tuple_desc ;
42+ TupleDesc tuple_desc ;
10343
10444 Path_rt * result_tuples = NULL ;
10545 size_t result_count = 0 ;
@@ -108,53 +48,59 @@ _pgr_astar(PG_FUNCTION_ARGS) {
10848 MemoryContext oldcontext ;
10949 funcctx = SRF_FIRSTCALL_INIT ();
11050 oldcontext = MemoryContextSwitchTo (funcctx -> multi_call_memory_ctx );
111-
112-
11351 if (PG_NARGS () == 9 ) {
11452 /*
11553 * many to many
11654 */
117- process (
55+ pgr_process_astar (
11856 text_to_cstring (PG_GETARG_TEXT_P (0 )),
11957 NULL ,
12058 PG_GETARG_ARRAYTYPE_P (1 ),
12159 PG_GETARG_ARRAYTYPE_P (2 ),
60+
12261 PG_GETARG_BOOL (3 ),
62+ PG_GETARG_BOOL (7 ),
63+ PG_GETARG_BOOL (8 ),
64+
12365 PG_GETARG_INT32 (4 ),
12466 PG_GETARG_FLOAT8 (5 ),
12567 PG_GETARG_FLOAT8 (6 ),
126- PG_GETARG_BOOL ( 7 ),
127- PG_GETARG_BOOL ( 8 ) ,
68+
69+ ASTAR ,
12870 & result_tuples ,
12971 & result_count );
13072 } else if (PG_NARGS () == 7 ) {
13173 /*
13274 * Combinations
13375 */
134- process (
76+ pgr_process_astar (
13577 text_to_cstring (PG_GETARG_TEXT_P (0 )),
13678 text_to_cstring (PG_GETARG_TEXT_P (1 )),
137- NULL ,
138- NULL ,
79+
80+ NULL , NULL ,
81+
13982 PG_GETARG_BOOL (2 ),
83+ PG_GETARG_BOOL (6 ),
84+ true,
85+
14086 PG_GETARG_INT32 (3 ),
14187 PG_GETARG_FLOAT8 (4 ),
14288 PG_GETARG_FLOAT8 (5 ),
143- PG_GETARG_BOOL ( 6 ),
144- true ,
89+
90+ ASTAR ,
14591 & result_tuples ,
14692 & result_count );
14793 }
14894
149-
15095 funcctx -> max_calls = result_count ;
15196 funcctx -> user_fctx = result_tuples ;
15297 if (get_call_result_type (fcinfo , NULL , & tuple_desc )
153- != TYPEFUNC_COMPOSITE )
98+ != TYPEFUNC_COMPOSITE ) {
15499 ereport (ERROR ,
155100 (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
156101 errmsg ("function returning record called in context "
157102 "that cannot accept type record" )));
103+ }
158104
159105 funcctx -> tuple_desc = tuple_desc ;
160106 MemoryContextSwitchTo (oldcontext );
@@ -171,7 +117,6 @@ _pgr_astar(PG_FUNCTION_ARGS) {
171117 bool * nulls ;
172118 size_t call_cntr = funcctx -> call_cntr ;
173119
174-
175120 size_t numb = 8 ;
176121 values = palloc (numb * sizeof (Datum ));
177122 nulls = palloc (numb * sizeof (bool ));
0 commit comments