~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to include/my_bitmap.h

Removed/replaced DBUG symbols and standardized TRUE/FALSE

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
#define MY_BIT_NONE (~(uint) 0)
20
20
 
21
 
#include <mystrings/m_string.h>
 
21
#include <m_string.h>
22
22
 
23
 
typedef uint32_t my_bitmap_map;
 
23
typedef uint32 my_bitmap_map;
24
24
 
25
25
typedef struct st_bitmap
26
26
{
27
27
  my_bitmap_map *bitmap;
28
 
  uint32_t n_bits; /* number of bits occupied by the above */
 
28
  uint n_bits; /* number of bits occupied by the above */
29
29
  my_bitmap_map last_word_mask;
30
30
  my_bitmap_map *last_word_ptr;
31
31
  /*
40
40
extern "C" {
41
41
#endif
42
42
extern void create_last_word_mask(MY_BITMAP *map);
43
 
extern bool bitmap_init(MY_BITMAP *map, my_bitmap_map *buf, uint32_t n_bits,
44
 
                           bool thread_safe);
45
 
extern bool bitmap_is_clear_all(const MY_BITMAP *map);
46
 
extern bool bitmap_is_prefix(const MY_BITMAP *map, uint32_t prefix_size);
47
 
extern bool bitmap_is_set_all(const MY_BITMAP *map);
48
 
extern bool bitmap_is_subset(const MY_BITMAP *map1, const MY_BITMAP *map2);
49
 
extern bool bitmap_is_overlapping(const MY_BITMAP *map1,
 
43
extern my_bool bitmap_init(MY_BITMAP *map, my_bitmap_map *buf, uint n_bits,
 
44
                           my_bool thread_safe);
 
45
extern my_bool bitmap_is_clear_all(const MY_BITMAP *map);
 
46
extern my_bool bitmap_is_prefix(const MY_BITMAP *map, uint prefix_size);
 
47
extern my_bool bitmap_is_set_all(const MY_BITMAP *map);
 
48
extern my_bool bitmap_is_subset(const MY_BITMAP *map1, const MY_BITMAP *map2);
 
49
extern my_bool bitmap_is_overlapping(const MY_BITMAP *map1,
50
50
                                     const MY_BITMAP *map2);
51
 
extern bool bitmap_test_and_set(MY_BITMAP *map, uint32_t bitmap_bit);
52
 
extern bool bitmap_test_and_clear(MY_BITMAP *map, uint32_t bitmap_bit);
53
 
extern bool bitmap_fast_test_and_clear(MY_BITMAP *map, uint32_t bitmap_bit);
54
 
extern bool bitmap_fast_test_and_set(MY_BITMAP *map, uint32_t bitmap_bit);
55
 
extern uint32_t bitmap_set_next(MY_BITMAP *map);
56
 
extern uint32_t bitmap_get_first(const MY_BITMAP *map);
57
 
extern uint32_t bitmap_get_first_set(const MY_BITMAP *map);
58
 
extern uint32_t bitmap_bits_set(const MY_BITMAP *map);
 
51
extern my_bool bitmap_test_and_set(MY_BITMAP *map, uint bitmap_bit);
 
52
extern my_bool bitmap_test_and_clear(MY_BITMAP *map, uint bitmap_bit);
 
53
extern my_bool bitmap_fast_test_and_clear(MY_BITMAP *map, uint bitmap_bit);
 
54
extern my_bool bitmap_fast_test_and_set(MY_BITMAP *map, uint bitmap_bit);
 
55
extern uint bitmap_set_next(MY_BITMAP *map);
 
56
extern uint bitmap_get_first(const MY_BITMAP *map);
 
57
extern uint bitmap_get_first_set(const MY_BITMAP *map);
 
58
extern uint bitmap_bits_set(const MY_BITMAP *map);
59
59
extern void bitmap_free(MY_BITMAP *map);
60
 
extern void bitmap_set_above(MY_BITMAP *map, uint32_t from_byte, uint32_t use_bit);
61
 
extern void bitmap_set_prefix(MY_BITMAP *map, uint32_t prefix_size);
 
60
extern void bitmap_set_above(MY_BITMAP *map, uint from_byte, uint use_bit);
 
61
extern void bitmap_set_prefix(MY_BITMAP *map, uint prefix_size);
62
62
extern void bitmap_intersect(MY_BITMAP *map, const MY_BITMAP *map2);
63
63
extern void bitmap_subtract(MY_BITMAP *map, const MY_BITMAP *map2);
64
64
extern void bitmap_union(MY_BITMAP *map, const MY_BITMAP *map2);
66
66
extern void bitmap_invert(MY_BITMAP *map);
67
67
extern void bitmap_copy(MY_BITMAP *map, const MY_BITMAP *map2);
68
68
 
69
 
extern uint32_t bitmap_lock_set_next(MY_BITMAP *map);
70
 
extern void bitmap_lock_clear_bit(MY_BITMAP *map, uint32_t bitmap_bit);
 
69
extern uint bitmap_lock_set_next(MY_BITMAP *map);
 
70
extern void bitmap_lock_clear_bit(MY_BITMAP *map, uint bitmap_bit);
71
71
#ifdef NOT_USED
72
 
extern uint32_t bitmap_lock_bits_set(const MY_BITMAP *map);
73
 
extern bool bitmap_lock_is_set_all(const MY_BITMAP *map);
74
 
extern uint32_t bitmap_lock_get_first(const MY_BITMAP *map);
75
 
extern uint32_t bitmap_lock_get_first_set(const MY_BITMAP *map);
76
 
extern bool bitmap_lock_is_subset(const MY_BITMAP *map1,
 
72
extern uint bitmap_lock_bits_set(const MY_BITMAP *map);
 
73
extern my_bool bitmap_lock_is_set_all(const MY_BITMAP *map);
 
74
extern uint bitmap_lock_get_first(const MY_BITMAP *map);
 
75
extern uint bitmap_lock_get_first_set(const MY_BITMAP *map);
 
76
extern my_bool bitmap_lock_is_subset(const MY_BITMAP *map1,
77
77
                                     const MY_BITMAP *map2);
78
 
extern bool bitmap_lock_is_prefix(const MY_BITMAP *map, uint32_t prefix_size);
79
 
extern bool bitmap_lock_is_set(const MY_BITMAP *map, uint32_t bitmap_bit);
80
 
extern bool bitmap_lock_is_clear_all(const MY_BITMAP *map);
81
 
extern bool bitmap_lock_cmp(const MY_BITMAP *map1, const MY_BITMAP *map2);
 
78
extern my_bool bitmap_lock_is_prefix(const MY_BITMAP *map, uint prefix_size);
 
79
extern my_bool bitmap_lock_is_set(const MY_BITMAP *map, uint bitmap_bit);
 
80
extern my_bool bitmap_lock_is_clear_all(const MY_BITMAP *map);
 
81
extern my_bool bitmap_lock_cmp(const MY_BITMAP *map1, const MY_BITMAP *map2);
82
82
extern void bitmap_lock_set_all(MY_BITMAP *map);
83
83
extern void bitmap_lock_clear_all(MY_BITMAP *map);
84
 
extern void bitmap_lock_set_bit(MY_BITMAP *map, uint32_t bitmap_bit);
85
 
extern void bitmap_lock_flip_bit(MY_BITMAP *map, uint32_t bitmap_bit);
86
 
extern void bitmap_lock_set_prefix(MY_BITMAP *map, uint32_t prefix_size);
 
84
extern void bitmap_lock_set_bit(MY_BITMAP *map, uint bitmap_bit);
 
85
extern void bitmap_lock_flip_bit(MY_BITMAP *map, uint bitmap_bit);
 
86
extern void bitmap_lock_set_prefix(MY_BITMAP *map, uint prefix_size);
87
87
extern void bitmap_lock_intersect(MY_BITMAP *map, const MY_BITMAP *map2);
88
88
extern void bitmap_lock_subtract(MY_BITMAP *map, const MY_BITMAP *map2);
89
89
extern void bitmap_lock_union(MY_BITMAP *map, const MY_BITMAP *map2);
95
95
#define no_bytes_in_map(map) (((map)->n_bits + 7)/8)
96
96
#define no_words_in_map(map) (((map)->n_bits + 31)/32)
97
97
#define bytes_word_aligned(bytes) (4*((bytes + 3)/4))
98
 
#define _bitmap_set_bit(MAP, BIT) (((unsigned char*)(MAP)->bitmap)[(BIT) / 8] \
 
98
#define _bitmap_set_bit(MAP, BIT) (((uchar*)(MAP)->bitmap)[(BIT) / 8] \
99
99
                                  |= (1 << ((BIT) & 7)))
100
 
#define _bitmap_flip_bit(MAP, BIT) (((unsigned char*)(MAP)->bitmap)[(BIT) / 8] \
 
100
#define _bitmap_flip_bit(MAP, BIT) (((uchar*)(MAP)->bitmap)[(BIT) / 8] \
101
101
                                  ^= (1 << ((BIT) & 7)))
102
 
#define _bitmap_clear_bit(MAP, BIT) (((unsigned char*)(MAP)->bitmap)[(BIT) / 8] \
 
102
#define _bitmap_clear_bit(MAP, BIT) (((uchar*)(MAP)->bitmap)[(BIT) / 8] \
103
103
                                  &= ~ (1 << ((BIT) & 7)))
104
 
#define _bitmap_is_set(MAP, BIT) (uint) (((unsigned char*)(MAP)->bitmap)[(BIT) / 8] \
 
104
#define _bitmap_is_set(MAP, BIT) (uint) (((uchar*)(MAP)->bitmap)[(BIT) / 8] \
105
105
                                         & (1 << ((BIT) & 7)))
106
106
/*
 
107
  WARNING!
 
108
 
 
109
  The below symbols are inline functions in DEBUG builds and macros in
 
110
  non-DEBUG builds. The latter evaluate their 'bit' argument twice.
 
111
 
107
112
  NEVER use an increment/decrement operator with the 'bit' argument.
 
113
  It would work with DEBUG builds, but fails later in production builds!
108
114
 
109
115
  FORBIDDEN: bitmap_set_bit($my_bitmap, (field++)->field_index);
110
116
*/
 
117
#ifndef DBUG_OFF
 
118
static inline void
 
119
bitmap_set_bit(MY_BITMAP *map,uint bit)
 
120
{
 
121
  DBUG_ASSERT(bit < (map)->n_bits);
 
122
  _bitmap_set_bit(map,bit);
 
123
}
 
124
static inline void
 
125
bitmap_flip_bit(MY_BITMAP *map,uint bit)
 
126
{
 
127
  DBUG_ASSERT(bit < (map)->n_bits);
 
128
  _bitmap_flip_bit(map,bit);
 
129
}
 
130
static inline void
 
131
bitmap_clear_bit(MY_BITMAP *map,uint bit)
 
132
{
 
133
  DBUG_ASSERT(bit < (map)->n_bits);
 
134
  _bitmap_clear_bit(map,bit);
 
135
}
 
136
static inline uint
 
137
bitmap_is_set(const MY_BITMAP *map,uint bit)
 
138
{
 
139
  DBUG_ASSERT(bit < (map)->n_bits);
 
140
  return _bitmap_is_set(map,bit);
 
141
}
 
142
#else
111
143
#define bitmap_set_bit(MAP, BIT) _bitmap_set_bit(MAP, BIT)
112
144
#define bitmap_flip_bit(MAP, BIT) _bitmap_flip_bit(MAP, BIT)
113
145
#define bitmap_clear_bit(MAP, BIT) _bitmap_clear_bit(MAP, BIT)
114
146
#define bitmap_is_set(MAP, BIT) _bitmap_is_set(MAP, BIT)
 
147
#endif
115
148
 
116
 
static inline bool bitmap_cmp(const MY_BITMAP *map1, const MY_BITMAP *map2)
 
149
static inline my_bool bitmap_cmp(const MY_BITMAP *map1, const MY_BITMAP *map2)
117
150
{
118
151
  *(map1)->last_word_ptr|= (map1)->last_word_mask;
119
152
  *(map2)->last_word_ptr|= (map2)->last_word_mask;
135
168
*/
136
169
 
137
170
#define bit_is_set(I,B)   (sizeof(I) * CHAR_BIT > (B) ?                 \
138
 
                           (((I) & (1UL << (B))) == 0 ? 0 : 1) : -1)
 
171
                           (((I) & (1ULL << (B))) == 0 ? 0 : 1) : -1)
139
172
#define bit_do_set(I,B)   (sizeof(I) * CHAR_BIT > (B) ?         \
140
 
                           ((I) |= (1UL << (B)), 1) : -1)
 
173
                           ((I) |= (1ULL << (B)), 1) : -1)
141
174
#define bit_do_clear(I,B) (sizeof(I) * CHAR_BIT > (B) ?         \
142
 
                           ((I) &= ~(1UL << (B)), 0) : -1)
 
175
                           ((I) &= ~(1ULL << (B)), 0) : -1)
143
176
 
144
177
#ifdef  __cplusplus
145
178
}