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

Go to the source code of this file.

Functions

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

Function Documentation

◆ _pgr_maxcardinalitymatch()

PGDLLEXPORT Datum _pgr_maxcardinalitymatch ( PG_FUNCTION_ARGS  )

Definition at line 102 of file maximum_cardinality_matching.c.

102  {
103  FuncCallContext *funcctx;
104  TupleDesc tuple_desc;
105 
106  /**************************************************************************/
107  pgr_basic_edge_t *result_tuples = NULL;
108  size_t result_count = 0;
109  /**************************************************************************/
110 
111  if (SRF_IS_FIRSTCALL()) {
112  MemoryContext oldcontext;
113  funcctx = SRF_FIRSTCALL_INIT();
114  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
115 
116 
117  /**********************************************************************/
118  PGR_DBG("Calling process");
119  process(
120  text_to_cstring(PG_GETARG_TEXT_P(0)),
121  PG_GETARG_BOOL(1),
122  &result_tuples,
123  &result_count);
124 
125  /**********************************************************************/
126 
127 #if PGSQL_VERSION > 95
128  funcctx->max_calls = result_count;
129 #else
130  funcctx->max_calls = (uint32_t)result_count;
131 #endif
132  funcctx->user_fctx = result_tuples;
133  if (get_call_result_type(fcinfo, NULL, &tuple_desc)
134  != TYPEFUNC_COMPOSITE) {
135  ereport(ERROR,
136  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
137  errmsg("function returning record called in context "
138  "that cannot accept type record")));
139  }
140 
141  funcctx->tuple_desc = tuple_desc;
142  MemoryContextSwitchTo(oldcontext);
143  }
144 
145  funcctx = SRF_PERCALL_SETUP();
146  tuple_desc = funcctx->tuple_desc;
147  result_tuples = (pgr_basic_edge_t *) funcctx->user_fctx;
148 
149  if (funcctx->call_cntr < funcctx->max_calls) {
150  HeapTuple tuple;
151  Datum result;
152  Datum *values;
153  bool *nulls;
154 
155  /**********************************************************************/
156 
157  values = palloc(4 * sizeof(Datum));
158  nulls = palloc(4 * sizeof(bool));
159 
160 
161  size_t i;
162  for (i = 0; i < 4; ++i) {
163  nulls[i] = false;
164  }
165 
166  values[0] = Int32GetDatum(funcctx->call_cntr + 1);
167  values[1] = Int64GetDatum(result_tuples[funcctx->call_cntr].edge_id);
168  values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].source);
169  values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].target);
170 
171  /**********************************************************************/
172 
173  tuple = heap_form_tuple(tuple_desc, values, nulls);
174  result = HeapTupleGetDatum(tuple);
175  SRF_RETURN_NEXT(funcctx, result);
176  } else {
177  SRF_RETURN_DONE(funcctx);
178  }
179 }

References pgr_basic_edge_t::edge_id, if(), PGR_DBG, process(), pgr_basic_edge_t::source, and pgr_basic_edge_t::target.

◆ PG_FUNCTION_INFO_V1()

PG_FUNCTION_INFO_V1 ( _pgr_maxcardinalitymatch  )

◆ process()

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

Definition at line 48 of file maximum_cardinality_matching.c.

52  {
54 
55  pgr_basic_edge_t *edges = NULL;
56  size_t total_edges = 0;
57  pgr_get_basic_edges(edges_sql, &edges, &total_edges);
58 
59  if (total_edges == 0) {
61  return;
62  }
63 
64  PGR_DBG("Starting timer");
65  clock_t start_t = clock();
66  char* log_msg = NULL;
67  char* notice_msg = NULL;
68  char *err_msg = NULL;
69 
71  edges, total_edges,
72  directed,
73  result_tuples,
74  result_count,
75 
76  &log_msg,
77  &notice_msg,
78  &err_msg);
79 
80  time_msg("pgr_maximumCardinalityMatching()", start_t, clock());
81 
82  if (edges) pfree(edges);
83 
84  if (err_msg && (*result_tuples)) {
85  pfree(*result_tuples);
86  (*result_tuples) = NULL;
87  (*result_count) = 0;
88  }
89 
90  pgr_global_report(log_msg, notice_msg, err_msg);
91 
92  if (log_msg) pfree(log_msg);
93  if (notice_msg) pfree(notice_msg);
94  if (err_msg) pfree(err_msg);
95 
96 
98 }

References do_pgr_maximum_cardinality_matching(), PGR_DBG, pgr_get_basic_edges(), pgr_global_report(), pgr_SPI_connect(), pgr_SPI_finish(), and time_msg().

Referenced by _pgr_maxcardinalitymatch().

process
static void process(char *edges_sql, bool directed, pgr_basic_edge_t **result_tuples, size_t *result_count)
Definition: maximum_cardinality_matching.c:48
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_DBG
#define PGR_DBG(...)
Definition: debug_macro.h:34
do_pgr_maximum_cardinality_matching
void do_pgr_maximum_cardinality_matching(pgr_basic_edge_t *data_edges, size_t total_tuples, bool directed, pgr_basic_edge_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
Definition: maximum_cardinality_matching_driver.cpp:42
pgr_get_basic_edges
void pgr_get_basic_edges(char *sql, pgr_basic_edge_t **edges, size_t *total_edges)
read basic edges
Definition: edges_input.c:766
pgr_basic_edge_t
Definition: pgr_basic_edge_t.h:38
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
pgr_global_report
void pgr_global_report(char *log, char *notice, char *err)
notice & error
Definition: e_report.c:93