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

unsigned long bitmap_cardinality ( const bitmap *  bm  ) 

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

Parameters:
bm The bitmaptor to check
Returns:
The cardinality of the bitmaptor
void bitmap_clear ( bitmap *  bm  ) 

Unset all bits in a bitmap.

Parameters:
bm The bitmap to clear
int bitmap_cmp ( const bitmap *  a,
const bitmap *  b 
)

Compare two bitmaps for equality.

Parameters:
a The first bitmaptor
b The other bitmaptor
Returns:
Similar to memcmp(), with tiebreaks determined by cardinality
bitmap* bitmap_copy ( const bitmap *  bm  ) 

Copy a bitmaptor.

Parameters:
bm The bitmaptor to copy
Returns:
Pointer to an identical bitmap on success, NULL on errors
unsigned long bitmap_count_set_bits ( const bitmap *  bm  ) 

Count set bits in map.

Completed in O(n/8) time.

Parameters:
bm The bitmaptor to count bits in
Returns:
The number of set bits
unsigned long bitmap_count_unset_bits ( const bitmap *  bm  ) 

Count unset bits in map.

Completed in O(n/8) time.

Parameters:
bm The bitmaptor to count bits in
Returns:
The number of set bits
bitmap* bitmap_create ( unsigned long  size  ) 

Create a bitmaptor of size 'size'.

Parameters:
size Desired storage capacity
Returns:
A bitmap pointer on success, NULL on errors
void bitmap_destroy ( bitmap *  bm  ) 

Destroy a bitmaptor by freeing all the memory it uses.

Parameters:
bm The bitmaptor to destroy
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.

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

Parameters:
a The first bitmaptor (numerator)
b The first bitmaptor (denominator)
Returns:
NULL on errors; A newly created bitmaptor on success.
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.

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

Parameters:
a The first bitmaptor
b The second bitmaptor
Returns:
NULL on errors; A newly created bitmaptor on success.
int bitmap_isset ( const bitmap *  bm,
unsigned long  pos 
)

Check if a particular bit is set in the map.

Parameters:
bm The bitmaptor to check
pos Position of the bit to check
Returns:
1 if set, otherwise 0
int bitmap_resize ( bitmap *  bm,
unsigned long  size 
)

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

Parameters:
bm The bitmap to resize
size The new desired size of the bitmap
Returns:
0 on success, -1 on errors.
int bitmap_set ( bitmap *  bm,
unsigned long  pos 
)

Set a bit in the map.

Parameters:
bm The bitmaptor to operate on
pos Position of the bit to set
Returns:
0 on success, -1 on errors
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.

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

Parameters:
a The first bitmaptor
b The second bitmaptor
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.

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

Parameters:
a The first bitmaptor
b The second bitmaptor
Returns:
NULL on errors; A newly created bitmaptor on success.
bitmap* bitmap_unite ( bitmap *  res,
const bitmap *  addme 
)

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

Parameters:
res The first bitmap
addme The bitmap to unite to the first bitmap
Returns:
NULL on errors, res on success
int bitmap_unset ( bitmap *  bm,
unsigned long  pos 
)

Unset a particular bit in the map.

Parameters:
bm The bitmaptor to operate on
pos Position of the bit to unset
 All Data Structures Files Functions Variables Typedefs Defines

Generated on 14 Aug 2014 for Nagios by  doxygen 1.6.1