00001
00002
00003
00004
00005
00006
00007 #ifndef __NM_BV_H
00008 #define __NM_BV_H
00009
00010 #include <stdlib.h>
00011 #include <string.h>
00012 #include <nm/nm.h>
00013
00014 #ifdef __cplusplus
00015 extern "C" {
00016 #endif
00017
00030 typedef struct nm_bv {
00031 int count;
00032 int set_count;
00033 nm_u32_t *bitvec;
00034 } nm_bv_t;
00035
00036 typedef struct nm_bv_iter {
00037 int next_idx;
00038 int next_bit;
00039 } nm_bv_iter_t;
00040
00041
00042
00043 #define NM_BV_DEF_COUNT 32
00044
00045
00046
00047
00048 #define NM_BV_SZ_SHIFT 3
00049
00050
00051
00052 #define NM_BV_IDX_SHIFT 5
00053
00054
00055 #define NM_BV_IBITS (32)
00056
00057
00058
00059 #define NM_BV_IBIT_MASK (NM_BV_IBITS-1)
00060
00061
00062 #define NM_BV_INITIALIZER { 0 }
00063
00064 static inline int nm_bv_bits_to_words(int bits)
00065 {
00066 return nm_roundup2(bits, NM_BV_IBITS) >> NM_BV_IDX_SHIFT;
00067 }
00068
00069 static inline void nm_bv_init(nm_bv_t *bv)
00070 {
00071 bv->count = bv->set_count = 0;
00072 bv->bitvec = NULL;
00073 }
00074
00080 extern void nm_bv_free(nm_bv_t *bv);
00081
00089 extern int nm_bv_copy(nm_bv_t *dst, nm_bv_t *src);
00090
00101 extern int nm_bv_set(nm_bv_t *bv, int bit);
00102
00110 extern int nm_bv_set_count(nm_bv_t *bv);
00111
00123 extern int nm_bv_reset(nm_bv_t *bv, int bit);
00124
00136 extern int nm_bv_test(nm_bv_t *bv, int bit);
00137
00146 extern int nm_bv_first(nm_bv_t *bv, nm_bv_iter_t *iter);
00147
00157 extern int nm_bv_next(nm_bv_t *bv, nm_bv_iter_t *iter);
00158
00175 extern int nm_sz_to_bv(const char *sz, nm_bv_t *bv,
00176 const char *rangesep, const char *sep);
00195 extern int nm_bv_to_sz(nm_bv_t *bv, char *sz, int maxlen,
00196 const char *rangesep, const char *sep);
00197
00200 #ifdef __cplusplus
00201 }
00202 #endif
00203
00204 #endif