52 size_t *result_count) {
55 size_t total_edges = 0;
59 if (total_edges == 0) {
65 clock_t start_t = clock();
67 char* notice_msg = NULL;
72 result_tuples, result_count,
77 time_msg(
"processing pgr_LTDTree()", start_t, clock());
80 if (err_msg && (*result_tuples)) {
81 pfree(*result_tuples);
82 (*result_tuples) = NULL;
88 if (log_msg) pfree(log_msg);
89 if (notice_msg) pfree(notice_msg);
90 if (err_msg) pfree(err_msg);
91 if (edges) pfree(edges);
97 FuncCallContext *funcctx;
102 size_t result_count = 0;
105 if (SRF_IS_FIRSTCALL()) {
106 MemoryContext oldcontext;
107 funcctx = SRF_FIRSTCALL_INIT();
108 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
113 text_to_cstring(PG_GETARG_TEXT_P(0)),
120 #if PGSQL_VERSION > 95
121 funcctx->max_calls = result_count;
123 funcctx->max_calls = (uint32_t)result_count;
125 funcctx->user_fctx = result_tuples;
126 if (get_call_result_type(fcinfo, NULL, &tuple_desc)
127 != TYPEFUNC_COMPOSITE)
129 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
130 errmsg(
"function returning record called in context "
131 "that cannot accept type record")));
132 funcctx->tuple_desc = tuple_desc;
133 MemoryContextSwitchTo(oldcontext);
136 funcctx = SRF_PERCALL_SETUP();
137 tuple_desc = funcctx->tuple_desc;
140 if (funcctx->call_cntr < funcctx->max_calls) {
145 size_t call_cntr = funcctx->call_cntr;
147 values =(Datum *)palloc(numb *
sizeof(Datum));
148 nulls = palloc(numb *
sizeof(
bool));
150 for (i = 0; i < numb; ++i) {
153 values[0] = Int32GetDatum(call_cntr + 1);
154 values[1] = Int64GetDatum(result_tuples[call_cntr].vid);
155 values[2] = Int64GetDatum(result_tuples[call_cntr].idom);
156 tuple = heap_form_tuple(tuple_desc, values, nulls);
157 result = HeapTupleGetDatum(tuple);
158 SRF_RETURN_NEXT(funcctx, result);
160 SRF_RETURN_DONE(funcctx);