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

Go to the source code of this file.

Functions

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

Function Documentation

◆ _pgr_johnson()

PGDLLEXPORT Datum _pgr_johnson ( PG_FUNCTION_ARGS  )

Definition at line 102 of file johnson.c.

102  {
103  FuncCallContext *funcctx;
104  TupleDesc tuple_desc;
105 
106  /**************************************************************************/
107  /* MODIFY AS NEEDED */
108  /* */
109  Matrix_cell_t *result_tuples = NULL;
110  size_t result_count = 0;
111  /* */
112  /**************************************************************************/
113 
114  if (SRF_IS_FIRSTCALL()) {
115  MemoryContext oldcontext;
116  funcctx = SRF_FIRSTCALL_INIT();
117  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
118 
119 
120  /*********************************************************************/
121  /* MODIFY AS NEEDED */
122  // CREATE OR REPLACE FUNCTION pgr_johnson(
123  // edges_sql TEXT,
124  // directed BOOLEAN,
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  /* MODIFY AS NEEDED */
165  // OUT seq BIGINT,
166  // OUT from_vid BIGINT,
167  // OUT to_vid BIGINT,
168  // OUT cost float)
169 
170  values = palloc(3 * sizeof(Datum));
171  nulls = palloc(3 * sizeof(bool));
172 
173  // postgres starts counting from 1
174  values[0] = Int64GetDatum(result_tuples[funcctx->call_cntr].from_vid);
175  nulls[0] = false;
176  values[1] = Int64GetDatum(result_tuples[funcctx->call_cntr].to_vid);
177  nulls[1] = false;
178  values[2] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost);
179  nulls[2] = false;
180 
181  /*********************************************************************/
182 
183  tuple = heap_form_tuple(tuple_desc, values, nulls);
184  result = HeapTupleGetDatum(tuple);
185  SRF_RETURN_NEXT(funcctx, result);
186  } else {
187  SRF_RETURN_DONE(funcctx);
188  }
189 }

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

◆ PG_FUNCTION_INFO_V1()

PG_FUNCTION_INFO_V1 ( _pgr_johnson  )

◆ process()

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

Definition at line 46 of file johnson.c.

50  {
52 
53  PGR_DBG("Load data");
54  pgr_edge_t *edges = NULL;
55  size_t total_tuples = 0;
56  pgr_get_edges_no_id(edges_sql, &edges, &total_tuples);
57 
58  if (total_tuples == 0) {
59  PGR_DBG("No edges found");
60  (*result_count) = 0;
61  (*result_tuples) = NULL;
63  return;
64  }
65  PGR_DBG("Total %ld tuples in query:", total_tuples);
66 
67  PGR_DBG("Starting processing");
68  char *log_msg = NULL;
69  char *notice_msg = NULL;
70  char *err_msg = NULL;
71  clock_t start_t = clock();
73  edges,
74  total_tuples,
75  directed,
76  result_tuples,
77  result_count,
78  &log_msg,
79  &err_msg);
80  time_msg(" processing Johnson", start_t, clock());
81 
82  if (err_msg && (*result_tuples)) {
83  free(*result_tuples);
84  (*result_tuples) = NULL;
85  (*result_count) = 0;
86  }
87 
88  pgr_global_report(log_msg, notice_msg, err_msg);
89 
90 
91  if (log_msg) pfree(log_msg);
92  if (notice_msg) pfree(notice_msg);
93  if (err_msg) pfree(err_msg);
94 
95  pfree(edges);
97 }

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

Referenced by _pgr_johnson().

pgr_edge_t
Definition: pgr_edge_t.h:37
pgr_SPI_connect
void pgr_SPI_connect(void)
Definition: postgres_connection.c:82
pgr_get_edges_no_id
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:733
pgr_SPI_finish
void pgr_SPI_finish(void)
Definition: postgres_connection.c:71
do_pgr_johnson
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)
Definition: johnson_driver.cpp:42
PGR_DBG
#define PGR_DBG(...)
Definition: debug_macro.h:34
process
static void process(char *edges_sql, bool directed, Matrix_cell_t **result_tuples, size_t *result_count)
Definition: johnson.c:46
if
if(DOXYGEN_FOUND) configure_file($
Definition: doxygen/CMakeLists.txt:13
time_msg
void time_msg(char *msg, clock_t start_t, clock_t end_t)
Definition: time_msg.c:32
matrix_cell
Definition: matrix_cell_t.h:37
pgr_global_report
void pgr_global_report(char *log, char *notice, char *err)
notice & error
Definition: e_report.c:93