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
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*
|
2001-01-24 20:43:33 +01:00
|
|
|
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
2001-10-25 07:50:21 +02:00
|
|
|
* $Id: array.h,v 1.30 2001/10/25 05:50:10 momjian Exp $
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
* NOTES
|
2000-07-22 05:34:43 +02:00
|
|
|
* XXX the data array should be MAXALIGN'd -- currently we only INTALIGN
|
|
|
|
* which is NOT good enough for, eg, arrays of Interval. Changing this
|
|
|
|
* will break existing user tables so hold off until we have some other
|
|
|
|
* reason to break user tables (like WAL).
|
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"
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2000-07-17 05:05:41 +02:00
|
|
|
/*
|
|
|
|
* Arrays are varlena objects, so must meet the varlena convention that
|
|
|
|
* the first int32 of the object contains the total object size in bytes.
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
2000-07-17 05:05:41 +02:00
|
|
|
int32 size; /* total array size (varlena requirement) */
|
1997-09-08 04:41:22 +02:00
|
|
|
int ndim; /* # of dimensions */
|
|
|
|
int flags; /* implementation flags */
|
2000-07-22 05:34:43 +02:00
|
|
|
/* flags field is currently unused, always zero. */
|
1997-09-08 22:59:27 +02:00
|
|
|
} ArrayType;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2000-07-17 05:05:41 +02:00
|
|
|
/*
|
|
|
|
* fmgr macros for array objects
|
|
|
|
*/
|
2001-03-22 05:01:46 +01:00
|
|
|
#define DatumGetArrayTypeP(X) ((ArrayType *) PG_DETOAST_DATUM(X))
|
|
|
|
#define DatumGetArrayTypePCopy(X) ((ArrayType *) PG_DETOAST_DATUM_COPY(X))
|
|
|
|
#define PG_GETARG_ARRAYTYPE_P(n) DatumGetArrayTypeP(PG_GETARG_DATUM(n))
|
2000-07-17 05:05:41 +02:00
|
|
|
#define PG_GETARG_ARRAYTYPE_P_COPY(n) DatumGetArrayTypePCopy(PG_GETARG_DATUM(n))
|
2001-03-22 05:01:46 +01:00
|
|
|
#define PG_RETURN_ARRAYTYPE_P(x) PG_RETURN_POINTER(x)
|
2000-07-17 05:05:41 +02:00
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
/*
|
2000-07-22 05:34:43 +02:00
|
|
|
* Access macros for array header fields.
|
|
|
|
*
|
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.
|
|
|
|
*/
|
2000-07-22 05:34:43 +02:00
|
|
|
#define ARR_SIZE(a) (((ArrayType *) (a))->size)
|
|
|
|
#define ARR_NDIM(a) (((ArrayType *) (a))->ndim)
|
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
#define ARR_DIMS(a) \
|
2000-07-22 05:34:43 +02:00
|
|
|
((int *) (((char *) (a)) + sizeof(ArrayType)))
|
1996-08-28 03:59:28 +02:00
|
|
|
#define ARR_LBOUND(a) \
|
2000-07-22 05:34:43 +02:00
|
|
|
((int *) (((char *) (a)) + sizeof(ArrayType) + \
|
|
|
|
(sizeof(int) * ARR_NDIM(a))))
|
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) \
|
2000-07-22 05:34:43 +02:00
|
|
|
(MAXALIGN(sizeof(ArrayType) + 2 * sizeof(int) * (n)))
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2000-07-22 05:34:43 +02:00
|
|
|
/*
|
|
|
|
* Returns a pointer to the actual array data.
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
2000-07-22 05:34:43 +02:00
|
|
|
#define ARR_DATA_PTR(a) \
|
|
|
|
(((char *) (a)) + ARR_OVERHEAD(ARR_NDIM(a)))
|
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,
|
2001-03-22 05:01:46 +01:00
|
|
|
bool elmbyval, int elmlen,
|
|
|
|
int arraylen, bool *isNull);
|
2000-06-13 09:35:40 +02:00
|
|
|
extern ArrayType *array_set(ArrayType *array, int nSubscripts, int *indx,
|
2001-03-22 05:01:46 +01:00
|
|
|
Datum dataValue,
|
|
|
|
bool elmbyval, int elmlen,
|
|
|
|
int arraylen, bool *isNull);
|
2000-07-22 05:34:43 +02:00
|
|
|
extern ArrayType *array_get_slice(ArrayType *array, int nSubscripts,
|
2001-03-22 05:01:46 +01:00
|
|
|
int *upperIndx, int *lowerIndx,
|
|
|
|
bool elmbyval, int elmlen,
|
|
|
|
int arraylen, bool *isNull);
|
2000-07-22 05:34:43 +02:00
|
|
|
extern ArrayType *array_set_slice(ArrayType *array, int nSubscripts,
|
2001-03-22 05:01:46 +01:00
|
|
|
int *upperIndx, int *lowerIndx,
|
|
|
|
ArrayType *srcArray,
|
|
|
|
bool elmbyval, int elmlen,
|
|
|
|
int arraylen, bool *isNull);
|
2000-07-22 05:34:43 +02:00
|
|
|
|
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
|
|
|
|
2000-07-17 05:05:41 +02:00
|
|
|
extern ArrayType *construct_array(Datum *elems, int nelems,
|
2001-03-22 05:01:46 +01:00
|
|
|
bool elmbyval, int elmlen, char elmalign);
|
2000-07-17 05:05:41 +02:00
|
|
|
extern void deconstruct_array(ArrayType *array,
|
2001-03-22 05:01:46 +01:00
|
|
|
bool elmbyval, int elmlen, char elmalign,
|
|
|
|
Datum **elemsp, int *nelemsp);
|
2000-07-17 05:05:41 +02:00
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* prototypes for functions defined in arrayutils.c
|
|
|
|
*/
|
|
|
|
|
2000-07-22 05:34:43 +02:00
|
|
|
extern int ArrayGetOffset(int n, int *dim, int *lb, int *indx);
|
|
|
|
extern int ArrayGetOffset0(int n, int *tup, int *scale);
|
|
|
|
extern int ArrayGetNItems(int n, int *a);
|
1998-09-01 05:29:17 +02:00
|
|
|
extern void mda_get_range(int n, int *span, int *st, int *endp);
|
2000-07-22 05:34:43 +02:00
|
|
|
extern void mda_get_prod(int n, int *range, int *prod);
|
|
|
|
extern void mda_get_offset_values(int n, int *dist, int *prod, int *span);
|
|
|
|
extern int mda_next_tuple(int n, int *curr, int *span);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
#endif /* ARRAY_H */
|