PGROUTING  2.5
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 117 of file bdDijkstra.c.

References if(), and process().

117  {
118  FuncCallContext *funcctx;
119  TupleDesc tuple_desc;
120 
121  /**************************************************************************/
122  /* MODIFY AS NEEDED */
123  /* */
124  General_path_element_t *result_tuples = NULL;
125  size_t result_count = 0;
126  /* */
127  /**************************************************************************/
128 
129  if (SRF_IS_FIRSTCALL()) {
130  MemoryContext oldcontext;
131  funcctx = SRF_FIRSTCALL_INIT();
132  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
133 
134 
135  /**********************************************************************/
136  /* MODIFY AS NEEDED */
137  /*
138  edges_sql TEXT,
139  start_vid BIGINT,
140  end_vid BIGINT,
141  directed BOOLEAN DEFAULT true,
142  only_cost BOOLEAN DEFAULT false,
143  **********************************************************************/
144 
145 
146  process(
147  text_to_cstring(PG_GETARG_TEXT_P(0)),
148  PG_GETARG_ARRAYTYPE_P(1),
149  PG_GETARG_ARRAYTYPE_P(2),
150  PG_GETARG_BOOL(3),
151  PG_GETARG_BOOL(4),
152  &result_tuples,
153  &result_count);
154 
155  /* */
156  /**********************************************************************/
157 
158 #if PGSQL_VERSION > 95
159  funcctx->max_calls = result_count;
160 #else
161  funcctx->max_calls = (uint32_t)result_count;
162 #endif
163  funcctx->user_fctx = result_tuples;
164  if (get_call_result_type(fcinfo, NULL, &tuple_desc)
165  != TYPEFUNC_COMPOSITE) {
166  ereport(ERROR,
167  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
168  errmsg("function returning record called in context "
169  "that cannot accept type record")));
170  }
171 
172  funcctx->tuple_desc = tuple_desc;
173  MemoryContextSwitchTo(oldcontext);
174  }
175 
176  funcctx = SRF_PERCALL_SETUP();
177  tuple_desc = funcctx->tuple_desc;
178 
179  result_tuples = (General_path_element_t*) funcctx->user_fctx;
180 
181  if (funcctx->call_cntr < funcctx->max_calls) {
182  HeapTuple tuple;
183  Datum result;
184  Datum *values;
185  bool* nulls;
186  size_t call_cntr = funcctx->call_cntr;
187 
188 
189  /**********************************************************************/
190  /* MODIFY AS NEEDED */
191  /*
192  OUT seq INTEGER,
193  OUT path_seq INTEGER,
194  OUT node BIGINT,
195  OUT edge BIGINT,
196  OUT cost FLOAT,
197  OUT agg_cost FLOAT
198  ***********************************************************************/
199 
200  size_t numb = 8;
201  values = palloc(numb * sizeof(Datum));
202  nulls = palloc(numb * sizeof(bool));
203 
204 
205  size_t i;
206  for (i = 0; i < numb; ++i) {
207  nulls[i] = false;
208  }
209 
210  values[0] = Int32GetDatum(call_cntr + 1);
211  values[1] = Int32GetDatum(result_tuples[call_cntr].seq);
212  values[2] = Int64GetDatum(result_tuples[call_cntr].start_id);
213  values[3] = Int64GetDatum(result_tuples[call_cntr].end_id);
214  values[4] = Int64GetDatum(result_tuples[call_cntr].node);
215  values[5] = Int64GetDatum(result_tuples[call_cntr].edge);
216  values[6] = Float8GetDatum(result_tuples[call_cntr].cost);
217  values[7] = Float8GetDatum(result_tuples[call_cntr].agg_cost);
218 
219  /**********************************************************************/
220 
221  tuple = heap_form_tuple(tuple_desc, values, nulls);
222  result = HeapTupleGetDatum(tuple);
223  SRF_RETURN_NEXT(funcctx, result);
224  } else {
225  SRF_RETURN_DONE(funcctx);
226  }
227 }
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(), edges, 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  PGR_DBG("Returning %ld tuples", *result_count);
105 
106  if (err_msg) {
107  if (*result_tuples) free(*result_tuples);
108  }
109  pgr_global_report(log_msg, notice_msg, err_msg);
110 
111  pfree(edges);
112  pgr_SPI_finish();
113 }
static edge_t edges[22573]
#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:540
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: