PGROUTING  2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
floydWarshall.c File Reference
Include dependency graph for floydWarshall.c:

Go to the source code of this file.

Functions

PGDLLEXPORT Datum floydWarshall (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (floydWarshall)
 
static void process (char *edges_sql, bool directed, Matrix_cell_t **result_tuples, size_t *result_count)
 

Function Documentation

PGDLLEXPORT Datum floydWarshall ( PG_FUNCTION_ARGS  )

Definition at line 97 of file floydWarshall.c.

References matrix_cell::cost, matrix_cell::from_vid, PGR_DBG, process(), and matrix_cell::to_vid.

97  {
98  FuncCallContext *funcctx;
99  TupleDesc tuple_desc;
100 
101  /**************************************************************************/
102  /* */
103  Matrix_cell_t *result_tuples = NULL;
104  size_t result_count = 0;
105  /* */
106  /**************************************************************************/
107 
108  if (SRF_IS_FIRSTCALL()) {
109  MemoryContext oldcontext;
110  funcctx = SRF_FIRSTCALL_INIT();
111  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
112 
113 
114  /*********************************************************************/
115  /* */
116  // QUERY
117  // CREATE OR REPLACE FUNCTION pgr_floydWarshalll(
118  // edges_sql TEXT,
119  // directed BOOLEAN,
120  // OUT seq INTEGER,
121  // OUT from_vid bigint,
122  // OUT to_vid bigint,
123  // OUT cost float)
124 
125 
126  PGR_DBG("Calling process");
127  process(
128  text_to_cstring(PG_GETARG_TEXT_P(0)),
129  PG_GETARG_BOOL(1),
130  &result_tuples,
131  &result_count);
132 
133  /* */
134  /*********************************************************************/
135 
136 #if PGSQL_VERSION > 95
137  funcctx->max_calls = result_count;
138 #else
139  funcctx->max_calls = (uint32_t)result_count;
140 #endif
141  funcctx->user_fctx = result_tuples;
142  if (get_call_result_type(fcinfo, NULL, &tuple_desc)
143  != TYPEFUNC_COMPOSITE)
144  ereport(ERROR,
145  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
146  errmsg("function returning record called in context "
147  "that cannot accept type record")));
148 
149  funcctx->tuple_desc = tuple_desc;
150  MemoryContextSwitchTo(oldcontext);
151  }
152 
153  funcctx = SRF_PERCALL_SETUP();
154  tuple_desc = funcctx->tuple_desc;
155  result_tuples = (Matrix_cell_t*) funcctx->user_fctx;
156 
157  if (funcctx->call_cntr < funcctx->max_calls) {
158  HeapTuple tuple;
159  Datum result;
160  Datum *values;
161  bool* nulls;
162 
163  /*********************************************************************/
164  values = palloc(3 * sizeof(Datum));
165  nulls = palloc(3 * sizeof(bool));
166 
167  // postgres starts counting from 1
168  values[0] = Int64GetDatum(result_tuples[funcctx->call_cntr].from_vid);
169  nulls[0] = false;
170  values[1] = Int64GetDatum(result_tuples[funcctx->call_cntr].to_vid);
171  nulls[1] = false;
172  values[2] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost);
173  nulls[2] = false;
174  /*********************************************************************/
175 
176  tuple = heap_form_tuple(tuple_desc, values, nulls);
177  result = HeapTupleGetDatum(tuple);
178  SRF_RETURN_NEXT(funcctx, result);
179  } else {
180  SRF_RETURN_DONE(funcctx);
181  }
182 }
#define PGR_DBG(...)
Definition: debug_macro.h:34
static void process(char *edges_sql, bool directed, Matrix_cell_t **result_tuples, size_t *result_count)
Definition: floydWarshall.c:44
int64_t from_vid
Definition: matrix_cell_t.h:59
int64_t to_vid
Definition: matrix_cell_t.h:60

Here is the call graph for this function:

PG_FUNCTION_INFO_V1 ( floydWarshall  )
static void process ( char *  edges_sql,
bool  directed,
Matrix_cell_t **  result_tuples,
size_t *  result_count 
)
static

Definition at line 44 of file floydWarshall.c.

References do_pgr_floydWarshall(), edges, PGR_DBG, pgr_get_edges_no_id(), pgr_SPI_connect(), pgr_SPI_finish(), and time_msg().

Referenced by floydWarshall().

48  {
50 
51  PGR_DBG("Load data");
52  pgr_edge_t *edges = NULL;
53  size_t total_tuples = 0;
54  pgr_get_edges_no_id(edges_sql, &edges, &total_tuples);
55 
56  if (total_tuples == 0) {
57  PGR_DBG("No edges found");
58  (*result_count) = 0;
59  (*result_tuples) = NULL;
61  return;
62  }
63  PGR_DBG("Total %ld tuples in query:", total_tuples);
64 
65  clock_t start_t = clock();
66  PGR_DBG("Starting processing");
67  char *err_msg = NULL;
68  char *log_msg = NULL;
70  edges,
71  total_tuples,
72  directed,
73  result_tuples,
74  result_count,
75  &log_msg,
76  &err_msg);
77  time_msg(" processing FloydWarshall", start_t, clock());
78 
79  PGR_DBG("Returning %ld tuples\n", *result_count);
80 
81  if (log_msg) {
82  PGR_DBG("LOG = %s\n", log_msg);
83  free(log_msg);
84  }
85 
86  if (err_msg) {
87  if (*result_tuples) free(*result_tuples);
88  elog(ERROR, " %s\n", err_msg);
89  }
90 
91  pfree(edges);
93 }
static edge_t edges[22573]
void do_pgr_floydWarshall(pgr_edge_t *data_edges, size_t total_tuples, bool directedFlag, Matrix_cell_t **return_tuples, size_t *return_count, char **log_msg, char **err_msg)
#define PGR_DBG(...)
Definition: debug_macro.h:34
void time_msg(char *msg, clock_t start_t, clock_t end_t)
Definition: time_msg.c:32
void pgr_SPI_finish(void)
void pgr_get_edges_no_id(char *edges_sql, pgr_edge_t **edges, size_t *total_edges)
edges_sql without id parameter
Definition: edges_input.c:562
void pgr_SPI_connect(void)

Here is the call graph for this function:

Here is the caller graph for this function: