postgres/contrib/bit
Bruce Momjian 1f747c6722 Attached are the C-routines that implement a BIT and BIT VARYING type.
Adriaan Joubert
1999-11-29 22:34:36 +00:00
..
Makefile Attached are the C-routines that implement a BIT and BIT VARYING type. 1999-11-29 22:34:36 +00:00
README Attached are the C-routines that implement a BIT and BIT VARYING type. 1999-11-29 22:34:36 +00:00
postgres.h Attached are the C-routines that implement a BIT and BIT VARYING type. 1999-11-29 22:34:36 +00:00
varbit.c Attached are the C-routines that implement a BIT and BIT VARYING type. 1999-11-29 22:34:36 +00:00
varbit.h Attached are the C-routines that implement a BIT and BIT VARYING type. 1999-11-29 22:34:36 +00:00
vartest.c Attached are the C-routines that implement a BIT and BIT VARYING type. 1999-11-29 22:34:36 +00:00

README

A set of C routines to implement an SQL-compliant bitstring type.

The file varbit.c contains the c-functions to implement both BIT and
BIT VARYING. Both types are implemented in essentially the same way,
except that BIT is zero padded to a specified length. I've tried to
make this code as independent as possible of the byte length, but it
is quite possible that there may be problems on machines that don't
have 8 bits/byte (are there still any around?).

In the input routines I have assumed that the parser eats the quotes
in B'...' or X'...'.

The SQL standard only defines comparison, SUBSTR and concatenation
operators, and these have been implemented. In addition all logical
operators have been implemented, i.e. ~,|,&,^,<< and >>. This is
useful if one wants to build bit masks. If the two strings are not of
the same length the longer string is truncated (truncation was the
only real option, as padding with zeros could give unintuitive results
for ^) and the result has the length of the shorter string. If there
is a requirement for any other functions, let me know, and I will have
a look.

My knowledge of postgres is not up to integrating a type, so I'm hoping
that somebody can integrate this type for me, or give me some hints as
to what needs to be done. These routines were developed outside the
postgres source tree, with a hacked version of postgres.h. The header
files probably need some ammending.

The included files are 

varbit.h       -- bit string header type
varbit.c       -- the routines
vartest.c      -- a few calls to the routines to 

The following routines are available. 

char * zpbitin(char *s, int dummy,  int32 atttypmod);
	Read in a zero padded bit string of the form X'...' or B'...'
    
char * zpbitout(char *s);
	Print a zero padded bit string in hex X'...'

char * zpbitsout(char *s);
	Print a zero padded bit string in binary B'...'

char * varbitin(char *s, int dummy,  int32 atttypmod);
	Read in a varying length bit string of the form X'...' or B'...'

[There is no need for separate output functions for varying bit, as 
 zpbitout will print them out correctly]

char * bitcat (char *arg1, char *arg2);
	Bit concatenation. 

char * bitsubstr (char *arg, int32 s, int32 l);
	Substring of a bit string.

bool biteq (char *arg1, char *arg2);
bool bitne (char *arg1, char *arg2);
bool bitge (char *arg1, char *arg2);
bool bitgt (char *arg1, char *arg2);
bool bitle (char *arg1, char *arg2);
bool bitlt (char *arg1, char *arg2);
int bitcmp (char *arg1, char *arg2);
	Comparison operators

char * bitand (char * arg1, char * arg2);
char * bitor (char * arg1, char * arg2);
char * bitxor (char * arg1, char * arg2);
char * bitnot (char * arg);
char * bitshiftright (char * arg, int shft);
char * bitshiftleft (char * arg, int shft);
	Bit operations.

If anything else needs to be done, please let me know.

Adriaan (adriaan@albourne.com)