Nagios 4.5.4
Dev docs for Nagios core and neb-module hackers
Loading...
Searching...
No Matches
bitmap.h File Reference

Bit map API. More...

Go to the source code of this file.

#define bitmap_size   bitmap_cardinality
 
typedef struct bitmap bitmap
 
int bitmap_resize (bitmap *bm, unsigned long size)
 Resize a bitmap If the bitmap is made smaller, data will silently be lost.
 
bitmap * bitmap_create (unsigned long size)
 Create a bitmaptor of size 'size'.
 
void bitmap_destroy (bitmap *bm)
 Destroy a bitmaptor by freeing all the memory it uses.
 
bitmap * bitmap_copy (const bitmap *bm)
 Copy a bitmaptor.
 
int bitmap_set (bitmap *bm, unsigned long pos)
 Set a bit in the map.
 
int bitmap_isset (const bitmap *bm, unsigned long pos)
 Check if a particular bit is set in the map.
 
int bitmap_unset (bitmap *bm, unsigned long pos)
 Unset a particular bit in the map.
 
unsigned long bitmap_cardinality (const bitmap *bm)
 Obtain cardinality (max number of elements) of the bitmaptor.
 
unsigned long bitmap_count_set_bits (const bitmap *bm)
 Count set bits in map.
 
unsigned long bitmap_count_unset_bits (const bitmap *bm)
 Count unset bits in map.
 
void bitmap_clear (bitmap *bm)
 Unset all bits in a bitmap.
 
bitmap * bitmap_intersect (const bitmap *a, const bitmap *b)
 Calculate intersection of two bitmaps The intersection is defined as all bits that are members of both A and B.
 
bitmap * bitmap_union (const bitmap *a, const bitmap *b)
 Calculate union of two bitmaps The union is defined as all bits that are members of A or B or both A and B.
 
bitmap * bitmap_unite (bitmap *res, const bitmap *addme)
 Calculate union of two bitmaps and store result in one of them.
 
bitmap * bitmap_diff (const bitmap *a, const bitmap *b)
 Calculate set difference between two bitmaps The set difference of A / B is defined as all members of A that isn't members of B.
 
bitmap * bitmap_symdiff (const bitmap *a, const bitmap *b)
 Calculate symmetric difference between two bitmaps The symmetric difference between A and B is the set that contains all elements in either set but not in both.
 
int bitmap_cmp (const bitmap *a, const bitmap *b)
 Compare two bitmaps for equality.
 

Detailed Description

Bit map API.

The bitmap api is useful for running set operations on objects indexed by unsigned integers.

Function Documentation

◆ bitmap_cardinality()

unsigned long bitmap_cardinality ( const bitmap * bm)
extern

Obtain cardinality (max number of elements) of the bitmaptor.

Parameters
bmThe bitmaptor to check
Returns
The cardinality of the bitmaptor

◆ bitmap_clear()

void bitmap_clear ( bitmap * bm)
extern

Unset all bits in a bitmap.

Parameters
bmThe bitmap to clear

◆ bitmap_cmp()

int bitmap_cmp ( const bitmap * a,
const bitmap * b )
extern

Compare two bitmaps for equality.

Parameters
aThe first bitmaptor
bThe other bitmaptor
Returns
Similar to memcmp(), with tiebreaks determined by cardinality

◆ bitmap_copy()

bitmap * bitmap_copy ( const bitmap * bm)
extern

Copy a bitmaptor.

Parameters
bmThe bitmaptor to copy
Returns
Pointer to an identical bitmap on success, NULL on errors

◆ bitmap_count_set_bits()

unsigned long bitmap_count_set_bits ( const bitmap * bm)
extern

Count set bits in map.

Completed in O(n/8) time.

Parameters
bmThe bitmaptor to count bits in
Returns
The number of set bits

◆ bitmap_count_unset_bits()

unsigned long bitmap_count_unset_bits ( const bitmap * bm)
extern

Count unset bits in map.

Completed in O(n/8) time.

Parameters
bmThe bitmaptor to count bits in
Returns
The number of set bits

◆ bitmap_create()

bitmap * bitmap_create ( unsigned long size)
extern

Create a bitmaptor of size 'size'.

Parameters
sizeDesired storage capacity
Returns
A bitmap pointer on success, NULL on errors

◆ bitmap_destroy()

void bitmap_destroy ( bitmap * bm)
extern

Destroy a bitmaptor by freeing all the memory it uses.

Parameters
bmThe bitmaptor to destroy

◆ bitmap_diff()

bitmap * bitmap_diff ( const bitmap * a,
const bitmap * b )
extern

Calculate set difference between two bitmaps The set difference of A / B is defined as all members of A that isn't members of B.

Note that parameter ordering matters for this function. This function completes in O(n/sizeof(long)) operations.

Parameters
aThe first bitmaptor (numerator)
bThe first bitmaptor (denominator)
Returns
NULL on errors; A newly created bitmaptor on success.

◆ bitmap_intersect()

bitmap * bitmap_intersect ( const bitmap * a,
const bitmap * b )
extern

Calculate intersection of two bitmaps The intersection is defined as all bits that are members of both A and B.

It's equivalent to bitwise AND. This function completes in O(n/sizeof(long)) operations.

Parameters
aThe first bitmaptor
bThe second bitmaptor
Returns
NULL on errors; A newly created bitmaptor on success.

◆ bitmap_isset()

int bitmap_isset ( const bitmap * bm,
unsigned long pos )
extern

Check if a particular bit is set in the map.

Parameters
bmThe bitmaptor to check
posPosition of the bit to check
Returns
1 if set, otherwise 0

◆ bitmap_resize()

int bitmap_resize ( bitmap * bm,
unsigned long size )
extern

Resize a bitmap If the bitmap is made smaller, data will silently be lost.

Parameters
bmThe bitmap to resize
sizeThe new desired size of the bitmap
Returns
0 on success, -1 on errors.

◆ bitmap_set()

int bitmap_set ( bitmap * bm,
unsigned long pos )
extern

Set a bit in the map.

Parameters
bmThe bitmaptor to operate on
posPosition of the bit to set
Returns
0 on success, -1 on errors

◆ bitmap_symdiff()

bitmap * bitmap_symdiff ( const bitmap * a,
const bitmap * b )
extern

Calculate symmetric difference between two bitmaps The symmetric difference between A and B is the set that contains all elements in either set but not in both.

This function completes in O(n/sizeof(long)) operations.

Parameters
aThe first bitmaptor
bThe second bitmaptor

◆ bitmap_union()

bitmap * bitmap_union ( const bitmap * a,
const bitmap * b )
extern

Calculate union of two bitmaps The union is defined as all bits that are members of A or B or both A and B.

It's equivalent to bitwise OR. This function completes in O(n/sizeof(long)) operations.

Parameters
aThe first bitmaptor
bThe second bitmaptor
Returns
NULL on errors; A newly created bitmaptor on success.

◆ bitmap_unite()

bitmap * bitmap_unite ( bitmap * res,
const bitmap * addme )
extern

Calculate union of two bitmaps and store result in one of them.

Parameters
resThe first bitmap
addmeThe bitmap to unite to the first bitmap
Returns
NULL on errors, res on success

◆ bitmap_unset()

int bitmap_unset ( bitmap * bm,
unsigned long pos )
extern

Unset a particular bit in the map.

Parameters
bmThe bitmaptor to operate on
posPosition of the bit to unset