diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2000-07-22 03:34:43 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2000-07-22 03:34:43 +0000 |
commit | d0e17e211230d37f26843711115864a87d0eae18 (patch) | |
tree | b039e4879d7faeb1ddfc33f6051af4b21fbc3ce4 /src/backend/utils/adt/arrayutils.c | |
parent | ec37ea1cc1356f1a0b7dad1d9e4933e50bea583f (diff) | |
download | postgresql-d0e17e211230d37f26843711115864a87d0eae18.tar.gz postgresql-d0e17e211230d37f26843711115864a87d0eae18.zip |
Arrays are toastable. (At least if you initdb, which I didn't force.)
Remove a bunch of crufty code for large-object-based arrays, which is
superseded by TOAST and likely hasn't worked in a long time anyway.
Clean up array code a little, and in particular eliminate its habit
of scribbling on the input array (ie, modifying the input tuple :-().
Diffstat (limited to 'src/backend/utils/adt/arrayutils.c')
-rw-r--r-- | src/backend/utils/adt/arrayutils.c | 106 |
1 files changed, 55 insertions, 51 deletions
diff --git a/src/backend/utils/adt/arrayutils.c b/src/backend/utils/adt/arrayutils.c index 3293cecc960..d103d8b885b 100644 --- a/src/backend/utils/adt/arrayutils.c +++ b/src/backend/utils/adt/arrayutils.c @@ -8,61 +8,62 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayutils.c,v 1.10 2000/01/26 05:57:12 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayutils.c,v 1.11 2000/07/22 03:34:43 tgl Exp $ * *------------------------------------------------------------------------- */ -#define WEAK_C_OPTIMIZER - #include "postgres.h" + #include "utils/array.h" + + +/* Convert subscript list into linear element number (from 0) */ int -GetOffset(int n, int *dim, int *lb, int *indx) +ArrayGetOffset(int n, int *dim, int *lb, int *indx) { int i, - scale, - offset; + scale = 1, + offset = 0; - for (i = n - 1, scale = 1, offset = 0; i >= 0; scale *= dim[i--]) + for (i = n - 1; i >= 0; i--) + { offset += (indx[i] - lb[i]) * scale; + scale *= dim[i]; + } return offset; } +/* Same, but subscripts are assumed 0-based, and use a scale array + * instead of raw dimension data (see mda_get_prod to create scale array) + */ int -getNitems(int n, int *a) +ArrayGetOffset0(int n, int *tup, int *scale) { int i, - ret; + lin = 0; - for (i = 0, ret = 1; i < n; ret *= a[i++]); - if (n == 0) - ret = 0; - return ret; + for (i = 0; i < n; i++) + lin += tup[i] * scale[i]; + return lin; } +/* Convert array dimensions into number of elements */ int -compute_size(int *st, int *endp, int n, int base) +ArrayGetNItems(int n, int *a) { int i, ret; - for (i = 0, ret = base; i < n; i++) - ret *= (endp[i] - st[i] + 1); + if (n <= 0) + return 0; + ret = 1; + for (i = 0; i < n; i++) + ret *= a[i]; return ret; } -void -mda_get_offset_values(int n, int *dist, int *PC, int *span) -{ - int i, - j; - - for (j = n - 2, dist[n - 1] = 0; j >= 0; j--) - for (i = j + 1, dist[j] = PC[j] - 1; i < n; - dist[j] -= (span[i] - 1) * PC[i], i++); -} - +/* Compute ranges (sub-array dimensions) for an array slice */ void mda_get_range(int n, int *span, int *st, int *endp) { @@ -72,56 +73,59 @@ mda_get_range(int n, int *span, int *st, int *endp) span[i] = endp[i] - st[i] + 1; } +/* Compute products of array dimensions, ie, scale factors for subscripts */ void -mda_get_prod(int n, int *range, int *P) +mda_get_prod(int n, int *range, int *prod) { int i; - for (i = n - 2, P[n - 1] = 1; i >= 0; i--) - P[i] = P[i + 1] * range[i + 1]; -} - -int -tuple2linear(int n, int *tup, int *scale) -{ - int i, - lin; - - for (i = lin = 0; i < n; i++) - lin += tup[i] * scale[i]; - return lin; + prod[n - 1] = 1; + for (i = n - 2; i >= 0; i--) + prod[i] = prod[i + 1] * range[i + 1]; } +/* From products of whole-array dimensions and spans of a sub-array, + * compute offset distances needed to step through subarray within array + */ void -array2chunk_coord(int n, int *C, int *a_coord, int *c_coord) +mda_get_offset_values(int n, int *dist, int *prod, int *span) { - int i; + int i, + j; - for (i = 0; i < n; i++) - c_coord[i] = a_coord[i] / C[i]; + 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]; + } } /*----------------------------------------------------------------------------- generates the tuple that is lexicographically one greater than the current n-tuple in "curr", with the restriction that the i-th element of "curr" is less than the i-th element of "span". - RETURNS 0 if no next tuple exists - 1 otherwise - -----------------------------------------------------------------------------*/ + Returns -1 if no next tuple exists, else the subscript position (0..n-1) + corresponding to the dimension to advance along. + ----------------------------------------------------------------------------- +*/ int -next_tuple(int n, int *curr, int *span) +mda_next_tuple(int n, int *curr, int *span) { int i; - if (!n) + if (n <= 0) return -1; + curr[n - 1] = (curr[n - 1] + 1) % span[n - 1]; - for (i = n - 1; i * (!curr[i]); i--) + 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; } |