|
| 1 | +A set of C routines to implement an SQL-compliant bitstring type. |
| 2 | + |
| 3 | +The file varbit.c contains the c-functions to implement both BIT and |
| 4 | +BIT VARYING. Both types are implemented in essentially the same way, |
| 5 | +except that BIT is zero padded to a specified length. I've tried to |
| 6 | +make this code as independent as possible of the byte length, but it |
| 7 | +is quite possible that there may be problems on machines that don't |
| 8 | +have 8 bits/byte (are there still any around?). |
| 9 | + |
| 10 | +In the input routines I have assumed that the parser eats the quotes |
| 11 | +in B'...' or X'...'. |
| 12 | + |
| 13 | +The SQL standard only defines comparison, SUBSTR and concatenation |
| 14 | +operators, and these have been implemented. In addition all logical |
| 15 | +operators have been implemented, i.e. ~,|,&,^,<< and >>. This is |
| 16 | +useful if one wants to build bit masks. If the two strings are not of |
| 17 | +the same length the longer string is truncated (truncation was the |
| 18 | +only real option, as padding with zeros could give unintuitive results |
| 19 | +for ^) and the result has the length of the shorter string. If there |
| 20 | +is a requirement for any other functions, let me know, and I will have |
| 21 | +a look. |
| 22 | + |
| 23 | +My knowledge of postgres is not up to integrating a type, so I'm hoping |
| 24 | +that somebody can integrate this type for me, or give me some hints as |
| 25 | +to what needs to be done. These routines were developed outside the |
| 26 | +postgres source tree, with a hacked version of postgres.h. The header |
| 27 | +files probably need some ammending. |
| 28 | + |
| 29 | +The included files are |
| 30 | + |
| 31 | +varbit.h -- bit string header type |
| 32 | +varbit.c -- the routines |
| 33 | +vartest.c -- a few calls to the routines to |
| 34 | + |
| 35 | +The following routines are available. |
| 36 | + |
| 37 | +char * zpbitin(char *s, int dummy, int32 atttypmod); |
| 38 | + Read in a zero padded bit string of the form X'...' or B'...' |
| 39 | + |
| 40 | +char * zpbitout(char *s); |
| 41 | + Print a zero padded bit string in hex X'...' |
| 42 | + |
| 43 | +char * zpbitsout(char *s); |
| 44 | + Print a zero padded bit string in binary B'...' |
| 45 | + |
| 46 | +char * varbitin(char *s, int dummy, int32 atttypmod); |
| 47 | + Read in a varying length bit string of the form X'...' or B'...' |
| 48 | + |
| 49 | +[There is no need for separate output functions for varying bit, as |
| 50 | + zpbitout will print them out correctly] |
| 51 | + |
| 52 | +char * bitcat (char *arg1, char *arg2); |
| 53 | + Bit concatenation. |
| 54 | + |
| 55 | +char * bitsubstr (char *arg, int32 s, int32 l); |
| 56 | + Substring of a bit string. |
| 57 | + |
| 58 | +bool biteq (char *arg1, char *arg2); |
| 59 | +bool bitne (char *arg1, char *arg2); |
| 60 | +bool bitge (char *arg1, char *arg2); |
| 61 | +bool bitgt (char *arg1, char *arg2); |
| 62 | +bool bitle (char *arg1, char *arg2); |
| 63 | +bool bitlt (char *arg1, char *arg2); |
| 64 | +int bitcmp (char *arg1, char *arg2); |
| 65 | + Comparison operators |
| 66 | + |
| 67 | +char * bitand (char * arg1, char * arg2); |
| 68 | +char * bitor (char * arg1, char * arg2); |
| 69 | +char * bitxor (char * arg1, char * arg2); |
| 70 | +char * bitnot (char * arg); |
| 71 | +char * bitshiftright (char * arg, int shft); |
| 72 | +char * bitshiftleft (char * arg, int shft); |
| 73 | + Bit operations. |
| 74 | + |
| 75 | +If anything else needs to be done, please let me know. |
| 76 | + |
| 77 | +Adriaan (adriaan@albourne.com) |
0 commit comments