29
29
#include <mysys/my_bitmap.h>
31
template <uint32_t default_width> class Bitmap
34
uint32_t buffer[(default_width+31)/32];
37
Bitmap(const Bitmap& from) { *this=from; }
38
explicit Bitmap(uint32_t prefix_to_set) { init(prefix_to_set); }
39
void init() { bitmap_init(&map, buffer, default_width, 0); }
40
void init(uint32_t prefix_to_set) { init(); set_prefix(prefix_to_set); }
41
uint32_t length() const { return default_width; }
42
Bitmap& operator=(const Bitmap& map2)
45
memcpy(buffer, map2.buffer, sizeof(buffer));
48
void set_bit(uint32_t n) { bitmap_set_bit(&map, n); }
49
void clear_bit(uint32_t n) { bitmap_clear_bit(&map, n); }
50
void set_prefix(uint32_t n) { bitmap_set_prefix(&map, n); }
51
void set_all() { bitmap_set_all(&map); }
52
void clear_all() { bitmap_clear_all(&map); }
53
void intersect(Bitmap& map2) { bitmap_intersect(&map, &map2.map); }
54
void intersect(uint64_t map2buff)
57
bitmap_init(&map2, (uint32_t *)&map2buff, sizeof(uint64_t)*8, 0);
58
bitmap_intersect(&map, &map2);
60
/* Use highest bit for all bits above sizeof(uint64_t)*8. */
61
void intersect_extended(uint64_t map2buff)
64
if (map.n_bits > sizeof(uint64_t) * 8)
65
bitmap_set_above(&map, sizeof(uint64_t),
66
test(map2buff & (1 << (sizeof(uint64_t) * 8 - 1))));
68
void subtract(Bitmap& map2) { bitmap_subtract(&map, &map2.map); }
69
void merge(Bitmap& map2) { bitmap_union(&map, &map2.map); }
70
bool is_set(uint32_t n) const { return bitmap_is_set(&map, n); }
71
bool is_set() const { return !bitmap_is_clear_all(&map); }
72
bool is_prefix(uint32_t n) const { return bitmap_is_prefix(&map, n); }
73
bool is_clear_all() const { return bitmap_is_clear_all(&map); }
74
bool is_set_all() const { return bitmap_is_set_all(&map); }
75
bool is_subset(const Bitmap& map2) const { return bitmap_is_subset(&map, &map2.map); }
76
bool is_overlapping(const Bitmap& map2) const { return bitmap_is_overlapping(&map, &map2.map); }
77
bool operator==(const Bitmap& map2) const { return bitmap_cmp(&map, &map2.map); }
78
bool operator!=(const Bitmap& map2) const { return !bitmap_cmp(&map, &map2.map); }
79
Bitmap operator&=(uint32_t n)
81
if (bitmap_is_set(&map, n))
83
bitmap_clear_all(&map);
84
bitmap_set_bit(&map, n);
87
bitmap_clear_all(&map);
90
Bitmap operator&=(const Bitmap& map2)
92
bitmap_intersect(&map, &map2.map);
95
Bitmap operator&(uint32_t n)
101
Bitmap operator&(const Bitmap& map2)
107
Bitmap operator|=(uint32_t n)
109
bitmap_set_bit(&map, n);
112
Bitmap operator|=(const Bitmap& map2)
114
bitmap_union(&map, &map2.map);
116
Bitmap operator|(uint32_t n)
122
Bitmap operator|(const Bitmap& map2)
131
bitmap_invert(&bm.map);
134
char *print(char *buf) const
137
const unsigned char *e=(unsigned char *)buffer, *b=e+sizeof(buffer)-1;
140
if ((*s=_dig_vec_upper[*b >> 4]) != '0')
142
*s++=_dig_vec_upper[*b & 15];
145
*s++=_dig_vec_upper[*b >> 4];
146
*s++=_dig_vec_upper[*b & 15];
151
uint64_t to_uint64_t() const
153
if (sizeof(buffer) >= 8)
154
return uint8korr(buffer);
155
assert(sizeof(buffer) >= 4);
156
return (uint64_t) uint4korr(buffer);
160
template <> class Bitmap<64>
164
Bitmap<64>() { map= 0; }
165
explicit Bitmap<64>(uint32_t prefix_to_set) { set_prefix(prefix_to_set); }
167
void init(uint32_t prefix_to_set) { set_prefix(prefix_to_set); }
168
uint32_t length() const { return 64; }
169
void set_bit(uint32_t n) { map|= ((uint64_t)1) << n; }
170
void clear_bit(uint32_t n) { map&= ~(((uint64_t)1) << n); }
171
void set_prefix(uint32_t n)
176
map= (((uint64_t)1) << n)-1;
178
void set_all() { map=~(uint64_t)0; }
179
void clear_all() { map=(uint64_t)0; }
180
void intersect(Bitmap<64>& map2) { map&= map2.map; }
181
void intersect(uint64_t map2) { map&= map2; }
182
void intersect_extended(uint64_t map2) { map&= map2; }
183
void subtract(Bitmap<64>& map2) { map&= ~map2.map; }
184
void merge(Bitmap<64>& map2) { map|= map2.map; }
185
bool is_set(uint32_t n) const { return test(map & (((uint64_t)1) << n)); }
186
bool is_prefix(uint32_t n) const { return map == (((uint64_t)1) << n)-1; }
187
bool is_clear_all() const { return map == (uint64_t)0; }
188
bool is_set_all() const { return map == ~(uint64_t)0; }
189
bool is_subset(const Bitmap<64>& map2) const { return !(map & ~map2.map); }
190
bool is_overlapping(const Bitmap<64>& map2) const { return (map & map2.map)!= 0; }
191
bool operator==(const Bitmap<64>& map2) const { return map == map2.map; }
192
char *print(char *buf) const { int64_t2str(map,buf,16); return buf; }
193
uint64_t to_uint64_t() const { return map; }
197
/* An iterator to quickly walk over bits in unint64_t bitmap. */
198
class Table_map_iterator
203
Table_map_iterator(uint64_t t) : bmp(t), no(0) {}
206
static const char last_bit[16]= {32, 0, 1, 0,
211
while ((bit= last_bit[bmp & 0xF]) == 32)
221
enum { BITMAP_END= 64 };
226
void print_bits(table_map bmp)
228
Table_map_iterator it(bmp);
230
fprintf(stderr, "0x%llx = ", bmp);
231
while ((i= it.next_bit()) != Table_map_iterator::BITMAP_END)
233
fprintf(stderr, " %s 2^%d", (first?"":"+"), i);
237
fprintf(stderr, "\n");
30
#include <drizzled/definitions.h>
31
#include <drizzled/util/test.h>
32
#include <drizzled/key_map.h>
35
typedef uint64_t table_map; /* Used for table bits in join */
36
typedef uint32_t nesting_map; /* Used for flags of nesting constructs */
39
Used to identify NESTED_JOIN structures within a join (applicable only to
40
structures that have not been simplified away and embed more the one
43
typedef uint64_t nested_join_map; /* Needed by sql_select.h and table.h */
253
45
#endif /* _SQL_BITMAP_H_ */