Veil
veil_bitmap.c
Go to the documentation of this file.
1 /**
2  * @file veil_bitmap.c
3  * \code
4  * Author: Marc Munro
5  * Copyright (c) 2005 - 2011 Marc Munro
6  * License: BSD
7  *
8  * \endcode
9  * @brief
10  * Functions for manipulating Bitmaps, BitmapHashes and BitmapArrays
11  *
12  */
13 
14 #include <stdio.h>
15 #include "postgres.h"
16 #include "veil_datatypes.h"
17 #include "veil_funcs.h"
18 
19 
20 #ifdef USE_64_BIT
21 /**
22  * Array of bit positions for int64, indexed by bitno.
23  */
24 static
25 uint64 bitmasks[64] = {
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};
50 
51 #else
52 /**
53  * Array of bit positions for int32, indexed by bitno.
54  */
55 static
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};
64 
65 #endif
66 
67 /**
68  * Clear all bits in a ::Bitmap.
69  *
70  * @param bitmap The ::Bitmap in which all bits are to be cleared
71  */
72 void
74 {
75  int elems = ARRAYELEMS(bitmap->bitzero, bitmap->bitmax);
76  int i;
77 
78  for (i = 0; i < elems; i++) {
79  bitmap->bitset[i] = 0;
80  }
81 }
82 
83 /**
84  * Return a newly initialised (empty) ::Bitmap. The bitmap may already
85  * exist in which case it will be re-used if possible. The bitmap may
86  * be created in either session or shared memory depending on the value
87  * of shared.
88  *
89  * @param p_bitmap Pointer to an existing bitmap if one exists
90  * @param shared Whether to create the bitmap in shared memory
91  * @param min The smallest bit to be stored in the bitmap
92  * @param max The largest bit to be stored in the bitmap
93  */
94 void
95 vl_NewBitmap(Bitmap **p_bitmap, bool shared,
96  int32 min, int32 max)
97 {
98  Bitmap *bitmap = *p_bitmap;
99  int elems = ARRAYELEMS(min, max);
100 
101  if (bitmap) {
102  int cur_elems = ARRAYELEMS(bitmap->bitzero, bitmap->bitmax);
103  /* OK, there is an old bitmap in place. If it is the same size
104  * or larger than we need we will re-use it, otherwise we will
105  * dispose of it and get a new one. */
106 
107  if (elems <= cur_elems) {
108  vl_ClearBitmap(bitmap);
109  }
110  else {
111  if (shared) {
112  vl_free(bitmap);
113  }
114  else {
115  pfree(bitmap);
116  }
117  bitmap = NULL;
118  }
119  }
120  if (!bitmap) {
121  /* We need a new bitmap */
122  if (shared) {
123  bitmap = vl_shmalloc(sizeof(Bitmap) + (sizeof(bm_int) * elems));
124  }
125  else {
126  bitmap = vl_malloc(sizeof(Bitmap) + (sizeof(bm_int) * elems));
127  }
128  }
129 
130  DBG_SET_CANARY(*bitmap);
131  DBG_SET_ELEMS(*bitmap, elems);
132  DBG_SET_TRAILER(*bitmap, bitset);
133  bitmap->type = OBJ_BITMAP;
134  bitmap->bitzero = min;
135  bitmap->bitmax = max;
136  vl_ClearBitmap(bitmap);
137 
138  DBG_TEST_CANARY(*bitmap);
139  DBG_TEST_TRAILER(*bitmap, bitset);
140  *p_bitmap = bitmap;
141 }
142 
143 /**
144  * Set a bit within a ::Bitmap. If the bit is outside of the acceptable
145  * range, raise an error.
146  *
147  * @param bitmap The ::Bitmap within which the bit is to be set.
148  * @param bit The bit to be set.
149  */
150 void
152  int32 bit)
153 {
154  int relative_bit = bit - BITZERO(bitmap->bitzero);
155  int element = BITSET_ELEM(relative_bit);
156 
157  if ((bit > bitmap->bitmax) ||
158  (bit < bitmap->bitzero))
159  {
160  ereport(ERROR,
161  (errcode(ERRCODE_INTERNAL_ERROR),
162  errmsg("Bitmap range error"),
163  errdetail("Bit (%d) not in range %d..%d. ", bit,
164  bitmap->bitzero, bitmap->bitmax)));
165  }
166 
167  DBG_CHECK_INDEX(*bitmap, element);
168  bitmap->bitset[element] |= bitmasks[BITSET_BIT(relative_bit)];
169  DBG_TEST_CANARY(*bitmap);
170  DBG_TEST_TRAILER(*bitmap, bitset);
171 }
172 
173 /**
174  * Clear a bit within a ::Bitmap. If the bit is outside of the acceptable
175  * range, raise an error.
176  *
177  * @param bitmap The ::Bitmap within which the bit is to be cleared.
178  * @param bit The bit to be cleared.
179  */
180 void
182  int32 bit)
183 {
184  int relative_bit = bit - BITZERO(bitmap->bitzero);
185  int element = BITSET_ELEM(relative_bit);
186 
187  if ((bit > bitmap->bitmax) ||
188  (bit < bitmap->bitzero))
189  {
190  ereport(ERROR,
191  (errcode(ERRCODE_INTERNAL_ERROR),
192  errmsg("Bitmap range error"),
193  errdetail("Bit (%d) not in range %d..%d. ", bit,
194  bitmap->bitzero, bitmap->bitmax)));
195  }
196 
197  bitmap->bitset[element] &= ~(bitmasks[BITSET_BIT(relative_bit)]);
198 }
199 
200 /**
201  * Test a bit within a ::Bitmap. If the bit is outside of the acceptable
202  * range return false.
203  *
204  * @param bitmap The ::Bitmap within which the bit is to be set.
205  * @param bit The bit to be tested.
206  *
207  * @return True if the bit is set, false otherwise.
208  */
209 bool
211  int32 bit)
212 {
213  int relative_bit = bit - BITZERO(bitmap->bitzero);
214  int element = BITSET_ELEM(relative_bit);
215 
216  if ((bit > bitmap->bitmax) ||
217  (bit < bitmap->bitzero))
218  {
219  return false;
220  }
221 
222  return (bitmap->bitset[element] & bitmasks[BITSET_BIT(relative_bit)]) != 0;
223 }
224 
225 /**
226  * Create the union of two bitmaps, updating the first with the result.
227  *
228  * @param target The ::Bitmap into which the result will be placed.
229  * @param source The ::Bitmap to be unioned into target.
230  */
231 void
233  Bitmap *source)
234 {
235  int i;
236  int elems = ARRAYELEMS(target->bitzero, target->bitmax);
237 
238  /* TODO: Make this tolerant of range mismatches. */
239  if ((target->bitzero != source->bitzero) ||
240  (target->bitmax != source->bitmax))
241  {
242  ereport(ERROR,
243  (errcode(ERRCODE_INTERNAL_ERROR),
244  errmsg("Incompatible bitmaps"),
245  errdetail("Target range is %d..%d. Source range %d..%d.",
246  target->bitzero, target->bitmax,
247  source->bitzero, source->bitmax)));
248  }
249  for (i = 0; i < elems; i++) {
250  target->bitset[i] |= source->bitset[i];
251  }
252 }
253 
254 /**
255  * Create the intersection of two bitmaps, updating the first with the
256  * result.
257  *
258  * @param target The ::Bitmap into which the result will be placed.
259  * @param source The ::Bitmap to be intersected into target.
260  */
261 void
263  Bitmap *source)
264 {
265  int i;
266  int elems = ARRAYELEMS(target->bitzero, target->bitmax);
267 
268  /* TODO: Make this tolerant of range mismatches. */
269  if ((target->bitzero != source->bitzero) ||
270  (target->bitmax != source->bitmax))
271  {
272  ereport(ERROR,
273  (errcode(ERRCODE_INTERNAL_ERROR),
274  errmsg("Incompatible bitmaps"),
275  errdetail("Target range is %d..%d. Source range %d..%d.",
276  target->bitzero, target->bitmax,
277  source->bitzero, source->bitmax)));
278  }
279  for (i = 0; i < elems; i++) {
280  target->bitset[i] &= source->bitset[i];
281  }
282 }
283 
284 /**
285  * Return the next set bit in the ::Bitmap.
286  *
287  * @param bitmap The ::Bitmap being scanned.
288  * @param bit The starting bit from which to scan the bitmap
289  * @param found Boolean that will be set to true when a set bit has been
290  * found.
291  *
292  * @return The bit id of the found bit, or zero if no set bits were found.
293  */
294 int32
296  int32 bit,
297  bool *found)
298 {
299  while (bit <= bitmap->bitmax) {
300  if (vl_BitmapTestbit(bitmap, bit)) {
301  *found = true;
302  return bit;
303  }
304  bit++;
305  }
306  *found = false;
307  return 0;
308 }
309 
310 /**
311  * Return a specified ::Bitmap from a ::BitmapArray.
312  *
313  * @param bmarray The ::BitmapArray from which the result is to be
314  * returned.
315  * @param elem The index of the ::Bitmap within the array.
316  *
317  * @return The bitmap corresponding to the parameters, or NULL if no
318  *such entry exists within the array.
319  */
320 Bitmap *
322  int32 elem)
323 {
324  DBG_TEST_CANARY(*bmarray);
325  DBG_TEST_TRAILER(*bmarray, bitmap);
326  if ((elem < bmarray->arrayzero) || (elem > bmarray->arraymax)) {
327  return NULL;
328  }
329  else {
330  DBG_CHECK_INDEX(*bmarray, elem - bmarray->arrayzero);
331  return bmarray->bitmap[elem - bmarray->arrayzero];
332  }
333 }
334 
335 /**
336  * Clear all bitmaps in the given ::BitmapArray
337  *
338  * @param bmarray The ::BitmapArray to be cleared
339  */
340 void
342 {
343  int bitmaps = bmarray->arraymax + 1 - bmarray->arrayzero;
344  int i;
345 
346  DBG_TEST_CANARY(*bmarray);
347  DBG_TEST_TRAILER(*bmarray, bitmap);
348  for (i = 0; i < bitmaps; i++) {
349  DBG_CHECK_INDEX(*bmarray, i);
350  vl_ClearBitmap(bmarray->bitmap[i]);
351  }
352 }
353 
354 /**
355  * Return a newly initialised (empty) ::BitmapArray. It may already
356  * exist in which case it will be re-used if possible. It may
357  * be created in either session or shared memory depending on the value
358  * of shared.
359  *
360  * @param p_bmarray Pointer to an existing bitmap if one exists.
361  * @param shared Whether to create the bitmap in shared memory
362  * @param arrayzero The lowest array index
363  * @param arraymax The highest array index
364  * @param bitzero The smallest bit to be stored in the bitmap
365  * @param bitmax The largest bit to be stored in the bitmap
366  */
367 void
368 vl_NewBitmapArray(BitmapArray **p_bmarray, bool shared,
369  int32 arrayzero, int32 arraymax,
370  int32 bitzero, int32 bitmax)
371 {
372  BitmapArray *bmarray = *p_bmarray;
373  int bitsetelems = ARRAYELEMS(bitzero, bitmax);
374  int bitmaps = arraymax + 1 - arrayzero;
375  int i;
376 
377  if (bmarray) {
378  /* We already have a bitmap array. If possible, we re-use it. */
379  int cur_elems = ARRAYELEMS(bmarray->bitzero, bmarray->bitmax);
380  int cur_maps = bmarray->arraymax + 1 - bmarray->arrayzero;
381 
382  DBG_TEST_CANARY(*bmarray);
383  DBG_TEST_TRAILER(*bmarray, bitmap);
384  if ((cur_elems >= bitsetelems) && (cur_maps >= bitmaps)) {
385  vl_ClearBitmapArray(bmarray);
386  }
387  else {
388  if (shared) {
389  for (i = 0; i < cur_maps; i++) {
390  vl_free(bmarray->bitmap[i]);
391  }
392  vl_free(bmarray);
393  }
394  else {
395  for (i = 0; i < cur_maps; i++) {
396  pfree(bmarray->bitmap[i]);
397  }
398  pfree(bmarray);
399  }
400  bmarray = NULL;
401  }
402  }
403 
404  if (!bmarray) {
405  if (shared) {
406  bmarray = vl_shmalloc(sizeof(BitmapArray) +
407  (sizeof(Bitmap *) * bitmaps));
408 
409  }
410  else {
411  bmarray = vl_malloc(sizeof(BitmapArray) +
412  (sizeof(Bitmap *) * bitmaps));
413  }
414 
415  for (i = 0; i < bitmaps; i++) {
416  bmarray->bitmap[i] = NULL;
417  vl_NewBitmap(&(bmarray->bitmap[i]), shared, bitzero, bitmax);
418  }
419 
420  bmarray->type = OBJ_BITMAP_ARRAY;
421  DBG_SET_CANARY(*bmarray);
422  DBG_SET_ELEMS(*bmarray, bitmaps);
423  DBG_SET_TRAILERP(*bmarray, bitmap);
424  }
425  bmarray->bitzero = bitzero;
426  bmarray->bitmax = bitmax;
427  bmarray->arrayzero = arrayzero;
428  bmarray->arraymax = arraymax;
429 
430  for (i = 0; i < bitmaps; i++) {
431  bmarray->bitmap[i]->type = OBJ_BITMAP;
432  bmarray->bitmap[i]->bitzero = bitzero;
433  bmarray->bitmap[i]->bitmax = bitmax;
434  }
435 
436  *p_bmarray = bmarray;
437 }
438 
439 /**
440  * Create a new hash table. This is allocated from session memory as
441  * BitmapHashes may not be declared as shared variables.
442  *
443  * @param name The name of the hash to be created. Note that we prefix
444  * this with "vl_" to prevent name collisions from other subsystems.
445  *
446  * @return Pointer to the newly created hash table.
447  */
448 static HTAB *
449 new_hash(char *name)
450 {
451  char vl_name[HASH_KEYLEN];
452  HTAB *hash;
453  HASHCTL hashctl;
454 
455  (void) snprintf(vl_name, HASH_KEYLEN - 1, "vl_%s", name);
456 
457  hashctl.keysize = HASH_KEYLEN;
458  hashctl.entrysize = sizeof(VarEntry);
459 
460  hash = hash_create(vl_name, 200, &hashctl, HASH_ELEM);
461  return hash;
462 }
463 
464 /**
465  * Utility function for scanning the hash table of a BitmapHash.
466  *
467  * @param hash The hash table being scanned
468  * @param prev The entry from which to scan, starting with NULL.
469  *
470  * @return The next element in the hash table (a VarEntry) or NULL when
471  * the last element has already been scanned.
472  */
473 VarEntry *
474 vl_NextHashEntry(HTAB *hash,
475  VarEntry *prev)
476 {
477  VarEntry *next;
478  static HASH_SEQ_STATUS status;
479  if (!prev) {
480  /* Initialise the hash search */
481 
482  hash_seq_init(&status, hash);
483  }
484  next = (VarEntry *) hash_seq_search(&status);
485  return (next);
486 }
487 
488 /**
489  * Return a newly initialised (empty) ::BitmapHash. It may already
490  * exist in which case it will be re-used if possible. BitmapHash
491  * variables may only be created as session (not shared) variables.
492  *
493  * @param p_bmhash Pointer to an existing bitmap if one exists.
494  * @param name The name to be used for the hash table
495  * @param bitzero The smallest bit to be stored in the bitmap
496  * @param bitmax The largest bit to be stored in the bitmap
497  */
498 void
499 vl_NewBitmapHash(BitmapHash **p_bmhash, char *name,
500  int32 bitzero, int32 bitmax)
501 {
502  BitmapHash *bmhash = *p_bmhash;
503 
504  if (bmhash) {
505  VarEntry *entry = NULL;
506  HTAB *hash = bmhash->hash;
507  bool found;
508 
509  while ((entry = vl_NextHashEntry(hash, entry))) {
510  if (entry->obj) {
511  if (entry->obj->type != OBJ_BITMAP) {
512  ereport(ERROR,
513  (errcode(ERRCODE_INTERNAL_ERROR),
514  errmsg("Bitmap hash contains invalid object %d",
515  entry->obj->type),
516  errdetail("Object type is %d, expected is %d.",
517  entry->obj->type, OBJ_BITMAP)));
518  }
519  pfree(entry->obj); /* Free the bitmap */
520  }
521  /* Now remove the entry from the hash */
522  (void) hash_search(hash, entry->key, HASH_REMOVE, &found);
523  }
524  }
525  else {
526  bmhash = vl_malloc(sizeof(BitmapHash));
527  bmhash->type = OBJ_BITMAP_HASH;
528  bmhash->hash = new_hash(name);
529  }
530  bmhash->bitzero = bitzero;
531  bmhash->bitmax = bitmax;
532 
533  *p_bmhash = bmhash;
534 }
535 
536 /**
537  * Return a specified ::Bitmap from a ::BitmapHash. Raise an error if
538  * the returned object from the hash search is not a bitmap.
539  *
540  * @param bmhash The ::BitmapHash from which the result is to be
541  * returned.
542  * @param hashelem The key of the ::Bitmap within the hash.
543  *
544  * @return The bitmap corresponding to the parameters, or NULL if no
545  *such entry exists within the hash.
546  */
547 Bitmap *
549  char *hashelem)
550 {
551  VarEntry *var;
552  Bitmap *bitmap;
553  bool found;
554 
555  var = hash_search(bmhash->hash, hashelem, HASH_FIND, &found);
556  if (!found) {
557  return NULL;
558  }
559 
560  if (!var->obj) {
561  ereport(ERROR,
562  (errcode(ERRCODE_INTERNAL_ERROR),
563  errmsg("BitmapFromHash - empty VarEntry")));
564  }
565 
566  if (var->obj->type != OBJ_BITMAP) {
567  ereport(ERROR,
568  (errcode(ERRCODE_INTERNAL_ERROR),
569  errmsg("Bitmap hash contains invalid object %d",
570  var->obj->type),
571  errdetail("Object type is %d, expected is %d.",
572  var->obj->type, OBJ_BITMAP)));
573  }
574 
575  bitmap = (Bitmap *) var->obj;
576  return bitmap;
577 }
578 
579 /**
580  * Create a newly allocated empty ::Bitmap to a ::BitmapHash
581  *
582  * @param bmhash The ::BitmapHash to which to add the new ::Bitmap.
583  * @param hashelem The key for the new entry
584  *
585  * @return Pointer to the newly allocated empty ::Bitmap.
586  */
587 Bitmap *
589  char *hashelem)
590 {
591  VarEntry *var;
592  Bitmap *bitmap = NULL;
593  bool found;
594 
595  var = hash_search(bmhash->hash, hashelem, HASH_ENTER, &found);
596  if (found) {
597  if (!var->obj) {
598  ereport(ERROR,
599  (errcode(ERRCODE_INTERNAL_ERROR),
600  errmsg("AddBitmapToHash - empty VarEntry")));
601  }
602  if (var->obj->type != OBJ_BITMAP) {
603  ereport(ERROR,
604  (errcode(ERRCODE_INTERNAL_ERROR),
605  errmsg("AddBitmapToHash - type mismatch %d",
606  var->obj->type),
607  errdetail("Object type is %d, expected is %d.",
608  var->obj->type, OBJ_BITMAP)));
609  }
610  return (Bitmap *) var->obj;
611  }
612 
613  /* We've created a new entry. Now create the bitmap for it. */
614 
615  vl_NewBitmap(&bitmap, FALSE, bmhash->bitzero, bmhash->bitmax);
616  var->obj = (Object *) bitmap;
617  return bitmap;
618 }
619 
620 /**
621  * Determine whether the supplied key exists in the ::BitmapHash.
622  *
623  * @param bmhash The ::BitmapHash to be tested
624  * @param hashelem The key to be tested
625  *
626  * @return True if the key already exists in the hash.
627  */
628 bool
630  char *hashelem)
631 {
632  bool found;
633 
634  (void) hash_search(bmhash->hash, hashelem, HASH_FIND, &found);
635  return found;
636 }
637 
638 
#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.
Definition: veil_bitmap.c:56
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.
Definition: veil_bitmap.c:262
void vl_NewBitmap(Bitmap **p_bitmap, bool shared, int32 min, int32 max)
Return a newly initialised (empty) Bitmap.
Definition: veil_bitmap.c:95
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.
Definition: veil_bitmap.c:232
#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.
Definition: veil_bitmap.c:295
bool vl_BitmapTestbit(Bitmap *bitmap, int32 bit)
Test a bit within a Bitmap.
Definition: veil_bitmap.c:210
void vl_ClearBitmap(Bitmap *bitmap)
Clear all bits in a Bitmap.
Definition: veil_bitmap.c:73
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.
Definition: veil_bitmap.c:321
#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.
Definition: veil_bitmap.c:499
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.
Definition: veil_shmem.c:437
#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.
Definition: veil_bitmap.c:151
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.
Definition: veil_bitmap.c:449
#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.
Definition: veil_bitmap.c:548
HTAB * hash
Pointer to the (Postgresql dynahash) hash table.
A Veil variable.
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.
Definition: veil_bitmap.c:588
VarEntry * vl_NextHashEntry(HTAB *hash, VarEntry *prev)
Utility function for scanning the hash table of a BitmapHash.
Definition: veil_bitmap.c:474
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.
Definition: veil_bitmap.c:341
void * vl_shmalloc(size_t size)
Dynamically allocate a piece of shared memory from the current context.
Definition: veil_shmem.c:414
void vl_NewBitmapArray(BitmapArray **p_bmarray, bool shared, int32 arrayzero, int32 arraymax, int32 bitzero, int32 bitmax)
Return a newly initialised (empty) BitmapArray.
Definition: veil_bitmap.c:368
#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.
Definition: veil_utils.c:28
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.
Definition: veil_bitmap.c:629
char key[60]
String containing variable name.
void vl_BitmapClearbit(Bitmap *bitmap, int32 bit)
Clear a bit within a Bitmap.
Definition: veil_bitmap.c:181
Define all Veil public datatypes.