52 size_t *result_count) {
56 size_t total_edges = 0;
59 if (total_edges == 0) {
65 clock_t start_t = clock();
67 char* notice_msg = NULL;
80 time_msg(
"pgr_maximumCardinalityMatching()", start_t, clock());
82 if (edges) pfree(edges);
84 if (err_msg && (*result_tuples)) {
85 pfree(*result_tuples);
86 (*result_tuples) = NULL;
92 if (log_msg) pfree(log_msg);
93 if (notice_msg) pfree(notice_msg);
94 if (err_msg) pfree(err_msg);
103 FuncCallContext *funcctx;
104 TupleDesc tuple_desc;
108 size_t result_count = 0;
111 if (SRF_IS_FIRSTCALL()) {
112 MemoryContext oldcontext;
113 funcctx = SRF_FIRSTCALL_INIT();
114 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
120 text_to_cstring(PG_GETARG_TEXT_P(0)),
127 #if PGSQL_VERSION > 95
128 funcctx->max_calls = result_count;
130 funcctx->max_calls = (uint32_t)result_count;
132 funcctx->user_fctx = result_tuples;
133 if (get_call_result_type(fcinfo, NULL, &tuple_desc)
134 != TYPEFUNC_COMPOSITE) {
136 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
137 errmsg(
"function returning record called in context "
138 "that cannot accept type record")));
141 funcctx->tuple_desc = tuple_desc;
142 MemoryContextSwitchTo(oldcontext);
145 funcctx = SRF_PERCALL_SETUP();
146 tuple_desc = funcctx->tuple_desc;
149 if (funcctx->call_cntr < funcctx->max_calls) {
157 values = palloc(4 *
sizeof(Datum));
158 nulls = palloc(4 *
sizeof(
bool));
162 for (i = 0; i < 4; ++i) {
166 values[0] = Int32GetDatum(funcctx->call_cntr + 1);
167 values[1] = Int64GetDatum(result_tuples[funcctx->call_cntr].
edge_id);
168 values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].
source);
169 values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].
target);
173 tuple = heap_form_tuple(tuple_desc, values, nulls);
174 result = HeapTupleGetDatum(tuple);
175 SRF_RETURN_NEXT(funcctx, result);
177 SRF_RETURN_DONE(funcctx);