PGROUTING  3.2
new_trsp.c File Reference
#include <stdbool.h>
#include "c_common/postgres_connection.h"
#include "utils/array.h"
#include "drivers/trsp/trsp_driver.h"
#include "c_common/debug_macro.h"
#include "c_common/e_report.h"
#include "c_common/time_msg.h"
#include "c_types/pgr_edge_t.h"
#include "c_types/restriction_t.h"
#include "c_types/general_path_element_t.h"
#include "c_common/edges_input.h"
#include "c_common/restrictions_input.h"
#include "c_common/arrays_input.h"
Include dependency graph for new_trsp.c:

Go to the source code of this file.

Functions

PGDLLEXPORT Datum _trsp (PG_FUNCTION_ARGS)
 
static void compute_trsp (char *edges_sql, char *restrictions_sql, ArrayType *starts, ArrayType *ends, bool directed, General_path_element_t **result_tuples, size_t *result_count)
 
 PG_FUNCTION_INFO_V1 (_trsp)
 

Function Documentation

◆ _trsp()

PGDLLEXPORT Datum _trsp ( PG_FUNCTION_ARGS  )

Definition at line 118 of file new_trsp.c.

118  {
119  FuncCallContext *funcctx;
120  TupleDesc tuple_desc;
121 
122  size_t result_count = 0;
123  General_path_element_t *result_tuples = NULL;
124 
125  // stuff done only on the first call of the function
126  if (SRF_IS_FIRSTCALL()) {
127  MemoryContext oldcontext;
128  funcctx = SRF_FIRSTCALL_INIT();
129  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
130 
131  PGR_DBG("Calling compute_trsp");
132  compute_trsp(
133  text_to_cstring(PG_GETARG_TEXT_P(0)),
134  text_to_cstring(PG_GETARG_TEXT_P(1)),
135  PG_GETARG_ARRAYTYPE_P(2),
136  PG_GETARG_ARRAYTYPE_P(3),
137  PG_GETARG_BOOL(4),
138  &result_tuples, &result_count);
139 
140  //-----------------------------------------------
141 
142 #if PGSQL_VERSION > 95
143  funcctx->max_calls = result_count;
144 #else
145  funcctx->max_calls = (uint32_t)result_count;
146 #endif
147 
148  funcctx->user_fctx = result_tuples;
149  if (get_call_result_type(fcinfo, NULL, &tuple_desc)
150  != TYPEFUNC_COMPOSITE) {
151  ereport(ERROR,
152  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
153  errmsg("function returning record called in context "
154  "that cannot accept type record")));
155  }
156 
157  funcctx->tuple_desc = tuple_desc;
158  MemoryContextSwitchTo(oldcontext);
159  }
160 
161  funcctx = SRF_PERCALL_SETUP();
162 
163  tuple_desc = funcctx->tuple_desc;
164  result_tuples = (General_path_element_t *) funcctx->user_fctx;
165 
166  if (funcctx->call_cntr < funcctx->max_calls) {
167  // do when there is more left to send
168  HeapTuple tuple;
169  Datum result;
170  Datum *values;
171  bool* nulls;
172  size_t call_cntr = funcctx->call_cntr;
173 
174 
175  size_t numb = 8;
176  values = palloc(numb * sizeof(Datum));
177  nulls = palloc(numb * sizeof(bool));
178 
179  size_t i;
180  for (i = 0; i < numb; ++i) {
181  nulls[i] = false;
182  }
183 
184  values[0] = Int32GetDatum(call_cntr + 1);
185  values[1] = Int32GetDatum(result_tuples[call_cntr].seq);
186  values[2] = Int64GetDatum(result_tuples[call_cntr].start_id);
187  values[3] = Int64GetDatum(result_tuples[call_cntr].end_id);
188  values[4] = Int64GetDatum(result_tuples[call_cntr].node);
189  values[5] = Int64GetDatum(result_tuples[call_cntr].edge);
190  values[6] = Float8GetDatum(result_tuples[call_cntr].cost);
191  values[7] = Float8GetDatum(result_tuples[call_cntr].agg_cost);
192 
193  tuple = heap_form_tuple(tuple_desc, values, nulls);
194 
195  result = HeapTupleGetDatum(tuple);
196 
197  pfree(values);
198  pfree(nulls);
199 
200  SRF_RETURN_NEXT(funcctx, result);
201  } else {
202  SRF_RETURN_DONE(funcctx);
203  }
204 }

References compute_trsp(), if(), and PGR_DBG.

◆ compute_trsp()

static void compute_trsp ( char *  edges_sql,
char *  restrictions_sql,
ArrayType *  starts,
ArrayType *  ends,
bool  directed,
General_path_element_t **  result_tuples,
size_t *  result_count 
)
static

Definition at line 50 of file new_trsp.c.

60  {
62 
63  pgr_edge_t *edges = NULL;
64  size_t total_edges = 0;
65  pgr_get_edges(edges_sql, &edges, &total_edges);
66 
67  Restriction_t * restrictions = NULL;
68  size_t total_restrictions = 0;
69  pgr_get_restrictions(restrictions_sql, &restrictions, &total_restrictions);
70 
71  size_t size_start_vidsArr = 0;
72  int64_t* start_vidsArr = (int64_t*)
73  pgr_get_bigIntArray(&size_start_vidsArr, starts);
74 
75  size_t size_end_vidsArr = 0;
76  int64_t* end_vidsArr = (int64_t*)
77  pgr_get_bigIntArray(&size_end_vidsArr, ends);
78 
79  PGR_DBG("Starting timer");
80  clock_t start_t = clock();
81  char* log_msg = NULL;
82  char* notice_msg = NULL;
83  char* err_msg = NULL;
84 
85  do_trsp(
86  edges,
87  total_edges,
88 
89  restrictions,
90  total_restrictions,
91 
92  start_vidsArr, size_start_vidsArr,
93  end_vidsArr, size_end_vidsArr,
94 
95  directed,
96 
97  result_tuples,
98  result_count,
99  &log_msg,
100  &notice_msg,
101  &err_msg);
102  time_msg("processing _pgr_trsp", start_t, clock());
103 
104  if (err_msg && (*result_tuples)) {
105  pfree(*result_tuples);
106  (*result_tuples) = NULL;
107  (*result_count) = 0;
108  }
109 
110  pgr_global_report(log_msg, notice_msg, err_msg);
111 
112  pgr_SPI_finish();
113 }

References do_trsp(), PGR_DBG, pgr_get_bigIntArray(), pgr_get_edges(), pgr_get_restrictions(), pgr_global_report(), pgr_SPI_connect(), pgr_SPI_finish(), and time_msg().

Referenced by _trsp().

◆ PG_FUNCTION_INFO_V1()

PG_FUNCTION_INFO_V1 ( _trsp  )
pgr_edge_t
Definition: pgr_edge_t.h:37
pgr_SPI_connect
void pgr_SPI_connect(void)
Definition: postgres_connection.c:82
pgr_get_restrictions
void pgr_get_restrictions(char *restrictions_sql, Restriction_t **restrictions, size_t *total_restrictions)
Definition: restrictions_input.c:63
pgr_SPI_finish
void pgr_SPI_finish(void)
Definition: postgres_connection.c:71
edge
Definition: trsp.h:41
pgr_get_bigIntArray
int64_t * pgr_get_bigIntArray(size_t *arrlen, ArrayType *input)
Enforces the input array to be NOT empty.
Definition: arrays_input.c:146
do_trsp
void do_trsp(pgr_edge_t *edges, size_t total_edges, Restriction_t *restrictions, size_t restrictions_size, int64_t *start_vidsArr, size_t size_start_vidsArr, int64_t *end_vidsArr, size_t size_end_vidsArr, bool directed, General_path_element_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
Definition: trsp_driver.cpp:41
PGR_DBG
#define PGR_DBG(...)
Definition: debug_macro.h:34
compute_trsp
static void compute_trsp(char *edges_sql, char *restrictions_sql, ArrayType *starts, ArrayType *ends, bool directed, General_path_element_t **result_tuples, size_t *result_count)
Definition: new_trsp.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
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
Restriction_t
Definition: restriction_t.h:37
pgr_global_report
void pgr_global_report(char *log, char *notice, char *err)
notice & error
Definition: e_report.c:93