libisdn
|
00001 #ifndef _BITMAP_H 00002 #define _BITMAP_H 00003 00004 #include <limits.h> 00005 #include "common.h" 00006 00007 #ifndef LONG_MAX 00008 #error "LONG_MAX not defined" 00009 #endif 00010 00011 #if (LONG_MAX == 2147483647) 00012 #define BITS_PER_LONG 32 00013 #define BITMAP_SIZE(x) (((x) + 31) >> 5) 00014 #define BITMAP_SIZE_BYTES(x) (BITMAP_SIZE(x) << 2) 00015 #define BITMAP_BIT(x) ((x) & 0x1f) 00016 #define BITMAP_OFFSET(x) ((x) >> 5) 00017 #else 00018 #define BITS_PER_LONG 64 00019 #define BITMAP_SIZE(x) (((x) + 63) >> 6) 00020 #define BITMAP_SIZE_BYTES(x) (BITMAP_SIZE(x) << 3) 00021 #define BITMAP_BIT(x) ((x) & 0x3f) 00022 #define BITMAP_OFFSET(x) ((x) >> 6) 00023 #endif 00024 00025 typedef unsigned long bitmap_t; 00026 00027 #define DECLARE_BITMAP(_name, _nbits) \ 00028 bitmap_t _name[BITMAP_SIZE(_nbits)] 00029 00036 int bitmap_create(bitmap_t **bm, const int nbits); 00037 00043 int bitmap_destroy(bitmap_t *bm); 00044 00051 int bitmap_init(bitmap_t *bm, const int nbits); 00052 00060 int bitmap_is_set(const bitmap_t *bm, const int nbits, const int pos); 00061 00068 int bitmap_set(bitmap_t *bm, const int nbits, const int pos); 00069 00077 int bitmap_unset(bitmap_t *bm, const int nbits, const int pos); 00078 00085 int bitmap_clear(bitmap_t *bm, const int nbits); 00086 00093 int bitmap_is_empty(const bitmap_t *bm, const int nbits); 00094 00095 00102 int bitmap_first_bit(const bitmap_t *bm, const int nbits); 00103 00111 int bitmap_next_bit(const bitmap_t *bm, const int nbits, const int last); 00112 00119 int bitmap_count(const bitmap_t *bm, const int nbits); 00120 00121 #endif