bitvec.h File Reference

An implementation of bit vectors. More...

`#include <string.h>`
`#include <sphinxbase/sphinxbase_export.h>`
`#include <sphinxbase/prim_type.h>`
`#include <sphinxbase/ckd_alloc.h>`

Go to the source code of this file.

## Macros

#define | BITVEC_BITS 32
#define | bitvec_size(n)
| Number of bitvec_t in a bit vector.
#define | bitvec_alloc(n)
| Allocate a bit vector, all bits are clear.
#define | bitvec_free(v)
| Free a bit vector.
#define | bitvec_set(v, b)
| Set the b-th bit of bit vector v.
#define | bitvec_set_all(v, n)
| Set all n bits in bit vector v.
#define | bitvec_clear(v, b)
| Clear the b-th bit of bit vector v.
#define | bitvec_clear_all(v, n)
| Clear all n bits in bit vector v.
#define | bitvec_is_set(v, b)
| Check whether the b-th bit is set in vector v.
#define | bitvec_is_clear(v, b)
| Check whether the b-th bit is cleared in vector v.

## Typedefs

typedef uint32 | bitvec_t

## Functions

SPHINXBASE_EXPORT bitvec_t * | bitvec_realloc (bitvec_t *vec, size_t old_len, size_t new_len)
| Resize a bit vector, clear the remaining bits.
SPHINXBASE_EXPORT size_t | bitvec_count_set (bitvec_t *vec, size_t len)
| Return the number of bits set in the given bitvector.

## Detailed Description

An implementation of bit vectors.

Implementation of basic operations of bit vectors.

Definition in file bitvec.h.

## Macro Definition Documentation

## bitvec_alloc

#define bitvec_alloc | ( |  | n | ) |

Value:
ckd_calloc(bitvec_size(n), sizeof(bitvec_t))
bitvec_size
#define bitvec_size(n)
Number of bitvec_t in a bit vector.
Definition bitvec.h:70
ckd_calloc
#define ckd_calloc(n, sz)
Macros to simplify the use of above functions.
Definition ckd_alloc.h:248

Allocate a bit vector, all bits are clear.

Definition at line 75 of file bitvec.h.

## BITVEC_BITS

#define BITVEC_BITS 32

Definition at line 64 of file bitvec.h.

## bitvec_clear

#define bitvec_clear | ( |  | v,
|  |  | b )

Value:
(v[(b)/BITVEC_BITS] &= ~(1UL << ((b) & (BITVEC_BITS-1))))

Clear the b-th bit of bit vector v.

Parameters

  v | is a vector
  b | is the bit which will be set

Definition at line 112 of file bitvec.h.

## bitvec_clear_all

#define bitvec_clear_all | ( |  | v,
|  |  | n )

Value:
memset(v, 0, (((n)+BITVEC_BITS-1)/BITVEC_BITS) * \
sizeof(bitvec_t))

Clear all n bits in bit vector v.

Parameters

  v | is a vector
  n | is the number of bits

Definition at line 120 of file bitvec.h.

## bitvec_free

#define bitvec_free | ( |  | v | ) |

Value:
ckd_free(v)
ckd_free
SPHINXBASE_EXPORT void ckd_free(void *ptr)
Test and free a 1-D array.
Definition ckd_alloc.c:244

Free a bit vector.

Definition at line 87 of file bitvec.h.

## bitvec_is_clear

#define bitvec_is_clear | ( |  | v,
|  |  | b )

Value:
(! (bitvec_is_set(v,b)))
bitvec_is_set
#define bitvec_is_set(v, b)
Check whether the b-th bit is set in vector v.
Definition bitvec.h:129

Check whether the b-th bit is cleared in vector v.

Parameters

  v | is a vector
  b | is the bit which will be checked

Definition at line 137 of file bitvec.h.

## bitvec_is_set

#define bitvec_is_set | ( |  | v,
|  |  | b )

Value:
(v[(b)/BITVEC_BITS] & (1UL << ((b) & (BITVEC_BITS-1))))

Check whether the b-th bit is set in vector v.

Parameters

  v | is a vector
  b | is the bit which will be checked

Definition at line 129 of file bitvec.h.

## bitvec_set

#define bitvec_set | ( |  | v,
|  |  | b )

Value:
(v[(b)/BITVEC_BITS] |= (1UL << ((b) & (BITVEC_BITS-1))))

Set the b-th bit of bit vector v.

Parameters

  v | is a vector
  b | is the bit which will be set

Definition at line 95 of file bitvec.h.

## bitvec_set_all

#define bitvec_set_all | ( |  | v,
|  |  | n )

Value:
memset(v, (bitvec_t)-1, \
(((n)+BITVEC_BITS-1)/BITVEC_BITS) * \
sizeof(bitvec_t))

Set all n bits in bit vector v.

Parameters

  v | is a vector
  n | is the number of bits

Definition at line 103 of file bitvec.h.

## bitvec_size

#define bitvec_size | ( |  | n | ) |

Value:
(((n)+BITVEC_BITS-1)/BITVEC_BITS)

Number of bitvec_t in a bit vector.

Definition at line 70 of file bitvec.h.

Referenced by bitvec_realloc().

## Typedef Documentation

## bitvec_t

typedef uint32 bitvec_t

Definition at line 65 of file bitvec.h.

## Function Documentation

## bitvec_count_set()

SPHINXBASE_EXPORT size_t bitvec_count_set | ( | bitvec_t * | vec,
|  | size_t | len )

Return the number of bits set in the given bitvector.

Parameters

  vec | is the bit vector
  len | is the length of bit vector `vec`

Returns
  the number of bits being set in vector `vec`

Definition at line 80 of file bitvec.c.

References bitvec_count_set().

Referenced by bitvec_count_set().

## bitvec_realloc()

SPHINXBASE_EXPORT bitvec_t * bitvec_realloc | ( | bitvec_t * | vec,
|  | size_t | old_len,
|  | size_t | new_len )

Resize a bit vector, clear the remaining bits.

Definition at line 64 of file bitvec.c.

References bitvec_realloc(), bitvec_size, and ckd_realloc.

Referenced by bitvec_realloc().