1996-08-28 03:59:28 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* array.h
|
2000-05-29 23:02:32 +02:00
|
|
|
* Utilities for the new array code. Contains prototypes from the
|
1997-09-07 07:04:48 +02:00
|
|
|
* following files:
|
|
|
|
* utils/adt/arrayfuncs.c
|
|
|
|
* utils/adt/arrayutils.c
|
|
|
|
* utils/adt/chunk.c
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
2000-06-13 09:35:40 +02:00
|
|
|
* $Id: array.h,v 1.25 2000/06/13 07:35:30 tgl Exp $
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
* NOTES
|
2000-05-29 23:02:32 +02:00
|
|
|
* XXX the data array should be MAXALIGN'd -- notice that the array
|
1997-09-07 07:04:48 +02:00
|
|
|
* allocation code does not allocate the extra space required for this,
|
2000-05-29 23:02:32 +02:00
|
|
|
* even though the array-packing code does the MAXALIGNs.
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef ARRAY_H
|
|
|
|
#define ARRAY_H
|
|
|
|
|
2000-05-29 23:02:32 +02:00
|
|
|
#include "fmgr.h"
|
1999-07-15 17:21:54 +02:00
|
|
|
#include "utils/memutils.h"
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
int size; /* total array size (in bytes) */
|
|
|
|
int ndim; /* # of dimensions */
|
|
|
|
int flags; /* implementation flags */
|
1997-09-08 22:59:27 +02:00
|
|
|
} ArrayType;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* bitmask of ArrayType flags field:
|
|
|
|
* 1st bit - large object flag
|
|
|
|
* 2nd bit - chunk flag (array is chunked if set)
|
|
|
|
* 3rd,4th,&5th bit - large object type (used only if bit 1 is set)
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#define ARR_LOB_FLAG (0x1)
|
|
|
|
#define ARR_CHK_FLAG (0x2)
|
|
|
|
#define ARR_OBJ_MASK (0x1c)
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
#define ARR_FLAGS(a) ((ArrayType *) a)->flags
|
|
|
|
#define ARR_SIZE(a) (((ArrayType *) a)->size)
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
#define ARR_NDIM(a) (((ArrayType *) a)->ndim)
|
|
|
|
#define ARR_NDIM_PTR(a) (&(((ArrayType *) a)->ndim))
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
#define ARR_IS_LO(a) \
|
1997-09-07 07:04:48 +02:00
|
|
|
(((ArrayType *) a)->flags & ARR_LOB_FLAG)
|
1996-08-28 03:59:28 +02:00
|
|
|
#define SET_LO_FLAG(f,a) \
|
1997-09-07 07:04:48 +02:00
|
|
|
(((ArrayType *) a)->flags |= ((f) ? ARR_LOB_FLAG : 0x0))
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
#define ARR_IS_CHUNKED(a) \
|
1997-09-07 07:04:48 +02:00
|
|
|
(((ArrayType *) a)->flags & ARR_CHK_FLAG)
|
1996-08-28 03:59:28 +02:00
|
|
|
#define SET_CHUNK_FLAG(f,a) \
|
1997-09-07 07:04:48 +02:00
|
|
|
(((ArrayType *) a)->flags |= ((f) ? ARR_CHK_FLAG : 0x0))
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
#define ARR_OBJ_TYPE(a) \
|
1997-09-07 07:04:48 +02:00
|
|
|
((ARR_FLAGS(a) & ARR_OBJ_MASK) >> 2)
|
1996-08-28 03:59:28 +02:00
|
|
|
#define SET_OBJ_TYPE(f,a) \
|
1997-09-07 07:04:48 +02:00
|
|
|
((ARR_FLAGS(a)&= ~ARR_OBJ_MASK), (ARR_FLAGS(a)|=((f<<2)&ARR_OBJ_MASK)))
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ARR_DIMS returns a pointer to an array of array dimensions (number of
|
|
|
|
* elements along the various array axes).
|
|
|
|
*
|
|
|
|
* ARR_LBOUND returns a pointer to an array of array lower bounds.
|
|
|
|
*
|
|
|
|
* That is: if the third axis of an array has elements 5 through 10, then
|
|
|
|
* ARR_DIMS(a)[2] == 6 and ARR_LBOUND[2] == 5.
|
|
|
|
*
|
|
|
|
* Unlike C, the default lower bound is 1.
|
|
|
|
*/
|
|
|
|
#define ARR_DIMS(a) \
|
1997-09-07 07:04:48 +02:00
|
|
|
((int *) (((char *) a) + sizeof(ArrayType)))
|
1996-08-28 03:59:28 +02:00
|
|
|
#define ARR_LBOUND(a) \
|
1997-09-07 07:04:48 +02:00
|
|
|
((int *) (((char *) a) + sizeof(ArrayType) + \
|
|
|
|
(sizeof(int) * (((ArrayType *) a)->ndim))))
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns a pointer to the actual array data.
|
|
|
|
*/
|
|
|
|
#define ARR_DATA_PTR(a) \
|
1997-09-07 07:04:48 +02:00
|
|
|
(((char *) a) + \
|
1999-07-19 09:07:29 +02:00
|
|
|
MAXALIGN(sizeof(ArrayType) + 2 * (sizeof(int) * (a)->ndim)))
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The total array header size for an array of dimension n (in bytes).
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#define ARR_OVERHEAD(n) \
|
1999-07-19 09:07:29 +02:00
|
|
|
(MAXALIGN(sizeof(ArrayType) + 2 * (n) * sizeof(int)))
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*------------------------------------------------------------------------
|
|
|
|
* Miscellaneous helper definitions and routines for arrayfuncs.c
|
|
|
|
*------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
#define RETURN_NULL(type) do { *isNull = true; return (type) 0; } while (0)
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
#define NAME_LEN 30
|
1999-05-03 21:10:48 +02:00
|
|
|
#define MAX_BUFF_SIZE BLCKSZ
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
char lo_name[NAME_LEN];
|
|
|
|
int C[MAXDIM];
|
1997-09-08 23:56:23 +02:00
|
|
|
} CHUNK_INFO;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* prototypes for functions defined in arrayfuncs.c
|
|
|
|
*/
|
2000-06-13 09:35:40 +02:00
|
|
|
extern Datum array_in(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum array_out(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum array_eq(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum array_dims(PG_FUNCTION_ARGS);
|
|
|
|
|
|
|
|
extern Datum array_ref(ArrayType *array, int nSubscripts, int *indx,
|
|
|
|
bool elmbyval, int elmlen,
|
|
|
|
int arraylen, bool *isNull);
|
|
|
|
extern ArrayType *array_set(ArrayType *array, int nSubscripts, int *indx,
|
|
|
|
Datum dataValue,
|
|
|
|
bool elmbyval, int elmlen,
|
|
|
|
int arraylen, bool *isNull);
|
|
|
|
extern ArrayType *array_clip(ArrayType *array, int nSubscripts,
|
|
|
|
int *upperIndx, int *lowerIndx,
|
|
|
|
bool elmbyval, int elmlen, bool *isNull);
|
|
|
|
extern ArrayType *array_assgn(ArrayType *array, int nSubscripts,
|
|
|
|
int *upperIndx, int *lowerIndx,
|
|
|
|
ArrayType *newArr,
|
|
|
|
bool elmbyval, int elmlen, bool *isNull);
|
2000-05-29 23:02:32 +02:00
|
|
|
extern Datum array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType);
|
2000-06-13 09:35:40 +02:00
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
extern int _LOtransfer(char **destfd, int size, int nitems, char **srcfd,
|
1997-09-07 07:04:48 +02:00
|
|
|
int isSrcLO, int isDestLO);
|
1997-09-08 04:41:22 +02:00
|
|
|
extern char *_array_newLO(int *fd, int flag);
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* prototypes for functions defined in arrayutils.c
|
|
|
|
* [these names seem to be too generic. Add prefix for arrays? -- AY]
|
|
|
|
*/
|
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
extern int GetOffset(int n, int *dim, int *lb, int *indx);
|
|
|
|
extern int getNitems(int n, int *a);
|
|
|
|
extern int compute_size(int *st, int *endp, int n, int base);
|
|
|
|
extern void mda_get_offset_values(int n, int *dist, int *PC, int *span);
|
|
|
|
extern void mda_get_range(int n, int *span, int *st, int *endp);
|
|
|
|
extern void mda_get_prod(int n, int *range, int *P);
|
|
|
|
extern int tuple2linear(int n, int *tup, int *scale);
|
|
|
|
extern void array2chunk_coord(int n, int *C, int *a_coord, int *c_coord);
|
|
|
|
extern int next_tuple(int n, int *curr, int *span);
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* prototypes for functions defined in chunk.c
|
|
|
|
*/
|
1998-09-01 06:40:42 +02:00
|
|
|
extern char *_ChunkArray(int fd, FILE *afd, int ndim, int *dim, int baseSize,
|
1997-09-07 07:04:48 +02:00
|
|
|
int *nbytes, char *chunkfile);
|
1998-09-01 06:40:42 +02:00
|
|
|
extern int _ReadChunkArray(int *st, int *endp, int bsize, int fp,
|
1997-09-08 23:56:23 +02:00
|
|
|
char *destfp, ArrayType *array, int isDestLO, bool *isNull);
|
1998-09-01 06:40:42 +02:00
|
|
|
extern struct varlena *_ReadChunkArray1El(int *st, int bsize, int fp,
|
1997-09-08 23:56:23 +02:00
|
|
|
ArrayType *array, bool *isNull);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
#endif /* ARRAY_H */
|