Veil
veil_bitmap.c File Reference

Functions for manipulating Bitmaps, BitmapHashes and BitmapArrays. More...

#include <stdio.h>
#include "postgres.h"
#include "veil_datatypes.h"
#include "veil_funcs.h"

Go to the source code of this file.

Functions

void vl_ClearBitmap (Bitmap *bitmap)
 Clear all bits in a Bitmap. More...
 
void vl_NewBitmap (Bitmap **p_bitmap, bool shared, int32 min, int32 max)
 Return a newly initialised (empty) Bitmap. More...
 
void vl_BitmapSetbit (Bitmap *bitmap, int32 bit)
 Set a bit within a Bitmap. More...
 
void vl_BitmapClearbit (Bitmap *bitmap, int32 bit)
 Clear a bit within a Bitmap. More...
 
bool vl_BitmapTestbit (Bitmap *bitmap, int32 bit)
 Test a bit within a Bitmap. More...
 
void vl_BitmapUnion (Bitmap *target, Bitmap *source)
 Create the union of two bitmaps, updating the first with the result. More...
 
void vl_BitmapIntersect (Bitmap *target, Bitmap *source)
 Create the intersection of two bitmaps, updating the first with the result. More...
 
int32 vl_BitmapNextBit (Bitmap *bitmap, int32 bit, bool *found)
 Return the next set bit in the Bitmap. More...
 
Bitmapvl_BitmapFromArray (BitmapArray *bmarray, int32 elem)
 Return a specified Bitmap from a BitmapArray. More...
 
void vl_ClearBitmapArray (BitmapArray *bmarray)
 Clear all bitmaps in the given BitmapArray. More...
 
void vl_NewBitmapArray (BitmapArray **p_bmarray, bool shared, int32 arrayzero, int32 arraymax, int32 bitzero, int32 bitmax)
 Return a newly initialised (empty) BitmapArray. More...
 
static HTAB * new_hash (char *name)
 Create a new hash table. More...
 
VarEntryvl_NextHashEntry (HTAB *hash, VarEntry *prev)
 Utility function for scanning the hash table of a BitmapHash. More...
 
void vl_NewBitmapHash (BitmapHash **p_bmhash, char *name, int32 bitzero, int32 bitmax)
 Return a newly initialised (empty) BitmapHash. More...
 
Bitmapvl_BitmapFromHash (BitmapHash *bmhash, char *hashelem)
 Return a specified Bitmap from a BitmapHash. More...
 
Bitmapvl_AddBitmapToHash (BitmapHash *bmhash, char *hashelem)
 Create a newly allocated empty Bitmap to a BitmapHash. More...
 
bool vl_BitmapHashHasKey (BitmapHash *bmhash, char *hashelem)
 Determine whether the supplied key exists in the BitmapHash. More...
 

Variables

static uint32 bitmasks []
 Array of bit positions for int32, indexed by bitno. More...
 

Detailed Description

Functions for manipulating Bitmaps, BitmapHashes and BitmapArrays.

Author: Marc Munro
Copyright (c) 2005 - 2011 Marc Munro
License: BSD

Definition in file veil_bitmap.c.

Function Documentation

◆ vl_ClearBitmap()

void vl_ClearBitmap ( Bitmap bitmap)

Clear all bits in a Bitmap.

Parameters
bitmapThe Bitmap in which all bits are to be cleared

Definition at line 73 of file veil_bitmap.c.

References ARRAYELEMS, Bitmap::bitmax, Bitmap::bitset, and Bitmap::bitzero.

Referenced by veil_clear_bitmap(), veil_intersect_from_bitmap_hash(), vl_ClearBitmapArray(), and vl_NewBitmap().

◆ vl_NewBitmap()

void vl_NewBitmap ( Bitmap **  p_bitmap,
bool  shared,
int32  min,
int32  max 
)

Return a newly initialised (empty) Bitmap.

The bitmap may already exist in which case it will be re-used if possible. The bitmap may be created in either session or shared memory depending on the value of shared.

Parameters
p_bitmapPointer to an existing bitmap if one exists
sharedWhether to create the bitmap in shared memory
minThe smallest bit to be stored in the bitmap
maxThe largest bit to be stored in the bitmap

Definition at line 95 of file veil_bitmap.c.

References ARRAYELEMS, Bitmap::bitmax, Bitmap::bitzero, DBG_SET_CANARY, DBG_SET_ELEMS, DBG_SET_TRAILER, Bitmap::type, vl_ClearBitmap(), vl_free(), vl_malloc(), and vl_shmalloc().

Referenced by veil_init_bitmap(), and vl_NewBitmapArray().

◆ vl_BitmapSetbit()

void vl_BitmapSetbit ( Bitmap bitmap,
int32  bit 
)

Set a bit within a Bitmap.

If the bit is outside of the acceptable range, raise an error.

Parameters
bitmapThe Bitmap within which the bit is to be set.
bitThe bit to be set.

Definition at line 151 of file veil_bitmap.c.

References bitmasks, Bitmap::bitmax, Bitmap::bitset, BITSET_BIT, BITSET_ELEM, BITZERO, Bitmap::bitzero, DBG_CHECK_INDEX, DBG_TEST_CANARY, and DBG_TEST_TRAILER.

Referenced by veil_bitmap_array_setbit(), veil_bitmap_hash_setbit(), and veil_bitmap_setbit().

◆ vl_BitmapClearbit()

void vl_BitmapClearbit ( Bitmap bitmap,
int32  bit 
)

Clear a bit within a Bitmap.

If the bit is outside of the acceptable range, raise an error.

Parameters
bitmapThe Bitmap within which the bit is to be cleared.
bitThe bit to be cleared.

Definition at line 181 of file veil_bitmap.c.

References bitmasks, Bitmap::bitmax, Bitmap::bitset, BITSET_BIT, BITSET_ELEM, BITZERO, and Bitmap::bitzero.

Referenced by veil_bitmap_array_clearbit(), veil_bitmap_clearbit(), and veil_bitmap_hash_clearbit().

◆ vl_BitmapTestbit()

bool vl_BitmapTestbit ( Bitmap bitmap,
int32  bit 
)

Test a bit within a Bitmap.

If the bit is outside of the acceptable range return false.

Parameters
bitmapThe Bitmap within which the bit is to be set.
bitThe bit to be tested.
Returns
True if the bit is set, false otherwise.

Definition at line 210 of file veil_bitmap.c.

References bitmasks, Bitmap::bitmax, Bitmap::bitset, BITSET_BIT, BITSET_ELEM, BITZERO, and Bitmap::bitzero.

Referenced by veil_bitmap_array_testbit(), veil_bitmap_hash_testbit(), veil_bitmap_testbit(), and vl_BitmapNextBit().

◆ vl_BitmapUnion()

void vl_BitmapUnion ( Bitmap target,
Bitmap source 
)

Create the union of two bitmaps, updating the first with the result.

Parameters
targetThe Bitmap into which the result will be placed.
sourceThe Bitmap to be unioned into target.

Definition at line 232 of file veil_bitmap.c.

References ARRAYELEMS, Bitmap::bitmax, Bitmap::bitset, and Bitmap::bitzero.

Referenced by veil_bitmap_union(), veil_union_from_bitmap_array(), veil_union_from_bitmap_hash(), and veil_union_into_bitmap_hash().

◆ vl_BitmapIntersect()

void vl_BitmapIntersect ( Bitmap target,
Bitmap source 
)

Create the intersection of two bitmaps, updating the first with the result.

Parameters
targetThe Bitmap into which the result will be placed.
sourceThe Bitmap to be intersected into target.

Definition at line 262 of file veil_bitmap.c.

References ARRAYELEMS, Bitmap::bitmax, Bitmap::bitset, and Bitmap::bitzero.

Referenced by veil_bitmap_intersect(), veil_intersect_from_bitmap_array(), and veil_intersect_from_bitmap_hash().

◆ vl_BitmapNextBit()

int32 vl_BitmapNextBit ( Bitmap bitmap,
int32  bit,
bool *  found 
)

Return the next set bit in the Bitmap.

Parameters
bitmapThe Bitmap being scanned.
bitThe starting bit from which to scan the bitmap
foundBoolean that will be set to true when a set bit has been found.
Returns
The bit id of the found bit, or zero if no set bits were found.

Definition at line 295 of file veil_bitmap.c.

References vl_BitmapTestbit().

Referenced by veil_bitmap_array_bits(), veil_bitmap_bits(), and veil_bitmap_hash_bits().

◆ vl_BitmapFromArray()

Bitmap* vl_BitmapFromArray ( BitmapArray bmarray,
int32  elem 
)

Return a specified Bitmap from a BitmapArray.

Parameters
bmarrayThe BitmapArray from which the result is to be returned.
elemThe index of the Bitmap within the array.
Returns
The bitmap corresponding to the parameters, or NULL if no such entry exists within the array.

Definition at line 321 of file veil_bitmap.c.

References BitmapArray::arraymax, BitmapArray::arrayzero, BitmapArray::bitmap, DBG_CHECK_INDEX, DBG_TEST_CANARY, and DBG_TEST_TRAILER.

Referenced by veil_bitmap_array_bits(), veil_bitmap_array_clearbit(), veil_bitmap_array_setbit(), veil_bitmap_array_testbit(), veil_bitmap_from_array(), veil_intersect_from_bitmap_array(), and veil_union_from_bitmap_array().

◆ vl_ClearBitmapArray()

void vl_ClearBitmapArray ( BitmapArray bmarray)

Clear all bitmaps in the given BitmapArray.

Parameters
bmarrayThe BitmapArray to be cleared

Definition at line 341 of file veil_bitmap.c.

References BitmapArray::arraymax, BitmapArray::arrayzero, BitmapArray::bitmap, DBG_CHECK_INDEX, DBG_TEST_CANARY, DBG_TEST_TRAILER, and vl_ClearBitmap().

Referenced by veil_clear_bitmap_array(), and vl_NewBitmapArray().

◆ vl_NewBitmapArray()

void vl_NewBitmapArray ( BitmapArray **  p_bmarray,
bool  shared,
int32  arrayzero,
int32  arraymax,
int32  bitzero,
int32  bitmax 
)

Return a newly initialised (empty) BitmapArray.

It may already exist in which case it will be re-used if possible. It may be created in either session or shared memory depending on the value of shared.

Parameters
p_bmarrayPointer to an existing bitmap if one exists.
sharedWhether to create the bitmap in shared memory
arrayzeroThe lowest array index
arraymaxThe highest array index
bitzeroThe smallest bit to be stored in the bitmap
bitmaxThe largest bit to be stored in the bitmap

Definition at line 368 of file veil_bitmap.c.

References ARRAYELEMS, BitmapArray::arraymax, BitmapArray::arrayzero, BitmapArray::bitmap, BitmapArray::bitmax, BitmapArray::bitzero, DBG_TEST_CANARY, DBG_TEST_TRAILER, BitmapArray::type, vl_ClearBitmapArray(), vl_free(), vl_malloc(), vl_NewBitmap(), and vl_shmalloc().

Referenced by veil_init_bitmap_array().

◆ new_hash()

static HTAB* new_hash ( char *  name)
static

Create a new hash table.

This is allocated from session memory as BitmapHashes may not be declared as shared variables.

Parameters
nameThe name of the hash to be created. Note that we prefix this with "vl_" to prevent name collisions from other subsystems.
Returns
Pointer to the newly created hash table.

Definition at line 449 of file veil_bitmap.c.

References HASH_KEYLEN.

◆ vl_NextHashEntry()

VarEntry* vl_NextHashEntry ( HTAB *  hash,
VarEntry prev 
)

Utility function for scanning the hash table of a BitmapHash.

Parameters
hashThe hash table being scanned
prevThe entry from which to scan, starting with NULL.
Returns
The next element in the hash table (a VarEntry) or NULL when the last element has already been scanned.

Definition at line 474 of file veil_bitmap.c.

Referenced by serialise_bitmap_hash(), sizeof_bitmaps_in_hash(), veil_bitmap_hash_entries(), and vl_NewBitmapHash().

◆ vl_NewBitmapHash()

void vl_NewBitmapHash ( BitmapHash **  p_bmhash,
char *  name,
int32  bitzero,
int32  bitmax 
)

Return a newly initialised (empty) BitmapHash.

It may already exist in which case it will be re-used if possible. BitmapHash variables may only be created as session (not shared) variables.

Parameters
p_bmhashPointer to an existing bitmap if one exists.
nameThe name to be used for the hash table
bitzeroThe smallest bit to be stored in the bitmap
bitmaxThe largest bit to be stored in the bitmap

Definition at line 499 of file veil_bitmap.c.

References BitmapHash::hash, VarEntry::obj, Object::type, and vl_NextHashEntry().

Referenced by veil_clear_bitmap_hash(), and veil_init_bitmap_hash().

◆ vl_BitmapFromHash()

Bitmap* vl_BitmapFromHash ( BitmapHash bmhash,
char *  hashelem 
)

Return a specified Bitmap from a BitmapHash.

Raise an error if the returned object from the hash search is not a bitmap.

Parameters
bmhashThe BitmapHash from which the result is to be returned.
hashelemThe key of the Bitmap within the hash.
Returns
The bitmap corresponding to the parameters, or NULL if no such entry exists within the hash.

Definition at line 548 of file veil_bitmap.c.

References BitmapHash::hash, VarEntry::obj, and Object::type.

Referenced by veil_bitmap_hash_bits(), veil_bitmap_hash_testbit(), veil_intersect_from_bitmap_hash(), and veil_union_from_bitmap_hash().

◆ vl_AddBitmapToHash()

Bitmap* vl_AddBitmapToHash ( BitmapHash bmhash,
char *  hashelem 
)

Create a newly allocated empty Bitmap to a BitmapHash.

Parameters
bmhashThe BitmapHash to which to add the new Bitmap.
hashelemThe key for the new entry
Returns
Pointer to the newly allocated empty Bitmap.

Definition at line 588 of file veil_bitmap.c.

References BitmapHash::hash, VarEntry::obj, and Object::type.

Referenced by veil_bitmap_from_hash(), veil_bitmap_hash_clearbit(), veil_bitmap_hash_setbit(), and veil_union_into_bitmap_hash().

◆ vl_BitmapHashHasKey()

bool vl_BitmapHashHasKey ( BitmapHash bmhash,
char *  hashelem 
)

Determine whether the supplied key exists in the BitmapHash.

Parameters
bmhashThe BitmapHash to be tested
hashelemThe key to be tested
Returns
True if the key already exists in the hash.

Definition at line 629 of file veil_bitmap.c.

References BitmapHash::hash.

Referenced by veil_bitmap_hash_key_exists().

Variable Documentation

◆ bitmasks

uint32 bitmasks[]
static
Initial value:
= {0x00000001, 0x00000002, 0x00000004, 0x00000008,
0x00000010, 0x00000020, 0x00000040, 0x00000080,
0x00000100, 0x00000200, 0x00000400, 0x00000800,
0x00001000, 0x00002000, 0x00004000, 0x00008000,
0x00010000, 0x00020000, 0x00040000, 0x00080000,
0x00100000, 0x00200000, 0x00400000, 0x00800000,
0x01000000, 0x02000000, 0x04000000, 0x08000000,
0x10000000, 0x20000000, 0x40000000, 0x80000000}

Array of bit positions for int32, indexed by bitno.

Definition at line 56 of file veil_bitmap.c.

Referenced by vl_BitmapClearbit(), vl_BitmapSetbit(), and vl_BitmapTestbit().