PGROUTING  3.2
combinations_input.c File Reference
#include "c_common/combinations_input.h"
#include <math.h>
#include <float.h>
#include <limits.h>
#include <stddef.h>
#include "c_types/column_info_t.h"
#include "c_types/pgr_combination_t.h"
#include "c_common/debug_macro.h"
#include "c_common/get_check_data.h"
#include "c_common/time_msg.h"
Include dependency graph for combinations_input.c:

Go to the source code of this file.

Functions

static void fetch_combination (HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info[2], pgr_combination_t *combination, size_t *valid_combinations)
 
static void get_combinations_2_columns (char *sql, pgr_combination_t **combinations, size_t *totalTuples)
 
void pgr_get_combinations (char *combinations_sql, pgr_combination_t **combinations, size_t *total_combinations)
 combinations_sql More...
 

Function Documentation

◆ fetch_combination()

static void fetch_combination ( HeapTuple *  tuple,
TupleDesc *  tupdesc,
Column_info_t  info[2],
pgr_combination_t combination,
size_t *  valid_combinations 
)
static

Definition at line 50 of file combinations_input.c.

55  {
56  combination->source = pgr_SPI_getBigInt(tuple, tupdesc, info[0]);
57  combination->target = pgr_SPI_getBigInt(tuple, tupdesc, info[1]);
58 
59  *valid_combinations = *valid_combinations + 1;
60 }

References pgr_SPI_getBigInt(), pgr_combination_t::source, and pgr_combination_t::target.

Referenced by get_combinations_2_columns().

◆ get_combinations_2_columns()

static void get_combinations_2_columns ( char *  sql,
pgr_combination_t **  combinations,
size_t *  totalTuples 
)
static

Definition at line 66 of file combinations_input.c.

69  {
70  clock_t start_t = clock();
71 
72  const int tuple_limit = 1000000;
73 
74  size_t total_tuples;
75  size_t valid_combinations;
76 
77  Column_info_t info[2];
78 
79  int i;
80  for (i = 0; i < 2; ++i) {
81  info[i].colNumber = -1;
82  info[i].type = 0;
83  info[i].strict = true;
84  info[i].eType = ANY_INTEGER;
85  }
86  info[0].name = "source";
87  info[1].name = "target";
88 
89  void *SPIplan;
90  SPIplan = pgr_SPI_prepare(sql);
91 
92  Portal SPIportal;
93  SPIportal = pgr_SPI_cursor_open(SPIplan);
94 
95 
96  bool moredata = true;
97  (*totalTuples) = total_tuples = valid_combinations = 0;
98 
99  while (moredata == true) {
100  SPI_cursor_fetch(SPIportal, true, tuple_limit);
101  if (total_tuples == 0)
102  pgr_fetch_column_info(info, 2);
103 
104  size_t ntuples = SPI_processed;
105  total_tuples += ntuples;
106 
107  if (ntuples > 0) {
108  if ((*combinations) == NULL)
109  (*combinations) = (pgr_combination_t *)
110  palloc0(total_tuples * sizeof(pgr_combination_t));
111  else
112  (*combinations) = (pgr_combination_t *)
113  repalloc((*combinations), total_tuples * sizeof(pgr_combination_t));
114 
115  if ((*combinations) == NULL) {
116  elog(ERROR, "Out of memory");
117  }
118 
119  size_t t;
120  SPITupleTable *tuptable = SPI_tuptable;
121  TupleDesc tupdesc = SPI_tuptable->tupdesc;
122  for (t = 0; t < ntuples; t++) {
123  HeapTuple tuple = tuptable->vals[t];
124  fetch_combination(&tuple, &tupdesc, info,
125  &(*combinations)[total_tuples - ntuples + t],
126  &valid_combinations);
127  }
128  SPI_freetuptable(tuptable);
129  } else {
130  moredata = false;
131  }
132  }
133 
134  SPI_cursor_close(SPIportal);
135 
136  if (total_tuples == 0 || valid_combinations == 0) {
137  PGR_DBG("No combinations found");
138  }
139 
140  (*totalTuples) = total_tuples;
141  PGR_DBG("Reading %ld combinations", total_tuples);
142  time_msg("reading combinations", start_t, clock());
143 }

References ANY_INTEGER, Column_info_t::colNumber, Column_info_t::eType, fetch_combination(), Column_info_t::name, PGR_DBG, pgr_fetch_column_info(), pgr_SPI_cursor_open(), pgr_SPI_prepare(), Column_info_t::strict, time_msg(), and Column_info_t::type.

Referenced by pgr_get_combinations().

◆ pgr_get_combinations()

void pgr_get_combinations ( char *  combinations_sql,
pgr_combination_t **  combinations,
size_t *  total_combinations 
)

combinations_sql

SELECT source, target
FROM combinations_table;
Parameters
[in]combinations_sql
[out]combinations
[out]combinations_edges

Definition at line 147 of file combinations_input.c.

150  {
151  get_combinations_2_columns(combinations_sql, combinations, total_combinations);
152 }

References get_combinations_2_columns().

Referenced by process(), and process_combinations().

Column_info_t::colNumber
int colNumber
Definition: column_info_t.h:51
Column_info_t::strict
bool strict
Definition: column_info_t.h:53
pgr_SPI_prepare
SPIPlanPtr pgr_SPI_prepare(char *sql)
Definition: postgres_connection.c:94
pgr_SPI_getBigInt
int64_t pgr_SPI_getBigInt(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info)
Function returns the value of specified column in integer type.
Definition: get_check_data.c:216
pgr_fetch_column_info
void pgr_fetch_column_info(Column_info_t info[], int info_size)
Function tells expected type of each column and then check the correspondence type of each column.
Definition: get_check_data.c:78
Column_info_t::name
char * name
Definition: column_info_t.h:54
pgr_SPI_cursor_open
Portal pgr_SPI_cursor_open(SPIPlanPtr SPIplan)
Definition: postgres_connection.c:107
PGR_DBG
#define PGR_DBG(...)
Definition: debug_macro.h:34
get_combinations_2_columns
static void get_combinations_2_columns(char *sql, pgr_combination_t **combinations, size_t *totalTuples)
Definition: combinations_input.c:66
pgr_combination_t::target
int64_t target
Definition: pgr_combination_t.h:45
pgr_combination_t
Definition: pgr_combination_t.h:43
Column_info_t::eType
expectType eType
Definition: column_info_t.h:55
time_msg
void time_msg(char *msg, clock_t start_t, clock_t end_t)
Definition: time_msg.c:32
ANY_INTEGER
@ ANY_INTEGER
Definition: column_info_t.h:41
pgr_combination_t::source
int64_t source
Definition: pgr_combination_t.h:44
fetch_combination
static void fetch_combination(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info[2], pgr_combination_t *combination, size_t *valid_combinations)
Definition: combinations_input.c:50
Column_info_t::type
uint64_t type
Definition: column_info_t.h:52
Column_info_t
Definition: column_info_t.h:49