1 /*-------------------------------------------------------------------------
4 * Utilities for the new array code. Contain prototypes from the
6 * utils/adt/arrayfuncs.c
7 * utils/adt/arrayutils.c
11 * Copyright (c) 1994, Regents of the University of California
13 * $Id: array.h,v 1.5 1997/09/07 05:02:07 momjian Exp $
16 * XXX the data array should be LONGALIGN'd -- notice that the array
17 * allocation code does not allocate the extra space required for this,
18 * even though the array-packing code does the LONGALIGNs.
20 *-------------------------------------------------------------------------
29 int size; /* total array size (in bytes) */
30 int ndim; /* # of dimensions */
31 int flags; /* implementation flags */
35 * bitmask of ArrayType flags field:
36 * 1st bit - large object flag
37 * 2nd bit - chunk flag (array is chunked if set)
38 * 3rd,4th,&5th bit - large object type (used only if bit 1 is set)
40 #define ARR_LOB_FLAG (0x1)
41 #define ARR_CHK_FLAG (0x2)
42 #define ARR_OBJ_MASK (0x1c)
44 #define ARR_FLAGS(a) ((ArrayType *) a)->flags
45 #define ARR_SIZE(a) (((ArrayType *) a)->size)
47 #define ARR_NDIM(a) (((ArrayType *) a)->ndim)
48 #define ARR_NDIM_PTR(a) (&(((ArrayType *) a)->ndim))
50 #define ARR_IS_LO(a) \
51 (((ArrayType *) a)->flags & ARR_LOB_FLAG)
52 #define SET_LO_FLAG(f,a) \
53 (((ArrayType *) a)->flags |= ((f) ? ARR_LOB_FLAG : 0x0))
55 #define ARR_IS_CHUNKED(a) \
56 (((ArrayType *) a)->flags & ARR_CHK_FLAG)
57 #define SET_CHUNK_FLAG(f,a) \
58 (((ArrayType *) a)->flags |= ((f) ? ARR_CHK_FLAG : 0x0))
60 #define ARR_OBJ_TYPE(a) \
61 ((ARR_FLAGS(a) & ARR_OBJ_MASK) >> 2)
62 #define SET_OBJ_TYPE(f,a) \
63 ((ARR_FLAGS(a)&= ~ARR_OBJ_MASK), (ARR_FLAGS(a)|=((f<<2)&ARR_OBJ_MASK)))
66 * ARR_DIMS returns a pointer to an array of array dimensions (number of
67 * elements along the various array axes).
69 * ARR_LBOUND returns a pointer to an array of array lower bounds.
71 * That is: if the third axis of an array has elements 5 through 10, then
72 * ARR_DIMS(a)[2] == 6 and ARR_LBOUND[2] == 5.
74 * Unlike C, the default lower bound is 1.
77 ((int *) (((char *) a) + sizeof(ArrayType)))
78 #define ARR_LBOUND(a) \
79 ((int *) (((char *) a) + sizeof(ArrayType) + \
80 (sizeof(int) * (((ArrayType *) a)->ndim))))
83 * Returns a pointer to the actual array data.
85 #define ARR_DATA_PTR(a) \
87 DOUBLEALIGN(sizeof(ArrayType) + 2 * (sizeof(int) * (a)->ndim)))
90 * The total array header size for an array of dimension n (in bytes).
92 #define ARR_OVERHEAD(n) \
93 (DOUBLEALIGN(sizeof(ArrayType) + 2 * (n) * sizeof(int)))
95 /*------------------------------------------------------------------------
96 * Miscellaneous helper definitions and routines for arrayfuncs.c
97 *------------------------------------------------------------------------
100 /* #if defined(irix5) */
101 /* #define RETURN_NULL {*isNull = true; return(0); }*/
102 /* #else*//* irix5 */
103 #define RETURN_NULL {*isNull = true; return(0); }
104 /* #endif *//* irix5 */
106 #define MAX_BUFF_SIZE (1 << 13)
110 char lo_name[NAME_LEN];
115 * prototypes for functions defined in arrayfuncs.c
117 extern char *array_in(char *string, Oid element_type);
118 extern char *array_out(ArrayType * v, Oid element_type);
119 extern char *array_dims(ArrayType * v, bool * isNull);
121 array_ref(ArrayType * array, int n, int indx[], int reftype,
122 int elmlen, int arraylen, bool * isNull);
124 array_clip(ArrayType * array, int n, int upperIndx[],
125 int lowerIndx[], int reftype, int len, bool * isNull);
127 array_set(ArrayType * array, int n, int indx[], char *dataPtr,
128 int reftype, int elmlen, int arraylen, bool * isNull);
130 array_assgn(ArrayType * array, int n, int upperIndx[],
131 int lowerIndx[], ArrayType * newArr, int reftype,
132 int len, bool * isNull);
133 extern int array_eq(ArrayType * array1, ArrayType * array2);
135 _LOtransfer(char **destfd, int size, int nitems, char **srcfd,
136 int isSrcLO, int isDestLO);
138 extern char *_array_newLO(int *fd, int flag);
142 * prototypes for functions defined in arrayutils.c
143 * [these names seem to be too generic. Add prefix for arrays? -- AY]
146 extern int GetOffset(int n, int dim[], int lb[], int indx[]);
147 extern int getNitems(int n, int a[]);
148 extern int compute_size(int st[], int endp[], int n, int base);
149 extern void mda_get_offset_values(int n, int dist[], int PC[], int span[]);
150 extern void mda_get_range(int n, int span[], int st[], int endp[]);
151 extern void mda_get_prod(int n, int range[], int P[]);
152 extern int tuple2linear(int n, int tup[], int scale[]);
153 extern void array2chunk_coord(int n, int C[], int a_coord[], int c_coord[]);
154 extern int next_tuple(int n, int curr[], int span[]);
157 * prototypes for functions defined in chunk.c
160 _ChunkArray(int fd, FILE * afd, int ndim, int dim[], int baseSize,
161 int *nbytes, char *chunkfile);
163 _ReadChunkArray(int st[], int endp[], int bsize, int fp,
164 char *destfp, ArrayType * array, int isDestLO, bool * isNull);
165 extern struct varlena *
166 _ReadChunkArray1El(int st[], int bsize, int fp,
167 ArrayType * array, bool * isNull);