diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/my_bitmap.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/include/my_bitmap.h b/include/my_bitmap.h index ab69b2d671d..78642df3362 100644 --- a/include/my_bitmap.h +++ b/include/my_bitmap.h @@ -159,6 +159,22 @@ static inline my_bool bitmap_cmp(const MY_BITMAP *map1, const MY_BITMAP *map2) #define bitmap_set_all(MAP) \ (memset((MAP)->bitmap, 0xFF, 4*no_words_in_map((MAP)))) +/** + check, set and clear a bit of interest of an integer. + + If the bit is out of range @retval -1. Otherwise + bit_is_set @return 0 or 1 reflecting the bit is set or not; + bit_do_set @return 1 (bit is set 1) + bit_do_clear @return 0 (bit is cleared to 0) +*/ + +#define bit_is_set(I,B) (sizeof(I) * CHAR_BIT > (B) ? \ + (((I) & (ULL(1) << (B))) == 0 ? 0 : 1) : -1) +#define bit_do_set(I,B) (sizeof(I) * CHAR_BIT > (B) ? \ + ((I) |= (ULL(1) << (B)), 1) : -1) +#define bit_do_clear(I,B) (sizeof(I) * CHAR_BIT > (B) ? \ + ((I) &= ~(ULL(1) << (B)), 0) : -1) + #ifdef __cplusplus } #endif |