#include "postgres.h"
#include "catalog/pg_type.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/memutils.h"
Go to the source code of this file.
Defines | |
#define | MaxArraySize ((Size) (MaxAllocSize / sizeof(Datum))) |
Functions | |
int | ArrayGetOffset (int n, const int *dim, const int *lb, const int *indx) |
int | ArrayGetOffset0 (int n, const int *tup, const int *scale) |
int | ArrayGetNItems (int ndim, const int *dims) |
void | mda_get_range (int n, int *span, const int *st, const int *endp) |
void | mda_get_prod (int n, const int *range, int *prod) |
void | mda_get_offset_values (int n, int *dist, const int *prod, const int *span) |
int | mda_next_tuple (int n, int *curr, const int *span) |
int32 * | ArrayGetIntegerTypmods (ArrayType *arr, int *n) |
Referenced by ArrayGetNItems().
Definition at line 200 of file arrayutils.c.
References ARR_ELEMTYPE, ARR_NDIM, array_contains_nulls(), CSTRINGOID, DatumGetCString, deconstruct_array(), ereport, errcode(), errmsg(), ERROR, i, NULL, palloc(), pfree(), and pg_atoi().
Referenced by anybit_typmodin(), anychar_typmodin(), anytime_typmodin(), anytimestamp_typmodin(), intervaltypmodin(), and numerictypmodin().
{ int32 *result; Datum *elem_values; int i; if (ARR_ELEMTYPE(arr) != CSTRINGOID) ereport(ERROR, (errcode(ERRCODE_ARRAY_ELEMENT_ERROR), errmsg("typmod array must be type cstring[]"))); if (ARR_NDIM(arr) != 1) ereport(ERROR, (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR), errmsg("typmod array must be one-dimensional"))); if (array_contains_nulls(arr)) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("typmod array must not contain nulls"))); /* hardwired knowledge about cstring's representation details here */ deconstruct_array(arr, CSTRINGOID, -2, false, 'c', &elem_values, NULL, n); result = (int32 *) palloc(*n * sizeof(int32)); for (i = 0; i < *n; i++) result[i] = pg_atoi(DatumGetCString(elem_values[i]), sizeof(int32), '\0'); pfree(elem_values); return result; }
int ArrayGetNItems | ( | int | ndim, | |
const int * | dims | |||
) |
Definition at line 75 of file arrayutils.c.
References Assert, ereport, errcode(), errmsg(), ERROR, i, and MaxArraySize.
Referenced by _arrq_cons(), _lca(), _lt_q_regex(), _ltree_compress(), array_cat(), array_cmp(), array_contain_compare(), array_contains_nulls(), array_create_iterator(), array_eq(), array_fill_internal(), array_get_slice(), array_in(), array_insert_slice(), array_iterator(), array_map(), array_out(), array_recv(), array_replace_internal(), array_send(), array_set(), array_set_slice(), array_slice_size(), array_to_json_internal(), array_to_text_internal(), array_unnest(), arrq_cons(), construct_md_array(), deconstruct_array(), estimate_array_length(), ExecEvalArray(), ExecEvalScalarArrayOp(), get_text_array_contents(), getWeights(), hash_array(), is_strict_saop(), lt_q_regex(), predicate_classify(), and tsa_rewrite_accum().
{ int32 ret; int i; #define MaxArraySize ((Size) (MaxAllocSize / sizeof(Datum))) if (ndim <= 0) return 0; ret = 1; for (i = 0; i < ndim; i++) { int64 prod; /* A negative dimension implies that UB-LB overflowed ... */ if (dims[i] < 0) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), errmsg("array size exceeds the maximum allowed (%d)", (int) MaxArraySize))); prod = (int64) ret *(int64) dims[i]; ret = (int32) prod; if ((int64) ret != prod) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), errmsg("array size exceeds the maximum allowed (%d)", (int) MaxArraySize))); } Assert(ret >= 0); if ((Size) ret > MaxArraySize) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), errmsg("array size exceeds the maximum allowed (%d)", (int) MaxArraySize))); return (int) ret; }
int ArrayGetOffset | ( | int | n, | |
const int * | dim, | |||
const int * | lb, | |||
const int * | indx | |||
) |
Definition at line 31 of file arrayutils.c.
Referenced by array_extract_slice(), array_insert_slice(), array_ref(), array_set(), and array_slice_size().
int ArrayGetOffset0 | ( | int | n, | |
const int * | tup, | |||
const int * | scale | |||
) |
void mda_get_offset_values | ( | int | n, | |
int * | dist, | |||
const int * | prod, | |||
const int * | span | |||
) |
Definition at line 150 of file arrayutils.c.
References i.
Referenced by array_extract_slice(), array_insert_slice(), and array_slice_size().
{ int i, j; dist[n - 1] = 0; for (j = n - 2; j >= 0; j--) { dist[j] = prod[j] - 1; for (i = j + 1; i < n; i++) dist[j] -= (span[i] - 1) * prod[i]; } }
void mda_get_prod | ( | int | n, | |
const int * | range, | |||
int * | prod | |||
) |
Definition at line 134 of file arrayutils.c.
References i.
Referenced by array_extract_slice(), array_insert_slice(), array_slice_size(), and ReadArrayStr().
void mda_get_range | ( | int | n, | |
int * | span, | |||
const int * | st, | |||
const int * | endp | |||
) |
Definition at line 120 of file arrayutils.c.
References i.
Referenced by array_extract_slice(), array_get_slice(), array_insert_slice(), array_set_slice(), and array_slice_size().
{ int i; for (i = 0; i < n; i++) span[i] = endp[i] - st[i] + 1; }
int mda_next_tuple | ( | int | n, | |
int * | curr, | |||
const int * | span | |||
) |
Definition at line 175 of file arrayutils.c.
References i.
Referenced by array_extract_slice(), array_insert_slice(), and array_slice_size().
{ int i; if (n <= 0) return -1; curr[n - 1] = (curr[n - 1] + 1) % span[n - 1]; for (i = n - 1; i && curr[i] == 0; i--) curr[i - 1] = (curr[i - 1] + 1) % span[i - 1]; if (i) return i; if (curr[0]) return 0; return -1; }