pgbitmap
Postgres extension providing a bitmap type
|
Define a bitmap type for postgres. More...
#include "pgbitmap.h"
Macros | |
#define | INT32SIZE_B64 7 |
#define | INT64SIZE_B64 12 |
Functions | |
static unsigned | b64_encode (const char *src, unsigned len, char *dst) |
static unsigned | b64_decode (const char *src, unsigned len, char *dst) |
static boolean | bitmapEmpty (Bitmap *bitmap) |
static void | clearBitmap (Bitmap *bitmap) |
static Bitmap * | newBitmap (int32 min, int32 max) |
bool | bitmapTestbit (Bitmap *bitmap, int32 bit) |
Bitmap * | bitmapCopy (Bitmap *bitmap) |
static Bitmap * | extendBitmap (Bitmap *bitmap, int32 bit) |
static void | doSetBit (Bitmap *bitmap, int32 bit) |
static Bitmap * | bitmapSetbit (Bitmap *bitmap, int32 bit) |
static int32 | bitmapNextBit (Bitmap *bitmap, int32 inbit, bool *found) |
static char * | serialise_bitmap (Bitmap *bitmap) |
static void | reduceBitmap (Bitmap *bitmap) |
static void | doClearBit (Bitmap *bitmap, int32 bit) |
static Bitmap * | bitmapClearbit (Bitmap *bitmap, int32 bit) |
static Bitmap * | bitmapSetMin (Bitmap *bitmap, int bitmin) |
static Bitmap * | bitmapSetMax (Bitmap *bitmap, int bitmax) |
static bool | bitmapEqual (Bitmap *bitmap1, Bitmap *bitmap2) |
static Bitmap * | bitmapUnion (Bitmap *bitmap1, Bitmap *bitmap2) |
static Bitmap * | bitmapIntersect (Bitmap *bitmap1, Bitmap *bitmap2) |
static Bitmap * | bitmapMinus (Bitmap *bitmap1, Bitmap *bitmap2) |
static void | serialise_int32 (char **p_stream, int32 value) |
static int32 | deserialise_int32 (char **p_stream) |
static void | serialise_stream (char **p_stream, int32 bytes, char *instream) |
static int | streamlen (int32 bytes) |
static void | deserialise_stream (char **p_stream, int32 bytes, char *outstream) |
static Bitmap * | deserialise_bitmap (char *charstream) |
static int | bitmapCmp (Bitmap *bitmap1, Bitmap *bitmap2) |
Datum | bitmap_in (FunctionCallInfo fcinfo) |
Datum | bitmap_out (FunctionCallInfo fcinfo) |
Datum | bitmap_is_empty (FunctionCallInfo fcinfo) |
Datum | bitmap_bitmin (FunctionCallInfo fcinfo) |
Datum | bitmap_bitmax (FunctionCallInfo fcinfo) |
Datum | bitmap_bits (FunctionCallInfo fcinfo) |
Datum | bitmap_new_empty (FunctionCallInfo fcinfo) |
Datum | bitmap_new (FunctionCallInfo fcinfo) |
Datum | bitmap_setbit (FunctionCallInfo fcinfo) |
Datum | bitmap_testbit (FunctionCallInfo fcinfo) |
Datum | bitmap_setmin (FunctionCallInfo fcinfo) |
Datum | bitmap_setmax (FunctionCallInfo fcinfo) |
Datum | bitmap_equal (FunctionCallInfo fcinfo) |
Datum | bitmap_nequal (FunctionCallInfo fcinfo) |
Datum | bitmap_cmp (FunctionCallInfo fcinfo) |
Datum | bitmap_lt (FunctionCallInfo fcinfo) |
Datum | bitmap_le (FunctionCallInfo fcinfo) |
Datum | bitmap_gt (FunctionCallInfo fcinfo) |
Datum | bitmap_ge (FunctionCallInfo fcinfo) |
Datum | bitmap_union (FunctionCallInfo fcinfo) |
Datum | bitmap_clearbit (FunctionCallInfo fcinfo) |
Datum | bitmap_intersection (FunctionCallInfo fcinfo) |
Datum | bitmap_minus (FunctionCallInfo fcinfo) |
Variables | |
static uint64 | bitmasks [64] |
static const char | _base64 [] |
static const short | b64lookup [128] |
Define a bitmap type for postgres.
#define INT32SIZE_B64 7 |
The length of a 64-bit integer as a base64 string. This should really be 8 but the last char is always '=' so we can optimise it away.
#define INT64SIZE_B64 12 |
The length of a 32-bit integer as a base64 string.
Datum bitmap_bitmax | ( | FunctionCallInfo | fcinfo | ) |
bitmap_bitmax(bitmap bitmap) returns boolean
Return the highest bit set in the bitmap, or NULL if none are set. This relies on bitmap->bitmax always identifying the highest numbered bit in the bitset, unless the bitmap is empty.
fcinfo | Params as described_below bitmap bitmap The bitmap being examined. |
integer
The lowest bit set in the bitmap or NULL if there are no bits set. Datum bitmap_bitmin | ( | FunctionCallInfo | fcinfo | ) |
bitmap_bitmin(bitmap bitmap) returns boolean
Return the lowest bit set in the bitmap, or NULL if none are set. This relies on bitmap->bitmin always identifying the lowest numbered bit in the bitset, unless the bitmap is empty.
fcinfo | Params as described_below bitmap bitmap The bitmap being examined. |
integer
The lowest bit set in the bitmap or NULL if there are no bits set. Datum bitmap_bits | ( | FunctionCallInfo | fcinfo | ) |
bitmap_bits(name text)
returns setof int4 Return the set of all bits set in the specified Bitmap.
fcinfo | name text The name of the bitmap. |
setof int4
The set of bits that are set in the bitmap. Datum bitmap_clearbit | ( | FunctionCallInfo | fcinfo | ) |
bitmap_clearbit(bitmap bitmap, bit int4) returns bool
Clear the given bit in the bitmap, returning FALSE.
fcinfo | Params as described_below bitmap bitmap The bitmap to be manipulated. bitno int4 The bitnumber to be set. |
bool
TRUE Datum bitmap_cmp | ( | FunctionCallInfo | fcinfo | ) |
bitmap_cmp(bitmap1 bitmap, bitmap2 bitmap) returns bool
Return result of comparison of bitmap1's string representation with bitmap2's.
fcinfo | Params as described_below bitmap1 bitmap The first bitmap bitmap2 bitmap The second bitmap |
int4
result of comparison Datum bitmap_equal | ( | FunctionCallInfo | fcinfo | ) |
bitmap_equal(bitmap1 bitmap, bitmap2 bitmap) returns bool
Return true if the bitmaps are equivalent,
fcinfo | Params as described_below bitmap1 bitmap The first bitmap bitmap2 bitmap The second bitmap |
bool
true if the bitmaps contain the same bits. Datum bitmap_ge | ( | FunctionCallInfo | fcinfo | ) |
bitmap_ge(bitmap1 bitmap, bitmap2 bitmap) returns bool
Return true if bitmap1's string representation should be sorted later than, or the same as, bitmap2's.
fcinfo | Params as described_below bitmap1 bitmap The first bitmap bitmap2 bitmap The second bitmap |
bool
true unless the bitmaps contain the same bits. Datum bitmap_gt | ( | FunctionCallInfo | fcinfo | ) |
bitmap_gt(bitmap1 bitmap, bitmap2 bitmap) returns bool
Return true if bitmap1's string representation should be sorted later than bitmap2's.
fcinfo | Params as described_below bitmap1 bitmap The first bitmap bitmap2 bitmap The second bitmap |
bool
true unless the bitmaps contain the same bits. Datum bitmap_in | ( | FunctionCallInfo | fcinfo | ) |
Datum bitmap_intersection | ( | FunctionCallInfo | fcinfo | ) |
bitmap_intersection(bitmap1 bitmap, bitmap2 bitmap) returns bitmap
Return the intersection of 2 bitmaps. This can be used as an aggregate function in which case the bitmap1 parameter will be null for the first call. In this case simply return the second argument.
fcinfo | Params as described_below bitmap1 bitmap The first bitmap bitmap2 bitmap The second bitmap |
bitmap
the intersection of the two bitmaps. Datum bitmap_is_empty | ( | FunctionCallInfo | fcinfo | ) |
bitmap_is_empty(bitmap bitmap) returns boolean
Predicate to identify whether a bitmap is empty or not.
fcinfo | Params as described_below bitmap bitmap The bitmap being examined. bitmap value. |
boolean
true, if the bitmap has no bits. Datum bitmap_le | ( | FunctionCallInfo | fcinfo | ) |
bitmap_le(bitmap1 bitmap, bitmap2 bitmap) returns bool
Return true if bitmap1's string representation should be sorted earlier than, or the same as, bitmap2's.
fcinfo | Params as described_below bitmap1 bitmap The first bitmap bitmap2 bitmap The second bitmap |
bool
true unless the bitmaps contain the same bits. Datum bitmap_lt | ( | FunctionCallInfo | fcinfo | ) |
bitmap_lt(bitmap1 bitmap, bitmap2 bitmap) returns bool
Return true if bitmap1's string representation should be sorted earlier than bitmap2's.
fcinfo | Params as described_below bitmap1 bitmap The first bitmap bitmap2 bitmap The second bitmap |
bool
true unless the bitmaps contain the same bits. Datum bitmap_minus | ( | FunctionCallInfo | fcinfo | ) |
bitmap_minus(bitmap1 bitmap, bitmap2 bitmap) returns bitmap
Return the bitmap1 with all bits from bitmap2 subtracted (cleared) from it.
fcinfo | Params as described_below bitmap1 bitmap The first bitmap bitmap2 bitmap The second bitmap |
bitmap
the subtraction of the two bitmaps. Datum bitmap_nequal | ( | FunctionCallInfo | fcinfo | ) |
bitmap_nequal(bitmap1 bitmap, bitmap2 bitmap) returns bool
Return true if the bitmaps are not equivalent,
fcinfo | Params as described_below bitmap1 bitmap The first bitmap bitmap2 bitmap The second bitmap |
bool
true unless the bitmaps contain the same bits. Datum bitmap_new | ( | FunctionCallInfo | fcinfo | ) |
bitmap_new() returns bitmap;
Create or re-initialise a Bitmap, for dealing with a named range of values.
fcinfo | Params as described_below bitno int32 The first integer value to be recorded in the bitmap |
Bitmap
the newly allocated bitmap Datum bitmap_new_empty | ( | FunctionCallInfo | fcinfo | ) |
bitmap_new_empty() returns bitmap;
Create an empty Bitmap, for dealing with a named range of values.
fcinfo | Params as described_below |
Bitmap
the newly allocated bitmap Datum bitmap_out | ( | FunctionCallInfo | fcinfo | ) |
bitmap_out(bitmap bitmap) returns text
Create a (base64) text representation of a bitmap.
fcinfo | Params as described_below bitmap bitmap A base64 serialiastion of a bitmap value. |
cstring
the newly serialised text stream. Datum bitmap_setbit | ( | FunctionCallInfo | fcinfo | ) |
bitmap_setbit(bitmap bitmap, bit int4) returns bool
Set the given bit in the bitmap, returning TRUE. This can be used as an aggregate function in which case the bitmap parameter will be null for the first call. In this case simply create a bitmap from the second argument.
fcinfo | Params as described_below bitmap bitmap The bitmap to be manipulated. bitno int4 The bitnumber to be set. |
bitmap
The result. Datum bitmap_setmax | ( | FunctionCallInfo | fcinfo | ) |
bitmap_setmax(bitmap bitmap, bitmax int4) returns bitmap
Return a new bitmap having no bits greater than bitmax
fcinfo | Params as described_below bitmap bitmap The bitmap to be manipulated. bitmax int4 The new maximum bit. |
bitmap
The new bitmap. Datum bitmap_setmin | ( | FunctionCallInfo | fcinfo | ) |
bitmap_setmin(bitmap bitmap, bitmin int4) returns bitmap
Return a new bitmap having no bits less than bitmin
fcinfo | Params as described_below bitmap bitmap The bitmap to be manipulated. bitmin int4 The new minimum bit. |
bitmap
The new bitmap. Datum bitmap_testbit | ( | FunctionCallInfo | fcinfo | ) |
bitmap_testbit(bitmap bitmap, bit int4) returns bool
Test the given bit in the bitmap, returning TRUE if it is 1.
fcinfo | Params as described_below bitmap bitmap The bitmap to be manipulated. bitno int4 The bitnumber to be tested. |
bool
the truth value of the bit. Datum bitmap_union | ( | FunctionCallInfo | fcinfo | ) |
bitmap_union(bitmap1 bitmap, bitmap2 bitmap) returns bitmap
Return the union of 2 bitmaps. This can be used as an aggregate function in which case the bitmap1 parameter will be null for the first call. In this case simply return the second argument.
fcinfo | Params as described_below bitmap1 bitmap The first bitmap bitmap2 bitmap The second bitmap |
bitmap
the union of the two bitmaps. Create a copy of a bitmap.
bitmap | The original bitmap |
Predicate identifying whether the bitmap is empty. This takes a pretty simplistic view of what it means to be empty: any properly contructed non-empty bitmap will have bits set in at least the bitmin and bitmax positions,
bitmap | The Bitmap being scanned. |
|
static |
Return the next set bit in the Bitmap.
bitmap | The Bitmap being scanned. |
inbit | The starting bit from which to scan the bitmap |
found | Boolean that will be set to true when a set bit has been found. |
Ensure bitmax of bitmap is no more than parameter
bitmap | The Bitmap to be modified |
bitmax | The new minimum value |
Ensure bitmin of bitmap is no less than parameter. This provides the means to quickly truncate a bitmap.
bitmap | The Bitmap to be modified |
bitmin | The new minimum value |
bool bitmapTestbit | ( | Bitmap * | bitmap, |
int32 | bit | ||
) |
|
static |
|
static |
De-serialise a bitmap.
charstream | The serialised character string containing the bitmap. |
|
static |
De-serialise an int32 value from a base64 character stream.
p_stream | Pointer into the stream currently being read. must be large enought to take the contents to be written. This pointer is updated to point to the next free slot in the stream after reading the int32 value. |
|
static |
De-serialise a binary stream.
p_stream | Pointer into the stream currently being read. pointer is updated to point to the next free slot in the stream after reading the stream. |
bytes | The number of bytes to be read |
outstream | Pointer into the pre-allocated memory are into which the binary from p_stream is to be written. |
|
static |
|
static |
Take an existing bitmap, and return a larger copy that will be able to store a specified bit.
bitmap | The original bitmap |
bit | A new bit that the returned bitmap must be capable of storing. |
|
static |
Return a new, possibly uninitialised, Bitmap.
min | The lowest value bit to be stored in the bitmap |
max | The highest value bit to be stored in the bitmap |
|
static |
|
static |
Serialise a bitmap.
bitmap | The bitmap to be serialised. |
|
static |
Serialise an int32 value as a base64 stream (truncated to save a byte) into *p_stream.
p_stream | Pointer into stream currently being written. This must be large enought to take the contents to be written. This pointer is updated to point to the next free slot in the stream after writing the int32 value, and is null terminated at that position. |
value | The value to be written to the stream. |
|
static |
Serialise a binary stream as a base64 stream into *p_stream.
p_stream | Pointer into stream currently being written. This pointer is updated to point to the next free slot in the stream after writing the contents of instream and is null terminated at that position. |
bytes | The number of bytes to be written. |
instream | The binary stream to be written. |
|
static |
Return the length of a base64 encoded stream for a binary stream of ::bytes length.
bytes | The length of the input binary stream in bytes |
|
static |
|
static |
|
static |
Array of bit positions for int64, indexed by bitno.