]> granicus.if.org Git - postgresql/blob - src/include/utils/array.h
Massive commit to run PGINDENT on all *.c and *.h files.
[postgresql] / src / include / utils / array.h
1 /*-------------------------------------------------------------------------
2  *
3  * array.h--
4  *        Utilities for the new array code. Contain prototypes from the
5  *        following files:
6  *                              utils/adt/arrayfuncs.c
7  *                              utils/adt/arrayutils.c
8  *                              utils/adt/chunk.c
9  *
10  *
11  * Copyright (c) 1994, Regents of the University of California
12  *
13  * $Id: array.h,v 1.5 1997/09/07 05:02:07 momjian Exp $
14  *
15  * NOTES
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.
19  *
20  *-------------------------------------------------------------------------
21  */
22 #ifndef ARRAY_H
23 #define ARRAY_H
24
25 #include <stdio.h>
26
27 typedef struct
28 {
29         int                             size;           /* total array size (in bytes) */
30         int                             ndim;           /* # of dimensions */
31         int                             flags;          /* implementation flags */
32 }                               ArrayType;
33
34 /*
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)
39  */
40 #define ARR_LOB_FLAG    (0x1)
41 #define ARR_CHK_FLAG    (0x2)
42 #define ARR_OBJ_MASK    (0x1c)
43
44 #define ARR_FLAGS(a)                    ((ArrayType *) a)->flags
45 #define ARR_SIZE(a)                             (((ArrayType *) a)->size)
46
47 #define ARR_NDIM(a)                             (((ArrayType *) a)->ndim)
48 #define ARR_NDIM_PTR(a)                 (&(((ArrayType *) a)->ndim))
49
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))
54
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))
59
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)))
64
65 /*
66  * ARR_DIMS returns a pointer to an array of array dimensions (number of
67  * elements along the various array axes).
68  *
69  * ARR_LBOUND returns a pointer to an array of array lower bounds.
70  *
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.
73  *
74  * Unlike C, the default lower bound is 1.
75  */
76 #define ARR_DIMS(a) \
77                 ((int *) (((char *) a) + sizeof(ArrayType)))
78 #define ARR_LBOUND(a) \
79                 ((int *) (((char *) a) + sizeof(ArrayType) + \
80                                   (sizeof(int) * (((ArrayType *) a)->ndim))))
81
82 /*
83  * Returns a pointer to the actual array data.
84  */
85 #define ARR_DATA_PTR(a) \
86                 (((char *) a) + \
87                  DOUBLEALIGN(sizeof(ArrayType) + 2 * (sizeof(int) * (a)->ndim)))
88
89 /*
90  * The total array header size for an array of dimension n (in bytes).
91  */
92 #define ARR_OVERHEAD(n) \
93                 (DOUBLEALIGN(sizeof(ArrayType) + 2 * (n) * sizeof(int)))
94
95 /*------------------------------------------------------------------------
96  * Miscellaneous helper definitions and routines for arrayfuncs.c
97  *------------------------------------------------------------------------
98  */
99
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 */
105 #define NAME_LEN        30
106 #define MAX_BUFF_SIZE (1 << 13)
107
108 typedef struct
109 {
110         char                    lo_name[NAME_LEN];
111         int                             C[MAXDIM];
112 }                               CHUNK_INFO;
113
114 /*
115  * prototypes for functions defined in arrayfuncs.c
116  */
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);
120 extern Datum
121 array_ref(ArrayType * array, int n, int indx[], int reftype,
122                   int elmlen, int arraylen, bool * isNull);
123 extern Datum
124 array_clip(ArrayType * array, int n, int upperIndx[],
125                    int lowerIndx[], int reftype, int len, bool * isNull);
126 extern char    *
127 array_set(ArrayType * array, int n, int indx[], char *dataPtr,
128                   int reftype, int elmlen, int arraylen, bool * isNull);
129 extern char    *
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);
134 extern int
135 _LOtransfer(char **destfd, int size, int nitems, char **srcfd,
136                         int isSrcLO, int isDestLO);
137
138 extern char    *_array_newLO(int *fd, int flag);
139
140
141 /*
142  * prototypes for functions defined in arrayutils.c
143  * [these names seem to be too generic. Add prefix for arrays? -- AY]
144  */
145
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[]);
155
156 /*
157  * prototypes for functions defined in chunk.c
158  */
159 extern char    *
160 _ChunkArray(int fd, FILE * afd, int ndim, int dim[], int baseSize,
161                         int *nbytes, char *chunkfile);
162 extern int
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);
168
169
170 #endif                                                  /* ARRAY_H */