@@ -31,73 +31,16 @@ 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/bdAstar/bdAstar_driver.h"
34+ #include "process/astar_process.h"
3935
4036PGDLLEXPORT Datum _pgr_bdastar (PG_FUNCTION_ARGS );
4137PG_FUNCTION_INFO_V1 (_pgr_bdastar );
4238
4339
44- static
45- void
46- process (char * edges_sql ,
47- char * combinations_sql ,
48- ArrayType * starts ,
49- ArrayType * ends ,
50- bool directed ,
51- int heuristic ,
52- double factor ,
53- double epsilon ,
54- bool only_cost ,
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_bdAstar (
66- edges_sql ,
67- combinations_sql ,
68- starts , ends ,
69-
70- directed ,
71- heuristic ,
72- factor ,
73- epsilon ,
74- only_cost ,
75- result_tuples , result_count ,
76- & log_msg ,
77- & notice_msg ,
78- & err_msg );
79-
80- if (only_cost ) {
81- time_msg ("pgr_bdAstarCost" , start_t , clock ());
82- } else {
83- time_msg ("pgr_bdAstar" , start_t , clock ());
84- }
85-
86- if (err_msg && (* result_tuples )) {
87- pfree (* result_tuples );
88- (* result_tuples ) = NULL ;
89- (* result_count ) = 0 ;
90- }
91-
92- pgr_global_report (& log_msg , & notice_msg , & err_msg );
93-
94- pgr_SPI_finish ();
95- }
96-
9740PGDLLEXPORT Datum
9841_pgr_bdastar (PG_FUNCTION_ARGS ) {
9942 FuncCallContext * funcctx ;
100- TupleDesc tuple_desc ;
43+ TupleDesc tuple_desc ;
10144
10245 Path_rt * result_tuples = NULL ;
10346 size_t result_count = 0 ;
@@ -107,50 +50,59 @@ _pgr_bdastar(PG_FUNCTION_ARGS) {
10750 funcctx = SRF_FIRSTCALL_INIT ();
10851 oldcontext = MemoryContextSwitchTo (funcctx -> multi_call_memory_ctx );
10952
110-
11153 if (PG_NARGS () == 8 ) {
11254 /*
11355 * many to many
11456 */
115- process (
57+ pgr_process_astar (
11658 text_to_cstring (PG_GETARG_TEXT_P (0 )),
11759 NULL ,
11860 PG_GETARG_ARRAYTYPE_P (1 ),
11961 PG_GETARG_ARRAYTYPE_P (2 ),
62+
12063 PG_GETARG_BOOL (3 ),
64+ PG_GETARG_BOOL (7 ),
65+ true,
66+
12167 PG_GETARG_INT32 (4 ),
12268 PG_GETARG_FLOAT8 (5 ),
12369 PG_GETARG_FLOAT8 (6 ),
124- PG_GETARG_BOOL (7 ),
70+
71+ BDASTAR ,
12572 & result_tuples ,
12673 & result_count );
12774 } else if (PG_NARGS () == 7 ) {
12875 /*
129- * combinations
76+ * Combinations
13077 */
131- process (
78+ pgr_process_astar (
13279 text_to_cstring (PG_GETARG_TEXT_P (0 )),
13380 text_to_cstring (PG_GETARG_TEXT_P (1 )),
134- NULL ,
135- NULL ,
81+
82+ NULL , NULL ,
83+
13684 PG_GETARG_BOOL (2 ),
85+ PG_GETARG_BOOL (6 ),
86+ true,
87+
13788 PG_GETARG_INT32 (3 ),
13889 PG_GETARG_FLOAT8 (4 ),
13990 PG_GETARG_FLOAT8 (5 ),
140- PG_GETARG_BOOL (6 ),
91+
92+ BDASTAR ,
14193 & result_tuples ,
14294 & result_count );
14395 }
14496
145-
14697 funcctx -> max_calls = result_count ;
14798 funcctx -> user_fctx = result_tuples ;
14899 if (get_call_result_type (fcinfo , NULL , & tuple_desc )
149- != TYPEFUNC_COMPOSITE )
100+ != TYPEFUNC_COMPOSITE ) {
150101 ereport (ERROR ,
151102 (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
152103 errmsg ("function returning record called in context "
153104 "that cannot accept type record" )));
105+ }
154106
155107 funcctx -> tuple_desc = tuple_desc ;
156108 MemoryContextSwitchTo (oldcontext );
@@ -167,7 +119,6 @@ _pgr_bdastar(PG_FUNCTION_ARGS) {
167119 bool * nulls ;
168120 size_t call_cntr = funcctx -> call_cntr ;
169121
170-
171122 size_t numb = 8 ;
172123 values = palloc (numb * sizeof (Datum ));
173124 nulls = palloc (numb * sizeof (bool ));
0 commit comments