PGROUTING  2.6-dev
bdDijkstra.c File Reference
Include dependency graph for bdDijkstra.c:

Go to the source code of this file.

Functions

PGDLLEXPORT Datum bdDijkstra (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (bdDijkstra)
 
static void process (char *edges_sql, ArrayType *starts, ArrayType *ends, bool directed, bool only_cost, General_path_element_t **result_tuples, size_t *result_count)
 

Function Documentation

PGDLLEXPORT Datum bdDijkstra ( PG_FUNCTION_ARGS  )

Definition at line 124 of file bdDijkstra.c.

References if(), and process().

124  {
125  FuncCallContext *funcctx;
126  TupleDesc tuple_desc;
127 
128  /**************************************************************************/
129  /* MODIFY AS NEEDED */
130  /* */
131  General_path_element_t *result_tuples = NULL;
132  size_t result_count = 0;
133  /* */
134  /**************************************************************************/
135 
136  if (SRF_IS_FIRSTCALL()) {
137  MemoryContext oldcontext;
138  funcctx = SRF_FIRSTCALL_INIT();
139  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
140 
141 
142  /**********************************************************************/
143  /* MODIFY AS NEEDED */
144  /*
145  edges_sql TEXT,
146  start_vid BIGINT,
147  end_vid BIGINT,
148  directed BOOLEAN DEFAULT true,
149  only_cost BOOLEAN DEFAULT false,
150  **********************************************************************/
151 
152 
153  process(
154  text_to_cstring(PG_GETARG_TEXT_P(0)),
155  PG_GETARG_ARRAYTYPE_P(1),
156  PG_GETARG_ARRAYTYPE_P(2),
157  PG_GETARG_BOOL(3),
158  PG_GETARG_BOOL(4),
159  &result_tuples,
160  &result_count);
161 
162  /* */
163  /**********************************************************************/
164 
165 #if PGSQL_VERSION > 95
166  funcctx->max_calls = result_count;
167 #else
168  funcctx->max_calls = (uint32_t)result_count;
169 #endif
170  funcctx->user_fctx = result_tuples;
171  if (get_call_result_type(fcinfo, NULL, &tuple_desc)
172  != TYPEFUNC_COMPOSITE) {
173  ereport(ERROR,
174  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
175  errmsg("function returning record called in context "
176  "that cannot accept type record")));
177  }
178 
179  funcctx->tuple_desc = tuple_desc;
180  MemoryContextSwitchTo(oldcontext);
181  }
182 
183  funcctx = SRF_PERCALL_SETUP();
184  tuple_desc = funcctx->tuple_desc;
185 
186  result_tuples = (General_path_element_t*) funcctx->user_fctx;
187 
188  if (funcctx->call_cntr < funcctx->max_calls) {
189  HeapTuple tuple;
190  Datum result;
191  Datum *values;
192  bool* nulls;
193  size_t call_cntr = funcctx->call_cntr;
194 
195 
196  /**********************************************************************/
197  /* MODIFY AS NEEDED */
198  /*
199  OUT seq INTEGER,
200  OUT path_seq INTEGER,
201  OUT node BIGINT,
202  OUT edge BIGINT,
203  OUT cost FLOAT,
204  OUT agg_cost FLOAT
205  ***********************************************************************/
206 
207  size_t numb = 8;
208  values = palloc(numb * sizeof(Datum));
209  nulls = palloc(numb * sizeof(bool));
210 
211 
212  size_t i;
213  for (i = 0; i < numb; ++i) {
214  nulls[i] = false;
215  }
216 
217  values[0] = Int32GetDatum(call_cntr + 1);
218  values[1] = Int32GetDatum(result_tuples[call_cntr].seq);
219  values[2] = Int64GetDatum(result_tuples[call_cntr].start_id);
220  values[3] = Int64GetDatum(result_tuples[call_cntr].end_id);
221  values[4] = Int64GetDatum(result_tuples[call_cntr].node);
222  values[5] = Int64GetDatum(result_tuples[call_cntr].edge);
223  values[6] = Float8GetDatum(result_tuples[call_cntr].cost);
224  values[7] = Float8GetDatum(result_tuples[call_cntr].agg_cost);
225 
226  /**********************************************************************/
227 
228  tuple = heap_form_tuple(tuple_desc, values, nulls);
229  result = HeapTupleGetDatum(tuple);
230  SRF_RETURN_NEXT(funcctx, result);
231  } else {
232  SRF_RETURN_DONE(funcctx);
233  }
234 }
Definition: trsp.h:31
static void process(char *edges_sql, ArrayType *starts, ArrayType *ends, bool directed, bool only_cost, General_path_element_t **result_tuples, size_t *result_count)
Definition: bdDijkstra.c:52
if(DOXYGEN_FOUND) configure_file($
Definition: CMakeLists.txt:13

Here is the call graph for this function:

PG_FUNCTION_INFO_V1 ( bdDijkstra  )
static void process ( char *  edges_sql,
ArrayType *  starts,
ArrayType *  ends,
bool  directed,
bool  only_cost,
General_path_element_t **  result_tuples,
size_t *  result_count 
)
static

Definition at line 52 of file bdDijkstra.c.

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

Referenced by bdDijkstra().

59  {
61 
62  int64_t* start_vidsArr = NULL;
63  size_t size_start_vidsArr = 0;
64  start_vidsArr = (int64_t*)
65  pgr_get_bigIntArray(&size_start_vidsArr, starts);
66 
67  int64_t* end_vidsArr = NULL;
68  size_t size_end_vidsArr = 0;
69  end_vidsArr = (int64_t*)
70  pgr_get_bigIntArray(&size_end_vidsArr, ends);
71 
72  pgr_edge_t *edges = NULL;
73  size_t total_edges = 0;
74 
75  pgr_get_edges(edges_sql, &edges, &total_edges);
76  PGR_DBG("Total %ld edges in query:", total_edges);
77 
78  if (total_edges == 0) {
79  PGR_DBG("No edges found");
81  return;
82  }
83 
84  PGR_DBG("Starting processing");
85  clock_t start_t = clock();
86  char *log_msg = NULL;
87  char *notice_msg = NULL;
88  char *err_msg = NULL;
90  edges, total_edges,
91  start_vidsArr, size_start_vidsArr,
92  end_vidsArr, size_end_vidsArr,
93 
94  directed,
95  only_cost,
96 
97  result_tuples,
98  result_count,
99  &log_msg,
100  &notice_msg,
101  &err_msg);
102 
103  time_msg(" processing pgr_bdDijkstra", start_t, clock());
104 
105 
106  if (err_msg && (*result_tuples)) {
107  pfree(*result_tuples);
108  (*result_tuples) = NULL;
109  (*result_count) = 0;
110  }
111 
112  pgr_global_report(log_msg, notice_msg, err_msg);
113 
114  if (log_msg) pfree(log_msg);
115  if (notice_msg) pfree(notice_msg);
116  if (err_msg) pfree(err_msg);
117  if (edges) pfree(edges);
118 
119  pgr_SPI_finish();
120 }
#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
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)
void do_pgr_bdDijkstra(pgr_edge_t *data_edges, size_t total_edges, int64_t *start_vidsArr, size_t size_start_vidsArr, int64_t *end_vidsArr, size_t size_end_vidsArr, bool directed, bool only_cost, General_path_element_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)

Here is the call graph for this function:

Here is the caller graph for this function: