PGROUTING  2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
arrays_input.c File Reference
#include "c_common/arrays_input.h"
#include "utils/lsyscache.h"
#include "catalog/pg_type.h"
#include "c_common/time_msg.h"
#include "c_common/debug_macro.h"
#include <assert.h>
Include dependency graph for arrays_input.c:

Go to the source code of this file.

Functions

static int64_t * pgr_get_bigIntArr (ArrayType *v, size_t *arrlen, bool allow_empty)
 
int64_t * pgr_get_bigIntArray (size_t *arrlen, ArrayType *input)
 enforces the input array to be NOT empty More...
 
int64_t * pgr_get_bigIntArray_allowEmpty (size_t *arrlen, ArrayType *input)
 Allows the input array to be empty. More...
 

Function Documentation

static int64_t* pgr_get_bigIntArr ( ArrayType *  v,
size_t *  arrlen,
bool  allow_empty 
)
static

Definition at line 37 of file arrays_input.c.

References PGR_DBG, and time_msg().

Referenced by pgr_get_bigIntArray(), and pgr_get_bigIntArray_allowEmpty().

37  {
38  clock_t start_t = clock();
39  int64_t *c_array = NULL;;
40 
41  Oid element_type = ARR_ELEMTYPE(v);
42  int *dim = ARR_DIMS(v);
43  int ndim = ARR_NDIM(v);
44  int nitems = ArrayGetNItems(ndim, dim);
45  Datum *elements;
46  bool *nulls;
47  int16 typlen;
48  bool typbyval;
49  char typalign;
50 
51  assert((*arrlen) == 0);
52 
53 
54  if (allow_empty && (ndim == 0 || nitems <= 0)) {
55  PGR_DBG("ndim %i nitems % i", ndim, nitems);
56  return (int64_t*) NULL;
57  }
58  /* the array is not empty*/
59 
60  if (ndim != 1) {
61  elog(ERROR, "One dimension expected");
62  return (int64_t*)NULL;
63  }
64 
65  if (nitems <= 0) {
66  elog(ERROR, "No elements found");
67  return (int64_t*)NULL;
68  }
69 
70  get_typlenbyvalalign(element_type,
71  &typlen, &typbyval, &typalign);
72 
73  /* validate input data type */
74  switch (element_type) {
75  case INT2OID:
76  case INT4OID:
77  case INT8OID:
78  break;
79  default:
80  elog(ERROR, "Expected array of ANY-INTEGER");
81  return (int64_t*)NULL;
82  break;
83  }
84 
85  deconstruct_array(v, element_type, typlen, typbyval,
86  typalign, &elements, &nulls,
87  &nitems);
88 
89  c_array = (int64_t *) palloc(sizeof(int64_t) * (size_t)nitems);
90  if (!c_array) {
91  elog(ERROR, "Out of memory!");
92  }
93 
94 
95  int i;
96  for (i = 0; i < nitems; i++) {
97  if (nulls[i]) {
98  pfree(c_array);
99  elog(ERROR, "NULL value found in Array!");
100  } else {
101  switch (element_type) {
102  case INT2OID:
103  c_array[i] = (int64_t) DatumGetInt16(elements[i]);
104  break;
105  case INT4OID:
106  c_array[i] = (int64_t) DatumGetInt32(elements[i]);
107  break;
108  case INT8OID:
109  c_array[i] = DatumGetInt64(elements[i]);
110  break;
111  }
112  }
113  }
114  (*arrlen) = (size_t)nitems;
115 
116  pfree(elements);
117  pfree(nulls);
118  PGR_DBG("Array size %ld", (*arrlen));
119  time_msg("reading Array", start_t, clock());
120  return c_array;
121 }
#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

Here is the call graph for this function:

Here is the caller graph for this function:

int64_t* pgr_get_bigIntArray ( size_t *  arrlen,
ArrayType *  input 
)

enforces the input array to be NOT empty

Definition at line 124 of file arrays_input.c.

References pgr_get_bigIntArr().

Referenced by process().

124  {
125  return pgr_get_bigIntArr(input, arrlen, false);
126 }
static int64_t * pgr_get_bigIntArr(ArrayType *v, size_t *arrlen, bool allow_empty)
Definition: arrays_input.c:37

Here is the call graph for this function:

Here is the caller graph for this function:

int64_t* pgr_get_bigIntArray_allowEmpty ( size_t *  arrlen,
ArrayType *  input 
)

Allows the input array to be empty.

Definition at line 130 of file arrays_input.c.

References pgr_get_bigIntArr().

Referenced by process().

130  {
131  return pgr_get_bigIntArr(input, arrlen, true);
132 }
static int64_t * pgr_get_bigIntArr(ArrayType *v, size_t *arrlen, bool allow_empty)
Definition: arrays_input.c:37

Here is the call graph for this function:

Here is the caller graph for this function: