PGROUTING  2.5
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 87 of file johnson.c.

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

Referenced by process().

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

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 43 of file johnson.c.

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

Referenced by johnson().

47  {
49 
50  PGR_DBG("Load data");
51  pgr_edge_t *edges = NULL;
52  size_t total_tuples = 0;
53  pgr_get_edges_no_id(edges_sql, &edges, &total_tuples);
54 
55  if (total_tuples == 0) {
56  PGR_DBG("No edges found");
57  (*result_count) = 0;
58  (*result_tuples) = NULL;
60  return;
61  }
62  PGR_DBG("Total %ld tuples in query:", total_tuples);
63 
64  PGR_DBG("Starting processing");
65  char *err_msg = (char *)"";
66  clock_t start_t = clock();
68  edges,
69  total_tuples,
70  directed,
71  result_tuples,
72  result_count,
73  &err_msg);
74  time_msg(" processing Johnson", start_t, clock());
75  PGR_DBG("Returning %ld tuples\n", *result_count);
76  PGR_DBG("Returned message = %s\n", err_msg);
77 
78  free(err_msg);
79  pfree(edges);
81 }
static edge_t edges[22573]
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 **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: