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

Go to the source code of this file.

Functions

PGDLLEXPORT Datum _pgr_bipartite (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (_pgr_bipartite)
 
static void process (char *edges_sql, pgr_bipartite_rt **result_tuples, size_t *result_count)
 

Function Documentation

◆ _pgr_bipartite()

PGDLLEXPORT Datum _pgr_bipartite ( PG_FUNCTION_ARGS  )

Definition at line 98 of file bipartite.c.

98  {
99  FuncCallContext *funcctx;
100  TupleDesc tuple_desc;
101  pgr_bipartite_rt *result_tuples = NULL;
102  size_t result_count = 0;
103  if (SRF_IS_FIRSTCALL()) {
104  MemoryContext oldcontext;
105  funcctx = SRF_FIRSTCALL_INIT();
106  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
107  process(
108  text_to_cstring(PG_GETARG_TEXT_P(0)),
109  &result_tuples,
110  &result_count);
111 
112 
113 #if PGSQL_VERSION > 95
114  funcctx->max_calls = result_count;
115 #else
116  funcctx->max_calls = (uint32_t)result_count;
117 #endif
118  funcctx->user_fctx = result_tuples;
119  if (get_call_result_type(fcinfo, NULL, &tuple_desc)
120  != TYPEFUNC_COMPOSITE)
121  ereport(ERROR,
122  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
123  errmsg("function returning record called in context "
124  "that cannot accept type record")));
125  funcctx->tuple_desc = tuple_desc;
126  MemoryContextSwitchTo(oldcontext);
127  }
128 
129  funcctx = SRF_PERCALL_SETUP();
130  tuple_desc = funcctx->tuple_desc;
131  result_tuples = (pgr_bipartite_rt*) funcctx->user_fctx;
132 
133  if (funcctx->call_cntr < funcctx->max_calls) {
134  HeapTuple tuple;
135  Datum result;
136  Datum *values;
137  bool *nulls;
138  size_t call_cntr = funcctx->call_cntr;
139 
140  size_t numb = 2;
141  values =(Datum *)palloc(numb * sizeof(Datum));
142  nulls = palloc(numb * sizeof(bool));
143  size_t i;
144  for (i = 0; i < numb; ++i) {
145  nulls[i] = false;
146  }
147  values[0] = Int64GetDatum(result_tuples[call_cntr].vid);
148  values[1] = Int64GetDatum(result_tuples[call_cntr].color);
149  tuple = heap_form_tuple(tuple_desc, values, nulls);
150  result = HeapTupleGetDatum(tuple);
151  SRF_RETURN_NEXT(funcctx, result);
152  } else {
153  SRF_RETURN_DONE(funcctx);
154  }
155 }

References if(), and process().

◆ PG_FUNCTION_INFO_V1()

PG_FUNCTION_INFO_V1 ( _pgr_bipartite  )

◆ process()

static void process ( char *  edges_sql,
pgr_bipartite_rt **  result_tuples,
size_t *  result_count 
)
static

Definition at line 54 of file bipartite.c.

56  {
58 
59  size_t total_edges = 0;
60  pgr_edge_t* edges = NULL;
61  pgr_get_edges(edges_sql, &edges, &total_edges);
62  if (total_edges == 0) {
64  return;
65  }
66 
67  PGR_DBG("Starting timer");
68  clock_t start_t = clock();
69  char* log_msg = NULL;
70  char* notice_msg = NULL;
71  char* err_msg = NULL;
73  edges, total_edges,
74  result_tuples, result_count,
75  &log_msg,
76  &notice_msg,
77  &err_msg);
78 
79  time_msg("processing pgr_bipartite()", start_t, clock());
80 
81 
82  if (err_msg && (*result_tuples)) {
83  pfree(*result_tuples);
84  (*result_tuples) = NULL;
85  (*result_count) = 0;
86  }
87 
88  pgr_global_report(log_msg, notice_msg, err_msg);
89 
90  if (log_msg) pfree(log_msg);
91  if (notice_msg) pfree(notice_msg);
92  if (err_msg) pfree(err_msg);
93  if (edges) pfree(edges);
95 }

References do_pgr_bipartite(), PGR_DBG, pgr_get_edges(), pgr_global_report(), pgr_SPI_connect(), pgr_SPI_finish(), and time_msg().

Referenced by _pgr_bipartite().

pgr_edge_t
Definition: pgr_edge_t.h:37
pgr_SPI_connect
void pgr_SPI_connect(void)
Definition: postgres_connection.c:82
pgr_SPI_finish
void pgr_SPI_finish(void)
Definition: postgres_connection.c:71
pgr_bipartite_rt
Definition: pgr_bipartite_rt.h:36
process
static void process(char *edges_sql, pgr_bipartite_rt **result_tuples, size_t *result_count)
Definition: bipartite.c:54
PGR_DBG
#define PGR_DBG(...)
Definition: debug_macro.h:34
pgr_get_edges
void pgr_get_edges(char *edges_sql, pgr_edge_t **edges, size_t *total_edges)
basic edge_sql
Definition: edges_input.c:711
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
do_pgr_bipartite
void do_pgr_bipartite(pgr_edge_t *data_edges, size_t total_edges, pgr_bipartite_rt **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
Definition: bipartite_driver.cpp:53
pgr_global_report
void pgr_global_report(char *log, char *notice, char *err)
notice & error
Definition: e_report.c:93