2000-08-21 06:48:57 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* varbit.h
|
|
|
|
* Functions for the SQL datatypes BIT() and BIT VARYING().
|
|
|
|
*
|
|
|
|
* Code originally contributed by Adriaan Joubert.
|
|
|
|
*
|
2010-01-02 17:58:17 +01:00
|
|
|
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
|
2000-08-21 06:48:57 +02:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
2010-01-07 21:17:44 +01:00
|
|
|
* $PostgreSQL: pgsql/src/include/utils/varbit.h,v 1.30 2010/01/07 20:17:44 tgl Exp $
|
2000-08-21 06:48:57 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2000-04-08 04:13:11 +02:00
|
|
|
#ifndef VARBIT_H
|
|
|
|
#define VARBIT_H
|
|
|
|
|
2000-08-21 06:48:57 +02:00
|
|
|
#include "fmgr.h"
|
2000-07-13 00:59:15 +02:00
|
|
|
|
2000-08-21 06:48:57 +02:00
|
|
|
/*
|
|
|
|
* Modeled on struct varlena from postgres.h, but data type is bits8.
|
|
|
|
*/
|
|
|
|
typedef struct
|
2000-04-08 04:13:11 +02:00
|
|
|
{
|
2007-02-28 00:48:10 +01:00
|
|
|
int32 vl_len_; /* varlena header (do not touch directly!) */
|
2000-08-21 06:48:57 +02:00
|
|
|
int32 bit_len; /* number of valid bits */
|
|
|
|
bits8 bit_dat[1]; /* bit string, most sig. byte first */
|
|
|
|
} VarBit;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* fmgr interface macros
|
|
|
|
*
|
|
|
|
* BIT and BIT VARYING are toastable varlena types. They are the same
|
|
|
|
* as far as representation goes, so we just have one set of macros.
|
|
|
|
*/
|
2001-03-22 05:01:46 +01:00
|
|
|
#define DatumGetVarBitP(X) ((VarBit *) PG_DETOAST_DATUM(X))
|
|
|
|
#define DatumGetVarBitPCopy(X) ((VarBit *) PG_DETOAST_DATUM_COPY(X))
|
|
|
|
#define VarBitPGetDatum(X) PointerGetDatum(X)
|
|
|
|
#define PG_GETARG_VARBIT_P(n) DatumGetVarBitP(PG_GETARG_DATUM(n))
|
2000-08-21 06:48:57 +02:00
|
|
|
#define PG_GETARG_VARBIT_P_COPY(n) DatumGetVarBitPCopy(PG_GETARG_DATUM(n))
|
2001-03-22 05:01:46 +01:00
|
|
|
#define PG_RETURN_VARBIT_P(x) return VarBitPGetDatum(x)
|
2000-04-08 04:13:11 +02:00
|
|
|
|
2000-08-21 06:48:57 +02:00
|
|
|
/* Header overhead *in addition to* VARHDRSZ */
|
|
|
|
#define VARBITHDRSZ sizeof(int32)
|
2000-04-08 04:13:11 +02:00
|
|
|
/* Number of bits in this bit string */
|
2000-08-21 06:48:57 +02:00
|
|
|
#define VARBITLEN(PTR) (((VarBit *) (PTR))->bit_len)
|
|
|
|
/* Pointer to the first byte containing bit string data */
|
|
|
|
#define VARBITS(PTR) (((VarBit *) (PTR))->bit_dat)
|
2000-04-08 04:13:11 +02:00
|
|
|
/* Number of bytes in the data section of a bit string */
|
|
|
|
#define VARBITBYTES(PTR) (VARSIZE(PTR) - VARHDRSZ - VARBITHDRSZ)
|
2000-08-21 06:48:57 +02:00
|
|
|
/* Padding of the bit string at the end (in bits) */
|
2000-08-26 23:53:44 +02:00
|
|
|
#define VARBITPAD(PTR) (VARBITBYTES(PTR)*BITS_PER_BYTE - VARBITLEN(PTR))
|
2000-04-08 04:13:11 +02:00
|
|
|
/* Number of bytes needed to store a bit string of a given length */
|
2000-08-26 23:53:44 +02:00
|
|
|
#define VARBITTOTALLEN(BITLEN) (((BITLEN) + BITS_PER_BYTE-1)/BITS_PER_BYTE + \
|
2000-08-21 06:48:57 +02:00
|
|
|
VARHDRSZ + VARBITHDRSZ)
|
2000-04-08 04:13:11 +02:00
|
|
|
/* pointer beyond the end of the bit string (like end() in STL containers) */
|
2000-08-21 06:48:57 +02:00
|
|
|
#define VARBITEND(PTR) (((bits8 *) (PTR)) + VARSIZE(PTR))
|
2000-08-26 23:53:44 +02:00
|
|
|
/* Mask that will cover exactly one byte, i.e. BITS_PER_BYTE bits */
|
2000-04-08 04:13:11 +02:00
|
|
|
#define BITMASK 0xFF
|
|
|
|
|
|
|
|
|
2001-05-22 18:37:17 +02:00
|
|
|
extern Datum bit_in(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bit_out(PG_FUNCTION_ARGS);
|
2003-05-13 01:08:52 +02:00
|
|
|
extern Datum bit_recv(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bit_send(PG_FUNCTION_ARGS);
|
2006-12-30 22:21:56 +01:00
|
|
|
extern Datum bittypmodin(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bittypmodout(PG_FUNCTION_ARGS);
|
2000-08-21 06:48:57 +02:00
|
|
|
extern Datum varbit_in(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum varbit_out(PG_FUNCTION_ARGS);
|
2003-05-13 01:08:52 +02:00
|
|
|
extern Datum varbit_recv(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum varbit_send(PG_FUNCTION_ARGS);
|
2006-12-30 22:21:56 +01:00
|
|
|
extern Datum varbittypmodin(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum varbittypmodout(PG_FUNCTION_ARGS);
|
2001-05-22 18:37:17 +02:00
|
|
|
extern Datum bit(PG_FUNCTION_ARGS);
|
2000-08-21 06:48:57 +02:00
|
|
|
extern Datum varbit(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum biteq(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitne(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitlt(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitle(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitgt(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitge(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitcmp(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitand(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitor(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitxor(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitnot(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitshiftleft(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitshiftright(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitcat(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitsubstr(PG_FUNCTION_ARGS);
|
2010-01-07 21:17:44 +01:00
|
|
|
extern Datum bitsubstr_no_len(PG_FUNCTION_ARGS);
|
2000-08-21 06:48:57 +02:00
|
|
|
extern Datum bitlength(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitoctetlength(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitfromint4(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bittoint4(PG_FUNCTION_ARGS);
|
2002-08-04 08:33:59 +02:00
|
|
|
extern Datum bitfromint8(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bittoint8(PG_FUNCTION_ARGS);
|
2000-10-31 11:22:13 +01:00
|
|
|
extern Datum bitposition(PG_FUNCTION_ARGS);
|
2001-10-28 07:26:15 +01:00
|
|
|
|
2000-04-08 04:13:11 +02:00
|
|
|
#endif
|