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

Go to the source code of this file.

Functions

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

Function Documentation

PGDLLEXPORT Datum johnson ( PG_FUNCTION_ARGS  )

Definition at line 101 of file johnson.c.

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

Referenced by process().

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

Here is the call graph for this function:

Here is the caller graph for this function:

PG_FUNCTION_INFO_V1 ( johnson  )

Referenced by process().

Here is the caller graph for this function:

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

Definition at line 44 of file johnson.c.

References do_pgr_johnson(), johnson(), PG_FUNCTION_INFO_V1(), PGR_DBG, pgr_get_edges_no_id(), pgr_global_report(), pgr_SPI_connect(), pgr_SPI_finish(), and time_msg().

Referenced by johnson().

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  PGR_DBG("Starting processing");
66  char *log_msg = NULL;
67  char *notice_msg = NULL;
68  char *err_msg = NULL;
69  clock_t start_t = clock();
71  edges,
72  total_tuples,
73  directed,
74  result_tuples,
75  result_count,
76  &log_msg,
77  &err_msg);
78  time_msg(" processing Johnson", start_t, clock());
79 
80  if (err_msg && (*result_tuples)) {
81  free(*result_tuples);
82  (*result_tuples) = NULL;
83  (*result_count) = 0;
84  }
85 
86  pgr_global_report(log_msg, notice_msg, err_msg);
87 
88 
89  if (log_msg) pfree(log_msg);
90  if (notice_msg) pfree(notice_msg);
91  if (err_msg) pfree(err_msg);
92 
93  pfree(edges);
95 }
void do_pgr_johnson(pgr_edge_t *data_edges, size_t total_tuples, bool directed, 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_global_report(char *log, char *notice, char *err)
notice & error
Definition: e_report.c:93
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:567
void pgr_SPI_connect(void)

Here is the call graph for this function:

Here is the caller graph for this function: