Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

bit_array.h File Reference


Detailed Description

Bit arrays.

Author:
Christian Biere

Raphael Manfredi

Date:
2006

#include "common.h"

Go to the source code of this file.

Defines

#define BIT_ARRAY_BITSIZE   (CHAR_BIT * sizeof(bit_array_t))
#define BIT_ARRAY_BITMASK   (BIT_ARRAY_BITSIZE - 1)
#define BIT_ARRAY_WORD(base, i)   base[(i) >> BIT_ARRAY_BITSHIFT]
#define BIT_ARRAY_BIT(base, i)   (1UL << ((i) & BIT_ARRAY_BITMASK))
#define BIT_ARRAY_SIZE(n)
 Use the macro BIT_ARRAY_SIZE for allocating a properly sized bit array for "n" bits.
#define BIT_ARRAY_BYTE_SIZE(n)   (BIT_ARRAY_SIZE(n) * sizeof (bit_array_t))
 Use the macro BIT_ARRAY_BYTE_SIZE for dynamic allocation.

Typedefs

typedef unsigned long bit_array_t

Functions

bit_array_tbit_array_realloc (bit_array_t *base, size_t n)
 Re-allocates "base" so that it can hold at least "n" bits.
void bit_array_set (bit_array_t *base, size_t i)
 Sets bit number "i" of the bit array "base".
void bit_array_clear (bit_array_t *base, size_t i)
 Sets bit number "i" of the bit array "base".
gboolean bit_array_flip (bit_array_t *base, size_t i)
 Flips bit number "i" of the bit array "base".
gboolean bit_array_get (const bit_array_t *base, size_t i)
 Retrieves bit number "i" of the bit array "base".
void bit_array_clear_range (bit_array_t *base, size_t from, size_t to)
 Clears all bits starting at "from" up to "to" inclusive.
void bit_array_set_range (bit_array_t *base, size_t from, size_t to)
 Sets all bits starting at "from" up to "to" inclusive.
size_t bit_array_first_clear (const bit_array_t *base, size_t from, size_t to)
 Peforms a linear scan for the first unset bit of the given bit array.


Define Documentation

#define BIT_ARRAY_BIT base,
 )     (1UL << ((i) & BIT_ARRAY_BITMASK))
 

#define BIT_ARRAY_BITMASK   (BIT_ARRAY_BITSIZE - 1)
 

#define BIT_ARRAY_BITSIZE   (CHAR_BIT * sizeof(bit_array_t))
 

#define BIT_ARRAY_BYTE_SIZE  )     (BIT_ARRAY_SIZE(n) * sizeof (bit_array_t))
 

Use the macro BIT_ARRAY_BYTE_SIZE for dynamic allocation.

Example:

bit_array_t *bits = malloc(BIT_ARRAY_BYTE_SIZE(num_bits));

#define BIT_ARRAY_SIZE  ) 
 

Value:

((n) / (CHAR_BIT * sizeof(bit_array_t)) + \
     ((n) % (CHAR_BIT * sizeof(bit_array_t)) ? 1 : 0))
Use the macro BIT_ARRAY_SIZE for allocating a properly sized bit array for "n" bits.

Example:

static bit_array_t ba[BIT_ARRAY_SIZE(100)];

#define BIT_ARRAY_WORD base,
 )     base[(i) >> BIT_ARRAY_BITSHIFT]
 


Typedef Documentation

typedef unsigned long bit_array_t
 


Function Documentation

void bit_array_clear bit_array_t base,
size_t  i
[inline, static]
 

Sets bit number "i" of the bit array "base".

Note:
: For optimum performance, there are no checks at all.

void bit_array_clear_range bit_array_t base,
size_t  from,
size_t  to
[inline, static]
 

Clears all bits starting at "from" up to "to" inclusive.

Note:
: For optimum performance, there are no checks at all.
Parameters:
base The base address of the bit array.
from The first bit.
to The last bit, must be equal or above "from".
Returns:
TRUE if the bit is set, FALSE otherwise.

size_t bit_array_first_clear const bit_array_t base,
size_t  from,
size_t  to
[inline, static]
 

Peforms a linear scan for the first unset bit of the given bit array.

Parameters:
base The base address of the bit array.
from The first bit.
to The last bit, must be equal or above "from".
Returns:
(size_t) -1, if no unset bit was found. On success the index of the first unset bit is returned.

gboolean bit_array_flip bit_array_t base,
size_t  i
[inline, static]
 

Flips bit number "i" of the bit array "base".

Note:
: For optimum performance, there are no checks at all.
Returns:
The new state of the bit.

gboolean bit_array_get const bit_array_t base,
size_t  i
[inline, static]
 

Retrieves bit number "i" of the bit array "base".

Note:
: For optimum performance, there are no checks at all.
Returns:
TRUE if the bit is set, FALSE otherwise.

bit_array_t* bit_array_realloc bit_array_t base,
size_t  n
[inline, static]
 

Re-allocates "base" so that it can hold at least "n" bits.

Parameters:
base The base address of the bit array, may be NULL.
n The number of bits the bit array should hold.
Returns:
the re-allocated bit array.
Attention:
DO NOT USE IN MEMORY ALLOCATING ROUTINES!

void bit_array_set bit_array_t base,
size_t  i
[inline, static]
 

Sets bit number "i" of the bit array "base".

Note:
: For optimum performance, there are no checks at all.

void bit_array_set_range bit_array_t base,
size_t  from,
size_t  to
[inline, static]
 

Sets all bits starting at "from" up to "to" inclusive.

Note:
: For optimum performance, there are no checks at all.
Parameters:
base The base address of the bit array.
from The first bit.
to The last bit, must be equal or above "from".
Returns:
TRUE if the bit is set, FALSE otherwise.


Generated on Sat Jun 30 17:53:25 2007 for gtk-gnutella by  doxygen 1.3.9.1