36 #include "utils/array.h"
70 size_t *result_count) {
73 (*result_tuples) = NULL;
77 size_t total_edges = 0;
81 clock_t start_t = clock();
83 char *notice_msg = NULL;
94 time_msg(
"processing pgr_sequentialVertexColoring", start_t, clock());
96 if (err_msg && (*result_tuples)) {
97 pfree(*result_tuples);
98 (*result_tuples) = NULL;
104 if (log_msg) pfree(log_msg);
105 if (notice_msg) pfree(notice_msg);
106 if (err_msg) pfree(err_msg);
107 if (edges) pfree(edges);
119 FuncCallContext *funcctx;
120 TupleDesc tuple_desc;
124 size_t result_count = 0;
127 if (SRF_IS_FIRSTCALL()) {
128 MemoryContext oldcontext;
129 funcctx = SRF_FIRSTCALL_INIT();
130 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
139 text_to_cstring(PG_GETARG_TEXT_P(0)),
146 #if PGSQL_VERSION > 95
147 funcctx->max_calls = result_count;
149 funcctx->max_calls = (uint32_t)result_count;
151 funcctx->user_fctx = result_tuples;
152 if (get_call_result_type(fcinfo, NULL, &tuple_desc)
153 != TYPEFUNC_COMPOSITE) {
155 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
156 errmsg(
"function returning record called in context "
157 "that cannot accept type record")));
160 funcctx->tuple_desc = tuple_desc;
161 MemoryContextSwitchTo(oldcontext);
164 funcctx = SRF_PERCALL_SETUP();
165 tuple_desc = funcctx->tuple_desc;
168 if (funcctx->call_cntr < funcctx->max_calls) {
182 values = palloc(num *
sizeof(Datum));
183 nulls = palloc(num *
sizeof(
bool));
187 for (i = 0; i < num; ++i) {
191 values[0] = Int64GetDatum(result_tuples[funcctx->call_cntr].
node);
192 values[1] = Int64GetDatum(result_tuples[funcctx->call_cntr].
color);
196 tuple = heap_form_tuple(tuple_desc, values, nulls);
197 result = HeapTupleGetDatum(tuple);
198 SRF_RETURN_NEXT(funcctx, result);
200 SRF_RETURN_DONE(funcctx);