26 0x00000001, 0x00000002, 0x00000004, 0x00000008,
27 0x00000010, 0x00000020, 0x00000040, 0x00000080,
28 0x00000100, 0x00000200, 0x00000400, 0x00000800,
29 0x00001000, 0x00002000, 0x00004000, 0x00008000,
30 0x00010000, 0x00020000, 0x00040000, 0x00080000,
31 0x00100000, 0x00200000, 0x00400000, 0x00800000,
32 0x01000000, 0x02000000, 0x04000000, 0x08000000,
33 0x10000000, 0x20000000, 0x40000000, 0x80000000,
34 0x0000000100000000, 0x0000000200000000,
35 0x0000000400000000, 0x0000000800000000,
36 0x0000001000000000, 0x0000002000000000,
37 0x0000004000000000, 0x0000008000000000,
38 0x0000010000000000, 0x0000020000000000,
39 0x0000040000000000, 0x0000080000000000,
40 0x0000100000000000, 0x0000200000000000,
41 0x0000400000000000, 0x0000800000000000,
42 0x0001000000000000, 0x0002000000000000,
43 0x0004000000000000, 0x0008000000000000,
44 0x0010000000000000, 0x0020000000000000,
45 0x0040000000000000, 0x0080000000000000,
46 0x0100000000000000, 0x0200000000000000,
47 0x0400000000000000, 0x0800000000000000,
48 0x1000000000000000, 0x2000000000000000,
49 0x4000000000000000, 0x8000000000000000};
56 uint32
bitmasks[] = {0x00000001, 0x00000002, 0x00000004, 0x00000008,
57 0x00000010, 0x00000020, 0x00000040, 0x00000080,
58 0x00000100, 0x00000200, 0x00000400, 0x00000800,
59 0x00001000, 0x00002000, 0x00004000, 0x00008000,
60 0x00010000, 0x00020000, 0x00040000, 0x00080000,
61 0x00100000, 0x00200000, 0x00400000, 0x00800000,
62 0x01000000, 0x02000000, 0x04000000, 0x08000000,
63 0x10000000, 0x20000000, 0x40000000, 0x80000000};
78 for (i = 0; i < elems; i++) {
98 Bitmap *bitmap = *p_bitmap;
107 if (elems <= cur_elems) {
133 bitmap->
type = OBJ_BITMAP;
157 if ((bit > bitmap->
bitmax) ||
158 (bit < bitmap->bitzero))
161 (errcode(ERRCODE_INTERNAL_ERROR),
162 errmsg(
"Bitmap range error"),
163 errdetail(
"Bit (%d) not in range %d..%d. ", bit,
187 if ((bit > bitmap->
bitmax) ||
188 (bit < bitmap->bitzero))
191 (errcode(ERRCODE_INTERNAL_ERROR),
192 errmsg(
"Bitmap range error"),
193 errdetail(
"Bit (%d) not in range %d..%d. ", bit,
216 if ((bit > bitmap->
bitmax) ||
217 (bit < bitmap->bitzero))
243 (errcode(ERRCODE_INTERNAL_ERROR),
244 errmsg(
"Incompatible bitmaps"),
245 errdetail(
"Target range is %d..%d. Source range %d..%d.",
249 for (i = 0; i < elems; i++) {
273 (errcode(ERRCODE_INTERNAL_ERROR),
274 errmsg(
"Incompatible bitmaps"),
275 errdetail(
"Target range is %d..%d. Source range %d..%d.",
279 for (i = 0; i < elems; i++) {
299 while (bit <= bitmap->bitmax) {
326 if ((elem < bmarray->arrayzero) || (elem > bmarray->
arraymax)) {
348 for (i = 0; i < bitmaps; i++) {
369 int32 arrayzero, int32 arraymax,
370 int32 bitzero, int32 bitmax)
373 int bitsetelems =
ARRAYELEMS(bitzero, bitmax);
374 int bitmaps = arraymax + 1 - arrayzero;
384 if ((cur_elems >= bitsetelems) && (cur_maps >= bitmaps)) {
389 for (i = 0; i < cur_maps; i++) {
395 for (i = 0; i < cur_maps; i++) {
396 pfree(bmarray->
bitmap[i]);
407 (
sizeof(
Bitmap *) * bitmaps));
412 (
sizeof(
Bitmap *) * bitmaps));
415 for (i = 0; i < bitmaps; i++) {
416 bmarray->
bitmap[i] = NULL;
420 bmarray->
type = OBJ_BITMAP_ARRAY;
430 for (i = 0; i < bitmaps; i++) {
436 *p_bmarray = bmarray;
455 (void) snprintf(vl_name,
HASH_KEYLEN - 1,
"vl_%s", name);
458 hashctl.entrysize =
sizeof(
VarEntry);
460 hash = hash_create(vl_name, 200, &hashctl, HASH_ELEM);
478 static HASH_SEQ_STATUS status;
482 hash_seq_init(&status, hash);
484 next = (
VarEntry *) hash_seq_search(&status);
500 int32 bitzero, int32 bitmax)
506 HTAB *hash = bmhash->
hash;
511 if (entry->
obj->
type != OBJ_BITMAP) {
513 (errcode(ERRCODE_INTERNAL_ERROR),
514 errmsg(
"Bitmap hash contains invalid object %d",
516 errdetail(
"Object type is %d, expected is %d.",
517 entry->
obj->
type, OBJ_BITMAP)));
522 (void) hash_search(hash, entry->
key, HASH_REMOVE, &found);
527 bmhash->
type = OBJ_BITMAP_HASH;
555 var = hash_search(bmhash->
hash, hashelem, HASH_FIND, &found);
562 (errcode(ERRCODE_INTERNAL_ERROR),
563 errmsg(
"BitmapFromHash - empty VarEntry")));
566 if (var->
obj->
type != OBJ_BITMAP) {
568 (errcode(ERRCODE_INTERNAL_ERROR),
569 errmsg(
"Bitmap hash contains invalid object %d",
571 errdetail(
"Object type is %d, expected is %d.",
595 var = hash_search(bmhash->
hash, hashelem, HASH_ENTER, &found);
599 (errcode(ERRCODE_INTERNAL_ERROR),
600 errmsg(
"AddBitmapToHash - empty VarEntry")));
602 if (var->
obj->
type != OBJ_BITMAP) {
604 (errcode(ERRCODE_INTERNAL_ERROR),
605 errmsg(
"AddBitmapToHash - type mismatch %d",
607 errdetail(
"Object type is %d, expected is %d.",
634 (void) hash_search(bmhash->
hash, hashelem, HASH_FIND, &found);
#define BITSET_BIT(x)
Gives the index into bitmasks for the bit specified in x.
static uint32 bitmasks[]
Array of bit positions for int32, indexed by bitno.
Subtype of Object for storing bitmaps.
void vl_BitmapIntersect(Bitmap *target, Bitmap *source)
Create the intersection of two bitmaps, updating the first with the result.
void vl_NewBitmap(Bitmap **p_bitmap, bool shared, int32 min, int32 max)
Return a newly initialised (empty) Bitmap.
int32 bitzero
The index of the lowest bit each bitmap can store.
int32 bitmax
The index of the highest bit each bitmap can store.
ObjType type
This must have the value OBJ_BITMAP.
void vl_BitmapUnion(Bitmap *target, Bitmap *source)
Create the union of two bitmaps, updating the first with the result.
#define DBG_SET_ELEMS(x, y)
Code to records the size of an array so that its canary element can be found.
ObjType type
This must have the value OBJ_BITMAP_ARRAY.
int32 vl_BitmapNextBit(Bitmap *bitmap, int32 bit, bool *found)
Return the next set bit in the Bitmap.
bool vl_BitmapTestbit(Bitmap *bitmap, int32 bit)
Test a bit within a Bitmap.
void vl_ClearBitmap(Bitmap *bitmap)
Clear all bits in a Bitmap.
int32 bitmax
The index of the highest bit the bitmap can store.
#define ARRAYELEMS(min, max)
Gives the number of array elements in a Bitmap that runs from element min to element max...
#define HASH_KEYLEN
The key length for veil hash types.
#define BITSET_ELEM(x)
Gives the index of a bit within the array of 32-bit words that comprise the bitmap.
Bitmap * vl_BitmapFromArray(BitmapArray *bmarray, int32 elem)
Return a specified Bitmap from a BitmapArray.
#define DBG_TEST_CANARY(x)
Code to test for a canary having been overwritten.
void vl_NewBitmapHash(BitmapHash **p_bmhash, char *name, int32 bitzero, int32 bitmax)
Return a newly initialised (empty) BitmapHash.
int32 arraymax
The index of the lowest numbered bitmap in the array.
void vl_free(void *mem)
Free a piece of shared memory within the current context.
#define DBG_SET_TRAILERP(x, y)
Set a trailing canary in an array (using a void pointer).
void vl_BitmapSetbit(Bitmap *bitmap, int32 bit)
Set a bit within a Bitmap.
Provide definitions for all non-local C-callable Veil functions.
General purpose object-type.
int32 bitzero
The index of the lowest bit the bitmap can store.
Subtype of Object for storing bitmap hashes.
static HTAB * new_hash(char *name)
Create a new hash table.
#define DBG_TEST_TRAILER(x, y)
Test the trailing canary in an array.
Bitmap * vl_BitmapFromHash(BitmapHash *bmhash, char *hashelem)
Return a specified Bitmap from a BitmapHash.
HTAB * hash
Pointer to the (Postgresql dynahash) hash table.
bm_int bitset[1]
Element zero of the array of int4 values comprising the bitmap.
Bitmap * vl_AddBitmapToHash(BitmapHash *bmhash, char *hashelem)
Create a newly allocated empty Bitmap to a BitmapHash.
VarEntry * vl_NextHashEntry(HTAB *hash, VarEntry *prev)
Utility function for scanning the hash table of a BitmapHash.
int32 arrayzero
The index of array element zero: the index of the lowest numbered bitmap in the array.
#define BITZERO(x)
Gives the bitmask index for the bitzero value of a Bitmap.
void vl_ClearBitmapArray(BitmapArray *bmarray)
Clear all bitmaps in the given BitmapArray.
void * vl_shmalloc(size_t size)
Dynamically allocate a piece of shared memory from the current context.
void vl_NewBitmapArray(BitmapArray **p_bmarray, bool shared, int32 arrayzero, int32 arraymax, int32 bitzero, int32 bitmax)
Return a newly initialised (empty) BitmapArray.
#define DBG_SET_CANARY(x)
Code to initialise a canary.
int32 bitzero
The index of the lowest bit each bitmap can store.
void * vl_malloc(size_t size)
Dynamically allocate memory using palloc in TopMemoryContext.
ObjType type
Identifies the type of the object.
int32 bitmax
The index of the highest bit each bitmap can store.
ObjType type
This must have the value OBJ_BITMAP_HASH.
Object * obj
Pointer to the contents of the variable.
#define DBG_SET_TRAILER(x, y)
Set a trailing canary in an array.
Subtype of Object for storing bitmap arrays.
Bitmap * bitmap[1]
Element zero of the array of Bitmap pointers comprising the array.
struct VarEntry VarEntry
A Veil variable.
#define DBG_CHECK_INDEX(x, i)
Check whether an array index is in bounds.
bool vl_BitmapHashHasKey(BitmapHash *bmhash, char *hashelem)
Determine whether the supplied key exists in the BitmapHash.
char key[60]
String containing variable name.
void vl_BitmapClearbit(Bitmap *bitmap, int32 bit)
Clear a bit within a Bitmap.
Define all Veil public datatypes.