PGROUTING  3.2
many_to_dist_driving_distance.c File Reference
#include <stdbool.h>
#include "c_common/postgres_connection.h"
#include "utils/array.h"
#include "c_common/debug_macro.h"
#include "c_common/e_report.h"
#include "c_common/time_msg.h"
#include "c_common/edges_input.h"
#include "c_common/arrays_input.h"
#include "drivers/driving_distance/drivedist_driver.h"
Include dependency graph for many_to_dist_driving_distance.c:

Go to the source code of this file.

Functions

PGDLLEXPORT Datum _pgr_drivingdistance (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (_pgr_drivingdistance)
 
static void process (char *sql, ArrayType *starts, float8 distance, bool directed, bool equicost, General_path_element_t **result_tuples, size_t *result_count)
 

Function Documentation

◆ _pgr_drivingdistance()

PGDLLEXPORT Datum _pgr_drivingdistance ( PG_FUNCTION_ARGS  )

Definition at line 102 of file many_to_dist_driving_distance.c.

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

References General_path_element_t::agg_cost, General_path_element_t::cost, General_path_element_t::edge, if(), General_path_element_t::node, PGR_DBG, process(), and General_path_element_t::start_id.

◆ PG_FUNCTION_INFO_V1()

PG_FUNCTION_INFO_V1 ( _pgr_drivingdistance  )

◆ process()

static void process ( char *  sql,
ArrayType *  starts,
float8  distance,
bool  directed,
bool  equicost,
General_path_element_t **  result_tuples,
size_t *  result_count 
)
static

Definition at line 43 of file many_to_dist_driving_distance.c.

50  {
52 
53  size_t size_start_vidsArr = 0;
54  int64_t* start_vidsArr = pgr_get_bigIntArray(&size_start_vidsArr, starts);
55 
56  pgr_edge_t *edges = NULL;
57  size_t total_tuples = 0;
58  pgr_get_edges(sql, &edges, &total_tuples);
59 
60  if (total_tuples == 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_tuples,
71  start_vidsArr, size_start_vidsArr,
72  distance,
73  directed,
74  equicost,
75  result_tuples, result_count,
76  &log_msg,
77  &notice_msg,
78  &err_msg);
79 
80  time_msg("processing pgr_drivingDistance()",
81  start_t, clock());
82 
83  if (err_msg && (*result_tuples)) {
84  pfree(*result_tuples);
85  (*result_tuples) = NULL;
86  (*result_count) = 0;
87  }
88 
89  pgr_global_report(log_msg, notice_msg, err_msg);
90 
91  if (log_msg) pfree(log_msg);
92  if (notice_msg) pfree(notice_msg);
93  if (err_msg) pfree(err_msg);
94  if (edges) pfree(edges);
95  if (start_vidsArr) pfree(start_vidsArr);
96 
98 }

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

Referenced by _pgr_drivingdistance().

pgr_edge_t
Definition: pgr_edge_t.h:37
process
static void process(char *sql, ArrayType *starts, float8 distance, bool directed, bool equicost, General_path_element_t **result_tuples, size_t *result_count)
Definition: many_to_dist_driving_distance.c:43
do_pgr_driving_many_to_dist
void do_pgr_driving_many_to_dist(pgr_edge_t *data_edges, size_t total_edges, int64_t *start_vertex, size_t s_len, double distance, bool directedFlag, bool equiCostFlag, General_path_element_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
Definition: drivedist_driver.cpp:82
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_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
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
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