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

Go to the source code of this file.

Functions

PGDLLEXPORT Datum _pgr_chinesepostman (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (_pgr_chinesepostman)
 
static void process (char *edges_sql, bool only_cost, General_path_element_t **result_tuples, size_t *result_count)
 

Function Documentation

◆ _pgr_chinesepostman()

PGDLLEXPORT Datum _pgr_chinesepostman ( PG_FUNCTION_ARGS  )

Definition at line 107 of file chinesePostman.c.

107  {
108  FuncCallContext *funcctx;
109  TupleDesc tuple_desc;
110 
111  /**************************************************************************/
112  General_path_element_t *result_tuples = NULL;
113  size_t result_count = 0;
114  /**************************************************************************/
115 
116  if (SRF_IS_FIRSTCALL()) {
117  MemoryContext oldcontext;
118  funcctx = SRF_FIRSTCALL_INIT();
119  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
120 
121 
122  /**********************************************************************/
123 
124  process(
125  text_to_cstring(PG_GETARG_TEXT_P(0)),
126  PG_GETARG_BOOL(1),
127  &result_tuples,
128  &result_count);
129 
130  /**********************************************************************/
131 
132 
133 #if PGSQL_VERSION > 95
134  funcctx->max_calls = result_count;
135 #else
136  funcctx->max_calls = (uint32_t)result_count;
137 #endif
138  funcctx->user_fctx = result_tuples;
139  if (get_call_result_type(fcinfo, NULL, &tuple_desc)
140  != TYPEFUNC_COMPOSITE) {
141  ereport(ERROR,
142  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
143  errmsg("function returning record called in context "
144  "that cannot accept type record")));
145  }
146 
147  funcctx->tuple_desc = tuple_desc;
148  MemoryContextSwitchTo(oldcontext);
149  }
150 
151  funcctx = SRF_PERCALL_SETUP();
152  tuple_desc = funcctx->tuple_desc;
153  result_tuples = (General_path_element_t*) funcctx->user_fctx;
154 
155  if (funcctx->call_cntr < funcctx->max_calls) {
156  HeapTuple tuple;
157  Datum result;
158  Datum *values;
159  bool* nulls;
160  size_t call_cntr = funcctx->call_cntr;
161 
162  /**********************************************************************/
163  /* MODIFY AS NEEDED */
164  /*
165  ***********************************************************************/
166 
167  size_t numb = 5;
168  values =(Datum *)palloc(numb * sizeof(Datum));
169  nulls = palloc(numb * sizeof(bool));
170 
171 
172  size_t i;
173  for (i = 0; i < numb; ++i) {
174  nulls[i] = false;
175  }
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);
181  /**********************************************************************/
182 
183  tuple = heap_form_tuple(tuple_desc, values, nulls);
184  result = HeapTupleGetDatum(tuple);
185  SRF_RETURN_NEXT(funcctx, result);
186  } else {
187  SRF_RETURN_DONE(funcctx);
188  }
189 }

References if(), and process().

◆ PG_FUNCTION_INFO_V1()

PG_FUNCTION_INFO_V1 ( _pgr_chinesepostman  )

◆ process()

static void process ( char *  edges_sql,
bool  only_cost,
General_path_element_t **  result_tuples,
size_t *  result_count 
)
static

Definition at line 51 of file chinesePostman.c.

55  {
57 
58  pgr_edge_t *edges = NULL;
59  size_t total_edges = 0;
60 
61  pgr_get_edges(edges_sql, &edges, &total_edges);
62 
63  if (total_edges == 0) {
65  return;
66  }
67 
68  clock_t start_t = clock();
69  char *log_msg = NULL;
70  char *notice_msg = NULL;
71  char *err_msg = NULL;
72 
74  edges, total_edges,
75  only_cost,
76 
77  result_tuples, result_count,
78 
79  &log_msg,
80  &notice_msg,
81  &err_msg);
82 
83  if (only_cost) {
84  time_msg(" processing pgr_chinesePostmanCost", start_t, clock());
85  } else {
86  time_msg(" processing pgr_chinesePostman", start_t, clock());
87  }
88 
89  if (edges) pfree(edges);
90 
91  if (err_msg && (*result_tuples)) {
92  pfree(*result_tuples);
93  (*result_tuples) = NULL;
94  (*result_count) = 0;
95  }
96 
97  pgr_global_report(log_msg, notice_msg, err_msg);
98 
99  if (log_msg) pfree(log_msg);
100  if (notice_msg) pfree(notice_msg);
101  if (err_msg) pfree(err_msg);
102 
103  pgr_SPI_finish();
104 }

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

Referenced by _pgr_chinesepostman().

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
edge
Definition: trsp.h:41
process
static void process(char *edges_sql, bool only_cost, General_path_element_t **result_tuples, size_t *result_count)
Definition: chinesePostman.c:51
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
General_path_element_t
Definition: general_path_element_t.h:37
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_global_report
void pgr_global_report(char *log, char *notice, char *err)
notice & error
Definition: e_report.c:93
do_pgr_directedChPP
void do_pgr_directedChPP(pgr_edge_t *data_edges, size_t total_edges, bool only_cost, General_path_element_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
Definition: chinesePostman_driver.cpp:44