head	1.5;
access;
symbols
	release_4_2:1.5
	aix_ok:1.4;
locks; strict;
comment	@ * @;


1.5
date	94.01.19.17.23.27;	author sunita;	state Exp;
branches;
next	1.4;

1.4
date	93.09.28.01.49.19;	author sklower;	state Exp;
branches;
next	1.3;

1.3
date	93.07.27.00.53.55;	author aoki;	state Exp;
branches;
next	1.2;

1.2
date	93.06.23.18.51.25;	author sunita;	state Exp;
branches;
next	1.1;

1.1
date	93.04.14.01.25.17;	author sunita;	state Exp;
branches;
next	;


desc
@New header file for array functions.
@


1.5
log
@changed a #define.
@
text
@/* --------------------------------------------------------------------------
 *   FILE
 *	array.h
 *
 *   DESCRIPTION
 *	Utilities for the new array code.
 *
 *   NOTES
 *	XXX the data array should be LONGALIGN'd -- notice that the array
 *	allocation code does not allocate the extra space required for this,
 *	even though the array-packing code does the LONGALIGNs.
 *
 *   IDENTIFICATION
 *	$Header: /private/src/postgres/src/backend/utils/adt/RCS/array.h,v 1.4 1993/09/28 01:49:19 sklower Exp sunita $
 * --------------------------------------------------------------------------
 */

#ifndef ArrayHIncluded			/* include only once */
#define	ArrayHIncluded 1

typedef struct {
	int	size;	/* total array size (in bytes) */ 
	int	ndim;	/* # of dimensions */
	int	flags;	/* implementation flags */
} ArrayType;

/*
 * 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)
 */
#define	ARR_LOB_FLAG	(0x1)
#define	ARR_CHK_FLAG	(0x2)
#define	ARR_OBJ_MASK	(0x1c)

#define ARR_FLAGS(a)		((ArrayType *) a)->flags
#define	ARR_SIZE(a)		(((ArrayType *) a)->size)

#define ARR_NDIM(a)		(((ArrayType *) a)->ndim)
#define ARR_NDIM_PTR(a)		(&(((ArrayType *) a)->ndim))

#define ARR_IS_LO(a) \
	(((ArrayType *) a)->flags & ARR_LOB_FLAG)
#define SET_LO_FLAG(f,a) \
	(((ArrayType *) a)->flags |= ((f) ? ARR_LOB_FLAG : 0x0))

#define ARR_IS_CHUNKED(a) \
	(((ArrayType *) a)->flags & ARR_CHK_FLAG)
#define SET_CHUNK_FLAG(f,a) \
	(((ArrayType *) a)->flags |= ((f) ? ARR_CHK_FLAG : 0x0))

#define ARR_OBJ_TYPE(a) \
	((ARR_FLAGS(a) & ARR_OBJ_MASK) >> 2)
#define SET_OBJ_TYPE(f,a) \
	((ARR_FLAGS(a)&= ~ARR_OBJ_MASK), (ARR_FLAGS(a)|=((f<<2)&ARR_OBJ_MASK)))
#define ARR_IS_INV(a) (ARR_OBJ_TYPE(a) == Inversion)

/*
 * 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) \
	((int *) (((char *) a) + sizeof(ArrayType)))
#define ARR_LBOUND(a) \
	((int *) (((char *) a) + sizeof(ArrayType) + \
		  (sizeof(int) * (((ArrayType *) a)->ndim))))

/*
 * Returns a pointer to the actual array data.
 */
#define ARR_DATA_PTR(a) \
	(((char *) a) + sizeof(ArrayType) + 2 * (sizeof(int) * (a)->ndim))

/*
 * The total array header size for an array of dimension n (in bytes).
 */
#define ARR_OVERHEAD(n)	\
	(sizeof(ArrayType) + 2 * (n) * sizeof(int))

/*------------------------------------------------------------------------
 * Miscellaneous helper definitions and routines for arrayfuncs.c
 *------------------------------------------------------------------------
 */

#define RETURN_NULL {*isNull = true; return(NULL); }
#define NAME_LEN    30
#define MAX_BUFF_SIZE (1 << 13)

typedef struct {
	char  lo_name[NAME_LEN];
	int   C[MAXDIM];
} CHUNK_INFO;

#endif /* ArrayHIncluded */
@


1.4
log
@changes to arrays to allow ``External'' and ``Jaquith'' large objects as stores
@
text
@d14 1
a14 1
 *	$Header: /home2/aoki/postgres/src/backend/utils/adt/RCS/array.h,v 1.3 1993/07/27 00:53:55 aoki Exp $
d95 1
a95 1
#define MAX_BUFF_SIZE (1 << 18)
@


1.3
log
@added comments (so i wouldn't have to figure it out again :-)
@
text
@d14 1
a14 1
 *	$Header: /home2/aoki/postgres/src/backend/utils/adt/RCS/array.h,v 1.3 1993/07/21 06:46:58 aoki Exp $
d31 1
a31 1
 * 3rd bit - inversion flag (used only if bit 1 is set)
d35 1
a35 1
#define	ARR_INV_FLAG	(0x4)
d37 1
d53 5
a57 4
#define ARR_IS_INV(a) \
	(((ArrayType *) a)->flags & ARR_INV_FLAG)
#define SET_INV_FLAG(f,a) \
	(((ArrayType *) a)->flags |= ((f) ? ARR_INV_FLAG : 0x0))
@


1.2
log
@changed some declarations to allow support for array chunking
@
text
@d1 20
d22 3
a24 5
	int	size;				/* total array size  									*/
	int	ndim;				/* # of dimensions   									*/
	int flags;				/* bit mask of flags: 1st bit - large object flag       */
							/* 2nd bit - chunk flag, array is chunked if set        */
							/* 3rd bit - inversion flag - used only if bit 1 is set */
d27 24
d52 4
a55 15
#define ARR_NDIM(a)    		 (a->ndim)
#define ARR_NDIM_PTR(a) 	 (&(a->ndim))
#define ARR_IS_LO(a)		 (a->flags & 0x1)
#define SET_LO_FLAG(f,a) 	 (a->flags |= ((f) ? 0x1 : 0x0))
#define ARR_IS_CHUNKED(a)	 (a->flags & 0x2)
#define SET_CHUNK_FLAG(f,a)	 (a->flags |= ((f) ? 0x2 : 0x0))
#define ARR_IS_INV(a)		 (a->flags & 0x4)
#define SET_INV_FLAG(f,a) 	 (a->flags |= ((f) ? 0x4 : 0x0))
#define ARR_DIMS(a)	         ((int *) (((char *)(a)) + sizeof(ArrayType)))
#define ARR_LBOUND(a)	     ((int *) (((char *)(a)) + sizeof(ArrayType) + \
                                       (sizeof(int) * (a)->ndim)))
#define ARR_DATA_PTR(a)	     (((char *) (a)) + sizeof(ArrayType) + 2 * \
								(sizeof(int) * (a)->ndim))
#define ARR_OVERHEAD(n)		 (sizeof(ArrayType) + 2*n*sizeof(int))
/*------------------------------------------------------------------------*/
d57 34
a91 2

/*-----------------------------------------------------------------------*/
d99 2
@


1.1
log
@Initial revision
@
text
@d2 5
a6 3
	int	size;
	int	ndim;
	bool isLO;
d9 1
d12 6
a17 2
#define ARR_IS_LO(a)		 (a->isLO)
#define ARR_IS_LO_PTR(a)	 (&(a->isLO))
d26 1
a26 38
#define GetOffset(offset, n, dim, lb, indx)   \
{                                               \
    int ii, scale;                                      \
    for (ii = n-1, scale = 1, offset = 0; ii >= 0; scale*=dim[ii--]) \
        offset += (indx[ii] - lb[ii])*scale; \
}
#define getNitems(ret, n, a) \
{   \
    int ii;     \
    for (ii = 0, ret = 1; ii < n; ret *= a[ii++]);  \
    if (n == 0) ret = 0;    \
}
#define get_offset_values(n, dist, PC, span) 						\
{																	\
	int def1_i, def1_j;												\
 	for (def1_j = n-2, dist[n-1]=0; def1_j  >= 0; def1_j--)			\
    for (def1_i = def1_j+1, dist[def1_j] = PC[def1_j]-1; def1_i < n;	\
        dist[def1_j] -= (span[def1_i] - 1)*PC[def1_i], def1_i++);	\
}																	
#define get_range(n, span, st, endp)								\
{																	\
	int def2_i;														\
	for (def2_i= 0; def2_i < n; def2_i++)							\
		span[def2_i] = endp[def2_i] - st[def2_i] + 1;				\
} 
#define get_prod(n, range, P)										\
{																	\
	int def3_i;														\
	for (def3_i= n-2, P[n-1] = 1; def3_i >= 0; def3_i--)			\
		P[def3_i] = P[def3_i+1] * range[def3_i + 1];				\
} 
#define tuple2linear(n, lin, tup, scale)							\
{																	\
	int def5_i;														\
	for (def5_i= lin = 0; def5_i < n; def5_i++)						\
		lin += tup[def5_i]*scale[def5_i];							\
} 
/*------------------------------------------------------------------------*/
d28 3
a30 2
#define isNumber(x)  ((x) <= '9' && (x) >= '0')
#define isSpace(x)   ((x) == ' ' || (x) == '\t')
d32 4
a35 3
/*------------------------------------------------------------------------*/

#define RETURN_NULL {*isNull = true; return(NULL); }
@
