1 /*-------------------------------------------------------------------------
4 * This file contains some support routines required for array functions.
6 * Copyright (c) 1994, Regents of the University of California
10 * $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayutils.c,v 1.2 1996/11/06 06:49:41 scrappy Exp $
12 *-------------------------------------------------------------------------
15 #define WEAK_C_OPTIMIZER
20 GetOffset(int n, int dim[], int lb[], int indx[])
23 for (i = n-1, scale = 1, offset = 0; i >= 0; scale*=dim[i--])
24 offset += (indx[i] - lb[i])*scale;
29 getNitems(int n, int a[])
32 for (i = 0, ret = 1; i < n; ret *= a[i++]);
38 compute_size(int st[], int endp[], int n, int base)
41 for (i = 0, ret = base; i < n; i++)
42 ret *= (endp[i] - st[i] + 1);
47 mda_get_offset_values(int n, int dist[], int PC[], int span[])
50 for (j = n-2, dist[n-1]=0; j >= 0; j--)
51 for (i = j+1, dist[j] = PC[j]-1; i < n;
52 dist[j] -= (span[i] - 1)*PC[i], i++);
56 mda_get_range(int n, int span[], int st[], int endp[])
59 for (i= 0; i < n; i++)
60 span[i] = endp[i] - st[i] + 1;
64 mda_get_prod(int n, int range[], int P[])
67 for (i= n-2, P[n-1] = 1; i >= 0; i--)
68 P[i] = P[i+1] * range[i + 1];
72 tuple2linear(int n, int tup[], int scale[])
75 for (i= lin = 0; i < n; i++)
76 lin += tup[i]*scale[i];
81 array2chunk_coord(int n, int C[], int a_coord[], int c_coord[])
84 for (i= 0; i < n; i++)
85 c_coord[i] = a_coord[i]/C[i];
88 /*-----------------------------------------------------------------------------
89 generates the tuple that is lexicographically one greater than the current
90 n-tuple in "curr", with the restriction that the i-th element of "curr" is
91 less than the i-th element of "span".
92 RETURNS 0 if no next tuple exists
94 -----------------------------------------------------------------------------*/
96 next_tuple(int n, int curr[], int span[])
101 curr[n-1] = (curr[n-1]+1)%span[n-1];
102 for (i = n-1; i*(!curr[i]); i--)
103 curr[i-1] = (curr[i-1]+1)%span[i-1];