Header And Logo

PostgreSQL
| The world's most advanced open source database.

varbit.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * varbit.h
00004  *    Functions for the SQL datatypes BIT() and BIT VARYING().
00005  *
00006  * Code originally contributed by Adriaan Joubert.
00007  *
00008  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00009  * Portions Copyright (c) 1994, Regents of the University of California
00010  *
00011  * src/include/utils/varbit.h
00012  *
00013  *-------------------------------------------------------------------------
00014  */
00015 #ifndef VARBIT_H
00016 #define VARBIT_H
00017 
00018 #include "fmgr.h"
00019 
00020 /*
00021  * Modeled on struct varlena from postgres.h, but data type is bits8.
00022  */
00023 typedef struct
00024 {
00025     int32       vl_len_;        /* varlena header (do not touch directly!) */
00026     int32       bit_len;        /* number of valid bits */
00027     bits8       bit_dat[1];     /* bit string, most sig. byte first */
00028 } VarBit;
00029 
00030 /*
00031  * fmgr interface macros
00032  *
00033  * BIT and BIT VARYING are toastable varlena types.  They are the same
00034  * as far as representation goes, so we just have one set of macros.
00035  */
00036 #define DatumGetVarBitP(X)         ((VarBit *) PG_DETOAST_DATUM(X))
00037 #define DatumGetVarBitPCopy(X)     ((VarBit *) PG_DETOAST_DATUM_COPY(X))
00038 #define VarBitPGetDatum(X)         PointerGetDatum(X)
00039 #define PG_GETARG_VARBIT_P(n)      DatumGetVarBitP(PG_GETARG_DATUM(n))
00040 #define PG_GETARG_VARBIT_P_COPY(n) DatumGetVarBitPCopy(PG_GETARG_DATUM(n))
00041 #define PG_RETURN_VARBIT_P(x)      return VarBitPGetDatum(x)
00042 
00043 /* Header overhead *in addition to* VARHDRSZ */
00044 #define VARBITHDRSZ         sizeof(int32)
00045 /* Number of bits in this bit string */
00046 #define VARBITLEN(PTR)      (((VarBit *) (PTR))->bit_len)
00047 /* Pointer to the first byte containing bit string data */
00048 #define VARBITS(PTR)        (((VarBit *) (PTR))->bit_dat)
00049 /* Number of bytes in the data section of a bit string */
00050 #define VARBITBYTES(PTR)    (VARSIZE(PTR) - VARHDRSZ - VARBITHDRSZ)
00051 /* Padding of the bit string at the end (in bits) */
00052 #define VARBITPAD(PTR)      (VARBITBYTES(PTR)*BITS_PER_BYTE - VARBITLEN(PTR))
00053 /* Number of bytes needed to store a bit string of a given length */
00054 #define VARBITTOTALLEN(BITLEN)  (((BITLEN) + BITS_PER_BYTE-1)/BITS_PER_BYTE + \
00055                                  VARHDRSZ + VARBITHDRSZ)
00056 /* pointer beyond the end of the bit string (like end() in STL containers) */
00057 #define VARBITEND(PTR)      (((bits8 *) (PTR)) + VARSIZE(PTR))
00058 /* Mask that will cover exactly one byte, i.e. BITS_PER_BYTE bits */
00059 #define BITMASK 0xFF
00060 
00061 
00062 extern Datum bit_in(PG_FUNCTION_ARGS);
00063 extern Datum bit_out(PG_FUNCTION_ARGS);
00064 extern Datum bit_recv(PG_FUNCTION_ARGS);
00065 extern Datum bit_send(PG_FUNCTION_ARGS);
00066 extern Datum bittypmodin(PG_FUNCTION_ARGS);
00067 extern Datum bittypmodout(PG_FUNCTION_ARGS);
00068 extern Datum varbit_in(PG_FUNCTION_ARGS);
00069 extern Datum varbit_out(PG_FUNCTION_ARGS);
00070 extern Datum varbit_recv(PG_FUNCTION_ARGS);
00071 extern Datum varbit_send(PG_FUNCTION_ARGS);
00072 extern Datum varbittypmodin(PG_FUNCTION_ARGS);
00073 extern Datum varbittypmodout(PG_FUNCTION_ARGS);
00074 extern Datum bit(PG_FUNCTION_ARGS);
00075 extern Datum varbit_transform(PG_FUNCTION_ARGS);
00076 extern Datum varbit(PG_FUNCTION_ARGS);
00077 extern Datum biteq(PG_FUNCTION_ARGS);
00078 extern Datum bitne(PG_FUNCTION_ARGS);
00079 extern Datum bitlt(PG_FUNCTION_ARGS);
00080 extern Datum bitle(PG_FUNCTION_ARGS);
00081 extern Datum bitgt(PG_FUNCTION_ARGS);
00082 extern Datum bitge(PG_FUNCTION_ARGS);
00083 extern Datum bitcmp(PG_FUNCTION_ARGS);
00084 
00085 /* avoid the names bitand and bitor, since they are C++ keywords */
00086 extern Datum bit_and(PG_FUNCTION_ARGS);
00087 extern Datum bit_or(PG_FUNCTION_ARGS);
00088 extern Datum bitxor(PG_FUNCTION_ARGS);
00089 extern Datum bitnot(PG_FUNCTION_ARGS);
00090 extern Datum bitshiftleft(PG_FUNCTION_ARGS);
00091 extern Datum bitshiftright(PG_FUNCTION_ARGS);
00092 extern Datum bitcat(PG_FUNCTION_ARGS);
00093 extern Datum bitsubstr(PG_FUNCTION_ARGS);
00094 extern Datum bitsubstr_no_len(PG_FUNCTION_ARGS);
00095 extern Datum bitoverlay(PG_FUNCTION_ARGS);
00096 extern Datum bitoverlay_no_len(PG_FUNCTION_ARGS);
00097 extern Datum bitlength(PG_FUNCTION_ARGS);
00098 extern Datum bitoctetlength(PG_FUNCTION_ARGS);
00099 extern Datum bitfromint4(PG_FUNCTION_ARGS);
00100 extern Datum bittoint4(PG_FUNCTION_ARGS);
00101 extern Datum bitfromint8(PG_FUNCTION_ARGS);
00102 extern Datum bittoint8(PG_FUNCTION_ARGS);
00103 extern Datum bitposition(PG_FUNCTION_ARGS);
00104 extern Datum bitsetbit(PG_FUNCTION_ARGS);
00105 extern Datum bitgetbit(PG_FUNCTION_ARGS);
00106 
00107 #endif