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

Go to the source code of this file.

Functions

PGDLLEXPORT Datum _pgr_lengauertarjandominatortree (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (_pgr_lengauertarjandominatortree)
 
static void process (char *edges_sql, int64_t root_vertex, pgr_ltdtree_rt **result_tuples, size_t *result_count)
 

Function Documentation

◆ _pgr_lengauertarjandominatortree()

PGDLLEXPORT Datum _pgr_lengauertarjandominatortree ( PG_FUNCTION_ARGS  )

Definition at line 96 of file lengauerTarjanDominatorTree.c.

96  {
97  FuncCallContext *funcctx;
98  TupleDesc tuple_desc;
99 
100  /**********************************************************************/
101  pgr_ltdtree_rt *result_tuples = NULL;
102  size_t result_count = 0;
103  /**********************************************************************/
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 
112  process(
113  text_to_cstring(PG_GETARG_TEXT_P(0)),
114  PG_GETARG_INT64(1),
115  &result_tuples,
116  &result_count);
117 
118 
119  /**********************************************************************/
120 #if PGSQL_VERSION > 95
121  funcctx->max_calls = result_count;
122 #else
123  funcctx->max_calls = (uint32_t)result_count;
124 #endif
125  funcctx->user_fctx = result_tuples;
126  if (get_call_result_type(fcinfo, NULL, &tuple_desc)
127  != TYPEFUNC_COMPOSITE)
128  ereport(ERROR,
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);
134  }
135 
136  funcctx = SRF_PERCALL_SETUP();
137  tuple_desc = funcctx->tuple_desc;
138  result_tuples = (pgr_ltdtree_rt*) funcctx->user_fctx;
139 
140  if (funcctx->call_cntr < funcctx->max_calls) {
141  HeapTuple tuple;
142  Datum result;
143  Datum *values;
144  bool *nulls;
145  size_t call_cntr = funcctx->call_cntr;
146  size_t numb = 3;
147  values =(Datum *)palloc(numb * sizeof(Datum));
148  nulls = palloc(numb * sizeof(bool));
149  size_t i;
150  for (i = 0; i < numb; ++i) {
151  nulls[i] = false;
152  }
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);
159  } else {
160  SRF_RETURN_DONE(funcctx);
161  }
162 }

References if(), and process().

◆ PG_FUNCTION_INFO_V1()

PG_FUNCTION_INFO_V1 ( _pgr_lengauertarjandominatortree  )

◆ process()

static void process ( char *  edges_sql,
int64_t  root_vertex,
pgr_ltdtree_rt **  result_tuples,
size_t *  result_count 
)
static

Definition at line 49 of file lengauerTarjanDominatorTree.c.

52  {
54 
55  size_t total_edges = 0;
56  pgr_edge_t* edges = NULL;
57 
58  pgr_get_edges(edges_sql, &edges, &total_edges);
59  if (total_edges == 0) {
61  return;
62  }
63 
64  PGR_DBG("Starting timer");
65  clock_t start_t = clock();
66  char* log_msg = NULL;
67  char* notice_msg = NULL;
68  char* err_msg = NULL;
70  edges, total_edges,
71  root_vertex,
72  result_tuples, result_count,
73  &log_msg,
74  &notice_msg,
75  &err_msg);
76 
77  time_msg("processing pgr_LTDTree()", start_t, clock());
78 
79 
80  if (err_msg && (*result_tuples)) {
81  pfree(*result_tuples);
82  (*result_tuples) = NULL;
83  (*result_count) = 0;
84  }
85 
86  pgr_global_report(log_msg, notice_msg, err_msg);
87 
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);
93 }

References do_pgr_LTDTree(), PGR_DBG, pgr_get_edges(), pgr_global_report(), pgr_SPI_connect(), pgr_SPI_finish(), and time_msg().

Referenced by _pgr_lengauertarjandominatortree().

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
do_pgr_LTDTree
void do_pgr_LTDTree(pgr_edge_t *data_edges, size_t total_edges, int64_t root_vertex, pgr_ltdtree_rt **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
Definition: lengauerTarjanDominatorTree_driver.cpp:51
PGR_DBG
#define PGR_DBG(...)
Definition: debug_macro.h:34
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
pgr_ltdtree_rt
Definition: pgr_ltdtree_rt.h:35
process
static void process(char *edges_sql, int64_t root_vertex, pgr_ltdtree_rt **result_tuples, size_t *result_count)
Definition: lengauerTarjanDominatorTree.c:49
pgr_global_report
void pgr_global_report(char *log, char *notice, char *err)
notice & error
Definition: e_report.c:93