PGROUTING  2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 maximum_cardinality_matching (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (maximum_cardinality_matching)
 
static void process (char *edges_sql, bool directed, pgr_basic_edge_t **result_tuples, size_t *result_count)
 

Function Documentation

PGDLLEXPORT Datum maximum_cardinality_matching ( PG_FUNCTION_ARGS  )

Definition at line 100 of file maximum_cardinality_matching.c.

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

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

Here is the call graph for this function:

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

Definition at line 46 of file maximum_cardinality_matching.c.

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

Referenced by maximum_cardinality_matching().

50  {
52 
53  pgr_basic_edge_t *edges = NULL;
54  size_t total_edges = 0;
55  pgr_get_basic_edges(edges_sql, &edges, &total_edges);
56 
57  if (total_edges == 0) {
59  return;
60  }
61 
62  PGR_DBG("Starting timer");
63  clock_t start_t = clock();
64  char* log_msg = NULL;
65  char* notice_msg = NULL;
66  char *err_msg = NULL;
67 
69  edges, total_edges,
70  directed,
71  result_tuples,
72  result_count,
73 
74  &log_msg,
75  &notice_msg,
76  &err_msg);
77 
78  time_msg("pgr_maximumCardinalityMatching()", start_t, clock());
79 
80  if (edges) pfree(edges);
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 
94 
96 }
static edge_t edges[22573]
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)
void pgr_get_basic_edges(char *sql, pgr_basic_edge_t **edges, size_t *total_edges)
read basic edges
Definition: edges_input.c:595
#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_SPI_connect(void)

Here is the call graph for this function:

Here is the caller graph for this function: