Define bitmap datatypes.
More...
#include "postgres.h"
#include "funcapi.h"
Go to the source code of this file.
Define bitmap datatypes.
Author: Marc Munro
Copyright (c) 2020 Marc Munro
License: BSD
◆ ARRAYELEMS
#define ARRAYELEMS |
( |
|
min, |
|
|
|
max |
|
) |
| (((max - BITZERO(min)) >> 6) + 1) |
Gives the number of array elements in a Bitmap that runs from element min to element max.
- Parameters
-
- Returns
- The number of elements in the bitmap.
◆ BITMAP_DATATYPES
#define BITMAP_DATATYPES 1 |
Prevent this header from being included multiple times.
◆ BITSET_BIT
#define BITSET_BIT |
( |
|
x | ) |
(x & 0x3f) |
Gives the index into bitmasks for the bit specified in x.
- Parameters
-
- Returns
- The bitmask index
◆ BITSET_ELEM
#define BITSET_ELEM |
( |
|
x | ) |
((x) >> 6) |
Gives the index of the word for a given bit, assuming bitmin is zero.
- Parameters
-
- Returns
- The array index of the bit.
◆ BITZERO
#define BITZERO |
( |
|
x | ) |
((x) & 0xffffffffffffffc0) |
Gives the bitmask index for the bitzero value of a Bitmap. This is part of the "normalisation" process for bitmap ranges. This process allows unlike bitmaps to be more easily compared by forcing bitmap indexes to be normalised around 32 or 64 bit word boundaries.
- Parameters
-
x | The bitzero value of a bitmap |
- Returns
- The bitmask index representing x.
◆ DatumGetBitmap
#define DatumGetBitmap |
( |
|
x | ) |
((Bitmap *) PG_DETOAST_DATUM(DatumGetPointer(x))) |
Provide a macro for getting a bitmap datum.
◆ ELEMBITS
◆ MAX
#define MAX |
( |
|
a, |
|
|
|
b |
|
) |
| ((a > b)? a: b) |
Return the larger of a or b. Note that expressions a and b may be evaluated more than once.
- Parameters
-
- Returns
- The smaller value of a or b.
◆ MIN
#define MIN |
( |
|
a, |
|
|
|
b |
|
) |
| ((a < b)? a: b) |
Return the smaller of a or b. Note that expressions a and b may be evaluated more than once.
- Parameters
-
- Returns
- The smaller value of a or b.
◆ PG_GETARG_BITMAP
#define PG_GETARG_BITMAP |
( |
|
x | ) |
|
Value: PG_DETOAST_DATUM(PG_GETARG_DATUM(x)))
#define DatumGetBitmap(x)
Definition: pgbitmap.h:193
Provide a macro for dealing with bitmap arguments.
◆ PG_RETURN_BITMAP
#define PG_RETURN_BITMAP |
( |
|
x | ) |
PG_RETURN_POINTER(x) |
Provide a macro for returning bitmap results.
◆ USE_64_BIT
Use 64-bit word definitions throughout.
◆ Bitmap
A bitmap is stored as an array of integer values. Note that the size of a Bitmap structure is determined dynamically at run time as the size of the array is only known then.
◆ bm_int
bm_int is the bitmap integer type (a 64-bit value).
◆ boolean
Defines a boolean type to make our code more readable.
◆ bitmap_bitmax()
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.
- Parameters
-
fcinfo | Params as described_below
bitmap bitmap The bitmap being examined. |
- Returns
integer
The lowest bit set in the bitmap or NULL if there are no bits set.
◆ bitmap_bitmin()
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.
- Parameters
-
fcinfo | Params as described_below
bitmap bitmap The bitmap being examined. |
- Returns
integer
The lowest bit set in the bitmap or NULL if there are no bits set.
◆ bitmap_bits()
Datum bitmap_bits |
( |
FunctionCallInfo |
fcinfo | ) |
|
bitmap_bits(name text)
returns setof int4 Return the set of all bits set in the specified Bitmap.
- Parameters
-
fcinfo | name text The name of the bitmap. |
- Returns
setof int4
The set of bits that are set in the bitmap.
◆ bitmap_clearbit()
Datum bitmap_clearbit |
( |
FunctionCallInfo |
fcinfo | ) |
|
bitmap_clearbit(bitmap bitmap, bit int4) returns bool
Clear the given bit in the bitmap, returning FALSE.
- Parameters
-
fcinfo | Params as described_below
bitmap bitmap The bitmap to be manipulated.
bitno int4 The bitnumber to be set. |
- Returns
bool
TRUE
◆ bitmap_cmp()
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.
- Parameters
-
fcinfo | Params as described_below
bitmap1 bitmap The first bitmap
bitmap2 bitmap The second bitmap |
- Returns
int4
result of comparison
◆ bitmap_equal()
Datum bitmap_equal |
( |
FunctionCallInfo |
fcinfo | ) |
|
bitmap_equal(bitmap1 bitmap, bitmap2 bitmap) returns bool
Return true if the bitmaps are equivalent,
- Parameters
-
fcinfo | Params as described_below
bitmap1 bitmap The first bitmap
bitmap2 bitmap The second bitmap |
- Returns
bool
true if the bitmaps contain the same bits.
◆ bitmap_ge()
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.
- Parameters
-
fcinfo | Params as described_below
bitmap1 bitmap The first bitmap
bitmap2 bitmap The second bitmap |
- Returns
bool
true unless the bitmaps contain the same bits.
◆ bitmap_gt()
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.
- Parameters
-
fcinfo | Params as described_below
bitmap1 bitmap The first bitmap
bitmap2 bitmap The second bitmap |
- Returns
bool
true unless the bitmaps contain the same bits.
◆ bitmap_in()
Datum bitmap_in |
( |
FunctionCallInfo |
fcinfo | ) |
|
bitmap_in(serialised_bitmap text) returns bitmap
Create a Bitmap initialised from a (base64) text value.
- Parameters
-
fcinfo | Params as described_below
serialised_bitmap text A base64 serialiastion of a bitmap value. |
- Returns
Bitmap
the newly created bitmap
◆ bitmap_intersection()
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.
- Parameters
-
fcinfo | Params as described_below
bitmap1 bitmap The first bitmap
bitmap2 bitmap The second bitmap |
- Returns
bitmap
the intersection of the two bitmaps.
◆ bitmap_is_empty()
Datum bitmap_is_empty |
( |
FunctionCallInfo |
fcinfo | ) |
|
bitmap_is_empty(bitmap bitmap) returns boolean
Predicate to identify whether a bitmap is empty or not.
- Parameters
-
fcinfo | Params as described_below
bitmap bitmap The bitmap being examined. bitmap value. |
- Returns
boolean
true, if the bitmap has no bits.
◆ bitmap_le()
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.
- Parameters
-
fcinfo | Params as described_below
bitmap1 bitmap The first bitmap
bitmap2 bitmap The second bitmap |
- Returns
bool
true unless the bitmaps contain the same bits.
◆ bitmap_lt()
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.
- Parameters
-
fcinfo | Params as described_below
bitmap1 bitmap The first bitmap
bitmap2 bitmap The second bitmap |
- Returns
bool
true unless the bitmaps contain the same bits.
◆ bitmap_minus()
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.
- Parameters
-
fcinfo | Params as described_below
bitmap1 bitmap The first bitmap
bitmap2 bitmap The second bitmap |
- Returns
bitmap
the subtraction of the two bitmaps.
◆ bitmap_nequal()
Datum bitmap_nequal |
( |
FunctionCallInfo |
fcinfo | ) |
|
bitmap_nequal(bitmap1 bitmap, bitmap2 bitmap) returns bool
Return true if the bitmaps are not equivalent,
- Parameters
-
fcinfo | Params as described_below
bitmap1 bitmap The first bitmap
bitmap2 bitmap The second bitmap |
- Returns
bool
true unless the bitmaps contain the same bits.
◆ bitmap_new()
Datum bitmap_new |
( |
FunctionCallInfo |
fcinfo | ) |
|
bitmap_new() returns bitmap;
Create or re-initialise a Bitmap, for dealing with a named range of values.
- Parameters
-
fcinfo | Params as described_below
bitno int32 The first integer value to be recorded in the bitmap |
- Returns
Bitmap
the newly allocated bitmap
◆ bitmap_new_empty()
Datum bitmap_new_empty |
( |
FunctionCallInfo |
fcinfo | ) |
|
bitmap_new_empty() returns bitmap;
Create an empty Bitmap, for dealing with a named range of values.
- Parameters
-
fcinfo | Params as described_below |
- Returns
Bitmap
the newly allocated bitmap
◆ bitmap_out()
Datum bitmap_out |
( |
FunctionCallInfo |
fcinfo | ) |
|
bitmap_out(bitmap bitmap) returns text
Create a (base64) text representation of a bitmap.
- Parameters
-
fcinfo | Params as described_below
bitmap bitmap A base64 serialiastion of a bitmap value. |
- Returns
cstring
the newly serialised text stream.
◆ bitmap_setbit()
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.
- Parameters
-
fcinfo | Params as described_below
bitmap bitmap The bitmap to be manipulated.
bitno int4 The bitnumber to be set. |
- Returns
bitmap
The result.
◆ bitmap_setmax()
Datum bitmap_setmax |
( |
FunctionCallInfo |
fcinfo | ) |
|
bitmap_setmax(bitmap bitmap, bitmax int4) returns bitmap
Return a new bitmap having no bits greater than bitmax
- Parameters
-
fcinfo | Params as described_below
bitmap bitmap The bitmap to be manipulated.
bitmax int4 The new maximum bit. |
- Returns
bitmap
The new bitmap.
◆ bitmap_setmin()
Datum bitmap_setmin |
( |
FunctionCallInfo |
fcinfo | ) |
|
bitmap_setmin(bitmap bitmap, bitmin int4) returns bitmap
Return a new bitmap having no bits less than bitmin
- Parameters
-
fcinfo | Params as described_below
bitmap bitmap The bitmap to be manipulated.
bitmin int4 The new minimum bit. |
- Returns
bitmap
The new bitmap.
◆ bitmap_testbit()
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.
- Parameters
-
fcinfo | Params as described_below
bitmap bitmap The bitmap to be manipulated.
bitno int4 The bitnumber to be tested. |
- Returns
bool
the truth value of the bit.
◆ bitmap_union()
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.
- Parameters
-
fcinfo | Params as described_below
bitmap1 bitmap The first bitmap
bitmap2 bitmap The second bitmap |
- Returns
bitmap
the union of the two bitmaps.
◆ bitmapCopy()
Create a copy of a bitmap.
- Parameters
-
bitmap | The original bitmap |
- Returns
- Copy of bitmap.
◆ bitmapTestbit()
bool bitmapTestbit |
( |
Bitmap * |
bitmap, |
|
|
int32 |
bit |
|
) |
| |
Test a bit within a Bitmap. If the bit is outside of the acceptable range return false.
- Parameters
-
bitmap | The Bitmap within which the bit is to be set. |
bit | The bit to be tested. |
- Returns
- True if the bit is set, false otherwise.