PGROUTING  3.2
strongComponents.c File Reference
Include dependency graph for strongComponents.c:

Go to the source code of this file.

Functions

PGDLLEXPORT Datum _pgr_strongcomponents (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (_pgr_strongcomponents)
 
static void process (char *edges_sql, pgr_components_rt **result_tuples, size_t *result_count)
 

Function Documentation

◆ _pgr_strongcomponents()

PGDLLEXPORT Datum _pgr_strongcomponents ( PG_FUNCTION_ARGS  )

Definition at line 98 of file strongComponents.c.

98  {
99  FuncCallContext *funcctx;
100  TupleDesc tuple_desc;
101 
102  pgr_components_rt *result_tuples = NULL;
103  size_t result_count = 0;
104 
105  if (SRF_IS_FIRSTCALL()) {
106  MemoryContext oldcontext;
107  funcctx = SRF_FIRSTCALL_INIT();
108  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
109 
110 
111  process(
112  text_to_cstring(PG_GETARG_TEXT_P(0)),
113  &result_tuples,
114  &result_count);
115 
116 
117 #if PGSQL_VERSION > 94
118  funcctx->max_calls = (uint32_t)result_count;
119 #else
120  funcctx->max_calls = (uint32_t)result_count;
121 #endif
122  funcctx->user_fctx = result_tuples;
123  if (get_call_result_type(fcinfo, NULL, &tuple_desc)
124  != TYPEFUNC_COMPOSITE) {
125  ereport(ERROR,
126  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
127  errmsg("function returning record called in context "
128  "that cannot accept type record")));
129  }
130 
131  funcctx->tuple_desc = tuple_desc;
132  MemoryContextSwitchTo(oldcontext);
133  }
134 
135  funcctx = SRF_PERCALL_SETUP();
136  tuple_desc = funcctx->tuple_desc;
137  result_tuples = (pgr_components_rt*) funcctx->user_fctx;
138 
139  if (funcctx->call_cntr < funcctx->max_calls) {
140  HeapTuple tuple;
141  Datum result;
142  Datum *values;
143  bool* nulls;
144 
145  size_t numb = 3;
146  values = palloc(numb * sizeof(Datum));
147  nulls = palloc(numb * sizeof(bool));
148 
149  size_t i;
150  for (i = 0; i < numb; ++i) {
151  nulls[i] = false;
152  }
153 
154  values[0] = Int64GetDatum(funcctx->call_cntr + 1);
155  values[1] = Int64GetDatum(result_tuples[funcctx->call_cntr].component);
156  values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].identifier);
157 
158  tuple = heap_form_tuple(tuple_desc, values, nulls);
159  result = HeapTupleGetDatum(tuple);
160  SRF_RETURN_NEXT(funcctx, result);
161  } else {
162  SRF_RETURN_DONE(funcctx);
163  }
164 }

References pgr_components_rt::component, pgr_components_rt::identifier, if(), and process().

◆ PG_FUNCTION_INFO_V1()

PG_FUNCTION_INFO_V1 ( _pgr_strongcomponents  )

◆ process()

static void process ( char *  edges_sql,
pgr_components_rt **  result_tuples,
size_t *  result_count 
)
static

Definition at line 50 of file strongComponents.c.

53  {
55 
56  (*result_tuples) = NULL;
57  (*result_count) = 0;
58 
59  pgr_edge_t *edges = NULL;
60  size_t total_edges = 0;
61 
62  pgr_get_edges(edges_sql, &edges, &total_edges);
63 
64  if (total_edges == 0) {
66  return;
67  }
68 
69  clock_t start_t = clock();
70  char *log_msg = NULL;
71  char *notice_msg = NULL;
72  char *err_msg = NULL;
74  edges,
75  total_edges,
76 
77  result_tuples,
78  result_count,
79  &log_msg,
80  &notice_msg,
81  &err_msg);
82 
83  time_msg(" processing pgr_strongComponents", start_t, clock());
84 
85  if (err_msg) {
86  if (*result_tuples) pfree(*result_tuples);
87  }
88  pgr_global_report(log_msg, notice_msg, err_msg);
89 
90  if (edges) pfree(edges);
91  if (log_msg) pfree(log_msg);
92  if (notice_msg) pfree(notice_msg);
93  if (err_msg) pfree(err_msg);
94 
96 }

References do_pgr_strongComponents(), pgr_get_edges(), pgr_global_report(), pgr_SPI_connect(), pgr_SPI_finish(), and time_msg().

Referenced by _pgr_strongcomponents().

pgr_edge_t
Definition: pgr_edge_t.h:37
pgr_SPI_connect
void pgr_SPI_connect(void)
Definition: postgres_connection.c:82
pgr_SPI_finish
void pgr_SPI_finish(void)
Definition: postgres_connection.c:71
pgr_components_rt
Definition: pgr_components_rt.h:39
process
static void process(char *edges_sql, pgr_components_rt **result_tuples, size_t *result_count)
Definition: strongComponents.c:50
pgr_get_edges
void pgr_get_edges(char *edges_sql, pgr_edge_t **edges, size_t *total_edges)
basic edge_sql
Definition: edges_input.c:711
if
if(DOXYGEN_FOUND) configure_file($
Definition: doxygen/CMakeLists.txt:13
time_msg
void time_msg(char *msg, clock_t start_t, clock_t end_t)
Definition: time_msg.c:32
do_pgr_strongComponents
void do_pgr_strongComponents(pgr_edge_t *data_edges, size_t total_edges, pgr_components_rt **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
Definition: strongComponents_driver.cpp:45
pgr_global_report
void pgr_global_report(char *log, char *notice, char *err)
notice & error
Definition: e_report.c:93