PGROUTING  2.6
many_to_dist_driving_distance.c File Reference
Include dependency graph for many_to_dist_driving_distance.c:

Go to the source code of this file.

Functions

PGDLLEXPORT Datum driving_many_to_dist (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (driving_many_to_dist)
 
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

PGDLLEXPORT Datum driving_many_to_dist ( PG_FUNCTION_ARGS  )

Definition at line 101 of file many_to_dist_driving_distance.c.

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.

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

Here is the call graph for this function:

PG_FUNCTION_INFO_V1 ( driving_many_to_dist  )
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 42 of file many_to_dist_driving_distance.c.

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 driving_many_to_dist().

49  {
51 
52  size_t size_start_vidsArr = 0;
53  int64_t* start_vidsArr = pgr_get_bigIntArray(&size_start_vidsArr, starts);
54 
55  pgr_edge_t *edges = NULL;
56  size_t total_tuples = 0;
57  pgr_get_edges(sql, &edges, &total_tuples);
58 
59  if (total_tuples == 0) {
60  return;
61  }
62 
63  PGR_DBG("Starting timer");
64  clock_t start_t = clock();
65  char* log_msg = NULL;
66  char* notice_msg = NULL;
67  char* err_msg = NULL;
69  edges, total_tuples,
70  start_vidsArr, size_start_vidsArr,
71  distance,
72  directed,
73  equicost,
74  result_tuples, result_count,
75  &log_msg,
76  &notice_msg,
77  &err_msg);
78 
79  time_msg("processing pgr_drivingDistance()",
80  start_t, clock());
81 
82  if (err_msg && (*result_tuples)) {
83  pfree(*result_tuples);
84  (*result_tuples) = NULL;
85  (*result_count) = 0;
86  }
87 
88  pgr_global_report(log_msg, notice_msg, err_msg);
89 
90  if (log_msg) pfree(log_msg);
91  if (notice_msg) pfree(notice_msg);
92  if (err_msg) pfree(err_msg);
93  if (edges) pfree(edges);
94  if (start_vidsArr) pfree(start_vidsArr);
95 
97 }
#define PGR_DBG(...)
Definition: debug_macro.h:34
void pgr_get_edges(char *edges_sql, pgr_edge_t **edges, size_t *total_edges)
basic edge_sql
Definition: edges_input.c:545
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)
int64_t * pgr_get_bigIntArray(size_t *arrlen, ArrayType *input)
enforces the input array to be NOT empty
Definition: arrays_input.c:124
void time_msg(char *msg, clock_t start_t, clock_t end_t)
Definition: time_msg.c:32
void pgr_global_report(char *log, char *notice, char *err)
notice & error
Definition: e_report.c:93
void pgr_SPI_finish(void)
void pgr_SPI_connect(void)

Here is the call graph for this function:

Here is the caller graph for this function: