51 size_t *result_count) {
57 (*result_tuples) = NULL;
62 size_t total_edges = 0;
65 PGR_DBG(
"Total %ld edges in query:", total_edges);
67 if (total_edges == 0) {
74 clock_t start_t = clock();
76 char *notice_msg = NULL;
87 time_msg(
" processing pgr_stoerWagner", start_t, clock());
88 PGR_DBG(
"Returning %ld tuples", *result_count);
91 if (*result_tuples) pfree(*result_tuples);
95 if (edges) pfree(edges);
96 if (log_msg) pfree(log_msg);
97 if (notice_msg) pfree(notice_msg);
98 if (err_msg) pfree(err_msg);
106 FuncCallContext *funcctx;
107 TupleDesc tuple_desc;
113 size_t result_count = 0;
117 if (SRF_IS_FIRSTCALL()) {
118 MemoryContext oldcontext;
119 funcctx = SRF_FIRSTCALL_INIT();
120 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
125 text_to_cstring(PG_GETARG_TEXT_P(0)),
133 #if PGSQL_VERSION > 94
134 funcctx->max_calls = (uint32_t)result_count;
136 funcctx->max_calls = (uint32_t)result_count;
138 funcctx->user_fctx = result_tuples;
139 if (get_call_result_type(fcinfo, NULL, &tuple_desc)
140 != TYPEFUNC_COMPOSITE) {
142 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
143 errmsg(
"function returning record called in context "
144 "that cannot accept type record")));
147 funcctx->tuple_desc = tuple_desc;
148 MemoryContextSwitchTo(oldcontext);
151 funcctx = SRF_PERCALL_SETUP();
152 tuple_desc = funcctx->tuple_desc;
155 if (funcctx->call_cntr < funcctx->max_calls) {
161 values = palloc(4 *
sizeof(Datum));
162 nulls = palloc(4 *
sizeof(
bool));
166 for (i = 0; i < 4; ++i) {
171 values[0] = Int32GetDatum(funcctx->call_cntr + 1);
172 values[1] = Int64GetDatum(result_tuples[funcctx->call_cntr].
edge);
173 values[2] = Float8GetDatum(result_tuples[funcctx->call_cntr].
cost);
174 values[3] = Float8GetDatum(result_tuples[funcctx->call_cntr].
mincut);
177 tuple = heap_form_tuple(tuple_desc, values, nulls);
178 result = HeapTupleGetDatum(tuple);
179 SRF_RETURN_NEXT(funcctx, result);
188 SRF_RETURN_DONE(funcctx);