|
|
| File: [pgFoundry] / varint / varint / varint.h (download)
Revision 1.1, Sun Sep 21 05:41:01 2008 UTC (23 months, 1 week ago) by jeremyd
Initial commit of an arbitrary precision unsigned integer data type with bitwise operators. The following operators are implemented so far (not optimally, but I'm not worried about that yet): & (bitwise and) | (bitwise or) ^ (bitwise xor) << (bitwise left shift) >> (bitwise right shift) + (arithmetic add) - (arithmetic subtract) * (arithmetic multiply) I plan to implement comparison operators and division next. |
#ifndef VARINT_H
#define VARINT_H
#include "fmgr.h"
/*
* Modeled on struct varlena from postgres.h, but data type is uint32.
*/
typedef struct
{
int32 vl_len_; /* varlena header (do not touch directly!) */
int32 bit_len; /* number of valid bits */
uint32 bit_dat[1]; /* bit string, least sig. uint32 first */
} VarInt;
/*
* 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.
*/
#define DatumGetVarIntP(X) ((VarInt *) PG_DETOAST_DATUM(X))
#define DatumGetVarIntPCopy(X) ((VarInt *) PG_DETOAST_DATUM_COPY(X))
#define VarIntPGetDatum(X) PointerGetDatum(X)
#define PG_GETARG_VARINT_P(n) DatumGetVarIntP(PG_GETARG_DATUM(n))
#define PG_GETARG_VARINT_P_COPY(n) DatumGetVarIntPCopy(PG_GETARG_DATUM(n))
#define PG_RETURN_VARINT_P(x) return VarIntPGetDatum(x)
extern Datum varint_in(PG_FUNCTION_ARGS);
extern Datum varint_out(PG_FUNCTION_ARGS);
extern Datum varinttypmodin(PG_FUNCTION_ARGS);
extern Datum varinttypmodout(PG_FUNCTION_ARGS);
extern Datum varintand(PG_FUNCTION_ARGS);
extern Datum varintor(PG_FUNCTION_ARGS);
extern Datum varintxor(PG_FUNCTION_ARGS);
extern Datum varintadd(PG_FUNCTION_ARGS);
extern Datum varintsub(PG_FUNCTION_ARGS);
extern Datum varintmul(PG_FUNCTION_ARGS);
extern Datum varintnot(PG_FUNCTION_ARGS);
extern Datum varintshl(PG_FUNCTION_ARGS);
extern Datum varintshr(PG_FUNCTION_ARGS);
#if 0
extern Datum varint_recv(PG_FUNCTION_ARGS);
extern Datum varint_send(PG_FUNCTION_ARGS);
extern Datum varint(PG_FUNCTION_ARGS);
#endif
#endif