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) (((n)+BITVEC_BITS-1)/BITVEC_BITS)
| Number of bitvec_t in a bit vector.
#define | bitvec_alloc(n) ckd_calloc(bitvec_size(n), sizeof(bitvec_t))
| Allocate a bit vector, all bits are clear.
#define | bitvec_free(v) ckd_free(v)
| Free a bit vector.
#define | bitvec_set(v, b) (v[(b)/BITVEC_BITS] |= (1UL << ((b) & (BITVEC_BITS-1))))
| Set the b-th bit of bit vector v. More...
#define | bitvec_set_all(v, n)
| Set all n bits in bit vector v. More...
#define | bitvec_clear(v, b) (v[(b)/BITVEC_BITS] &= ~(1UL << ((b) & (BITVEC_BITS-1))))
| Clear the b-th bit of bit vector v. More...
#define | bitvec_clear_all(v, n)
| Clear all n bits in bit vector v. More...
#define | bitvec_is_set(v, b) (v[(b)/BITVEC_BITS] & (1UL << ((b) & (BITVEC_BITS-1))))
| Check whether the b-th bit is set in vector v. More...
#define | bitvec_is_clear(v, b) (! (bitvec_is_set(v,b)))
| Check whether the b-th bit is cleared in vector v. More...

## 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. More...

## Detailed Description

An implementation of bit vectors.

Implementation of basic operations of bit vectors.

Definition in file bitvec.h.

## Macro Definition Documentation

## bitvec_clear

#define bitvec_clear | ( |  | v,
|  |  | b
| ) |  | (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_is_clear

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

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
| ) |  | (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
| ) |  | (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.

## 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.