@@ -29,75 +29,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2929#include <stdbool.h>
3030
3131#include "c_common/postgres_connection.h"
32- #include "utils/array.h"
3332
34- #include "c_common/debug_macro.h"
35- #include "c_common/e_report.h"
36- #include "c_common/time_msg.h"
3733#include "c_types/mst_rt.h"
3834
39- #include "drivers/spanningTree/mst_common.h"
40- #include "drivers/spanningTree/kruskal_driver.h"
35+ #include "process/spanningTree_process.h"
4136
4237PGDLLEXPORT Datum _pgr_kruskalv4 (PG_FUNCTION_ARGS );
4338PG_FUNCTION_INFO_V1 (_pgr_kruskalv4 );
4439
4540
46- static
47- void
48- process (
49- char * edges_sql ,
50- ArrayType * roots ,
51- char * fn_suffix ,
52- int64_t max_depth ,
53- double distance ,
54-
55- MST_rt * * result_tuples ,
56- size_t * result_count ) {
57- pgr_SPI_connect ();
58- char * log_msg = NULL ;
59- char * notice_msg = NULL ;
60- char * err_msg = NULL ;
61- (* result_tuples ) = NULL ;
62- (* result_count ) = 0 ;
63-
64-
65- char * fn_name = get_name (0 , fn_suffix , & err_msg );
66- if (err_msg ) {
67- pgr_global_report (& log_msg , & notice_msg , & err_msg );
68- return ;
69- }
70-
71- /* checks previously done on sql now done here */
72- if (strcmp (fn_suffix , "DD" ) == 0 && distance < 0 ) {
73- pgr_throw_error ("Negative value found on 'distance'" , "Must be positive" );
74- } else if ((strcmp (fn_suffix , "BFS" ) == 0 || strcmp (fn_suffix , "DFS" ) == 0 ) && max_depth < 0 ) {
75- pgr_throw_error ("Negative value found on 'max_depth'" , "Must be positive" );
76- }
77-
78- clock_t start_t = clock ();
79- pgr_do_kruskal (
80- edges_sql ,
81- roots ,
82- fn_suffix ,
83- max_depth ,
84- distance ,
85-
86- result_tuples ,
87- result_count ,
88- & log_msg ,
89- & notice_msg ,
90- & err_msg );
91- time_msg (fn_name , start_t , clock ());
92-
93- if (err_msg ) {
94- if (* result_tuples ) pfree (* result_tuples );
95- }
96- pgr_global_report (& log_msg , & notice_msg , & err_msg );
97-
98- pgr_SPI_finish ();
99- }
100-
10141PGDLLEXPORT Datum _pgr_kruskalv4 (PG_FUNCTION_ARGS ) {
10242 FuncCallContext * funcctx ;
10343 TupleDesc tuple_desc ;
@@ -110,12 +50,17 @@ PGDLLEXPORT Datum _pgr_kruskalv4(PG_FUNCTION_ARGS) {
11050 funcctx = SRF_FIRSTCALL_INIT ();
11151 oldcontext = MemoryContextSwitchTo (funcctx -> multi_call_memory_ctx );
11252
113- process (
53+ pgr_process_spanningTree (
11454 text_to_cstring (PG_GETARG_TEXT_P (0 )),
11555 PG_GETARG_ARRAYTYPE_P (1 ),
116- text_to_cstring (PG_GETARG_TEXT_P (2 )),
56+
57+ false,
11758 PG_GETARG_INT64 (3 ),
11859 PG_GETARG_FLOAT8 (4 ),
60+ false,
61+
62+ text_to_cstring (PG_GETARG_TEXT_P (2 )),
63+ KRUSKAL ,
11964 & result_tuples ,
12065 & result_count );
12166
@@ -143,7 +88,7 @@ PGDLLEXPORT Datum _pgr_kruskalv4(PG_FUNCTION_ARGS) {
14388 Datum * values ;
14489 bool * nulls ;
14590
146- size_t num = 8 ;
91+ size_t num = 8 ;
14792 values = palloc (num * sizeof (Datum ));
14893 nulls = palloc (num * sizeof (bool ));
14994
@@ -201,13 +146,17 @@ PGDLLEXPORT Datum _pgr_kruskal(PG_FUNCTION_ARGS) {
201146 errhint ("Consider upgrade pgRouting" )));
202147#endif
203148
204- /* Edge sql, tree roots, fn_suffix, max_depth, distance */
205- process (
149+ pgr_process_spanningTree (
206150 text_to_cstring (PG_GETARG_TEXT_P (0 )),
207151 PG_GETARG_ARRAYTYPE_P (1 ),
208- text_to_cstring (PG_GETARG_TEXT_P (2 )),
152+
153+ false,
209154 PG_GETARG_INT64 (3 ),
210155 PG_GETARG_FLOAT8 (4 ),
156+ false,
157+
158+ text_to_cstring (PG_GETARG_TEXT_P (2 )),
159+ KRUSKAL ,
211160 & result_tuples ,
212161 & result_count );
213162
0 commit comments