55 size_t *result_count) {
59 size_t total_edges = 0;
63 if (total_edges == 0) {
68 clock_t start_t = clock();
70 char *notice_msg = NULL;
77 result_tuples, result_count,
84 time_msg(
" processing pgr_chinesePostmanCost", start_t, clock());
86 time_msg(
" processing pgr_chinesePostman", start_t, clock());
89 if (edges) pfree(edges);
91 if (err_msg && (*result_tuples)) {
92 pfree(*result_tuples);
93 (*result_tuples) = NULL;
99 if (log_msg) pfree(log_msg);
100 if (notice_msg) pfree(notice_msg);
101 if (err_msg) pfree(err_msg);
108 FuncCallContext *funcctx;
109 TupleDesc tuple_desc;
113 size_t result_count = 0;
116 if (SRF_IS_FIRSTCALL()) {
117 MemoryContext oldcontext;
118 funcctx = SRF_FIRSTCALL_INIT();
119 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
125 text_to_cstring(PG_GETARG_TEXT_P(0)),
133 #if PGSQL_VERSION > 95
134 funcctx->max_calls = 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) {
160 size_t call_cntr = funcctx->call_cntr;
168 values =(Datum *)palloc(numb *
sizeof(Datum));
169 nulls = palloc(numb *
sizeof(
bool));
173 for (i = 0; i < numb; ++i) {
176 values[0] = Int32GetDatum(funcctx->call_cntr + 1);
177 values[1] = Int64GetDatum(result_tuples[call_cntr].node);
178 values[2] = Int64GetDatum(result_tuples[call_cntr].
edge);
179 values[3] = Float8GetDatum(result_tuples[call_cntr].cost);
180 values[4] = Float8GetDatum(result_tuples[call_cntr].agg_cost);
183 tuple = heap_form_tuple(tuple_desc, values, nulls);
184 result = HeapTupleGetDatum(tuple);
185 SRF_RETURN_NEXT(funcctx, result);
187 SRF_RETURN_DONE(funcctx);