26
26
also be able to use 32 or 64 bits bitmaps very efficiently
29
/// TODO: OMG FIX THIS
31
29
#include <mysys/my_bitmap.h>
30
#include <drizzled/definitions.h>
32
31
#include <drizzled/util/test.h>
34
template <uint32_t default_width> class Bitmap
37
uint32_t buffer[(default_width+31)/32];
39
Bitmap() : map() { init(); }
40
Bitmap(const Bitmap& from) : map() { *this=from; }
41
explicit Bitmap(uint32_t prefix_to_set) : map(0) { init(prefix_to_set); }
42
void init() { bitmap_init(&map, buffer, default_width, 0); }
43
void init(uint32_t prefix_to_set) { init(); set_prefix(prefix_to_set); }
44
uint32_t length() const { return default_width; }
45
Bitmap& operator=(const Bitmap& map2)
48
memcpy(buffer, map2.buffer, sizeof(buffer));
51
void set_bit(uint32_t n) { bitmap_set_bit(&map, n); }
52
void clear_bit(uint32_t n) { bitmap_clear_bit(&map, n); }
53
void set_prefix(uint32_t n) { bitmap_set_prefix(&map, n); }
54
void set_all() { bitmap_set_all(&map); }
55
void clear_all() { bitmap_clear_all(&map); }
56
void intersect(Bitmap& map2) { bitmap_intersect(&map, &map2.map); }
57
void intersect(uint64_t map2buff)
60
bitmap_init(&map2, (uint32_t *)&map2buff, sizeof(uint64_t)*8, 0);
61
bitmap_intersect(&map, &map2);
63
/* Use highest bit for all bits above sizeof(uint64_t)*8. */
64
void intersect_extended(uint64_t map2buff)
67
if (map.n_bits > sizeof(uint64_t) * 8)
68
bitmap_set_above(&map, sizeof(uint64_t),
69
test(map2buff & (1 << (sizeof(uint64_t) * 8 - 1))));
71
void subtract(Bitmap& map2) { bitmap_subtract(&map, &map2.map); }
72
void merge(Bitmap& map2) { bitmap_union(&map, &map2.map); }
73
bool is_set(uint32_t n) const { return bitmap_is_set(&map, n); }
74
bool is_set() const { return !bitmap_is_clear_all(&map); }
75
bool is_prefix(uint32_t n) const { return bitmap_is_prefix(&map, n); }
76
bool is_clear_all() const { return bitmap_is_clear_all(&map); }
77
bool is_set_all() const { return bitmap_is_set_all(&map); }
78
bool is_subset(const Bitmap& map2) const { return bitmap_is_subset(&map, &map2.map); }
79
bool operator==(const Bitmap& map2) const { return bitmap_cmp(&map, &map2.map); }
80
bool operator!=(const Bitmap& map2) const { return !bitmap_cmp(&map, &map2.map); }
81
Bitmap operator&=(uint32_t n)
83
if (bitmap_is_set(&map, n))
85
bitmap_clear_all(&map);
86
bitmap_set_bit(&map, n);
89
bitmap_clear_all(&map);
92
Bitmap operator&=(const Bitmap& map2)
94
bitmap_intersect(&map, &map2.map);
97
Bitmap operator&(uint32_t n)
103
Bitmap operator&(const Bitmap& map2)
109
Bitmap operator|=(uint32_t n)
111
bitmap_set_bit(&map, n);
114
Bitmap operator|=(const Bitmap& map2)
116
bitmap_union(&map, &map2.map);
118
Bitmap operator|(uint32_t n)
124
Bitmap operator|(const Bitmap& map2)
133
bitmap_invert(&bm.map);
136
char *print(char *buf) const
139
const unsigned char *e=(unsigned char *)buffer, *b=e+sizeof(buffer)-1;
142
if ((*s=_dig_vec_upper[*b >> 4]) != '0')
144
*s++=_dig_vec_upper[*b & 15];
147
*s++=_dig_vec_upper[*b >> 4];
148
*s++=_dig_vec_upper[*b & 15];
153
uint64_t to_uint64_t() const
155
if (sizeof(buffer) >= 8)
156
return uint8korr(buffer);
157
assert(sizeof(buffer) >= 4);
158
return (uint64_t) uint4korr(buffer);
162
template <> class Bitmap<64>
166
Bitmap<64>() : map(0) { }
167
explicit Bitmap<64>(uint32_t prefix_to_set) : map(0) { set_prefix(prefix_to_set); }
169
void init(uint32_t prefix_to_set) { set_prefix(prefix_to_set); }
170
uint32_t length() const { return 64; }
171
void set_bit(uint32_t n) { map|= ((uint64_t)1) << n; }
172
void clear_bit(uint32_t n) { map&= ~(((uint64_t)1) << n); }
173
void set_prefix(uint32_t n)
178
map= (((uint64_t)1) << n)-1;
180
void set_all() { map=~(uint64_t)0; }
181
void clear_all() { map=(uint64_t)0; }
182
void intersect(Bitmap<64>& map2) { map&= map2.map; }
183
void intersect(uint64_t map2) { map&= map2; }
184
void intersect_extended(uint64_t map2) { map&= map2; }
185
void subtract(Bitmap<64>& map2) { map&= ~map2.map; }
186
void merge(Bitmap<64>& map2) { map|= map2.map; }
187
bool is_set(uint32_t n) const { return test(map & (((uint64_t)1) << n)); }
188
bool is_prefix(uint32_t n) const { return map == (((uint64_t)1) << n)-1; }
189
bool is_clear_all() const { return map == (uint64_t)0; }
190
bool is_set_all() const { return map == ~(uint64_t)0; }
191
bool is_subset(const Bitmap<64>& map2) const { return !(map & ~map2.map); }
192
bool is_overlapping(const Bitmap<64>& map2) const { return (map & map2.map)!= 0; }
193
bool operator==(const Bitmap<64>& map2) const { return map == map2.map; }
194
char *print(char *buf) const { int64_t2str(map,buf,16); return buf; }
195
uint64_t to_uint64_t() const { return map; }
32
#include <drizzled/key_map.h>
199
38
typedef uint64_t table_map; /* Used for table bits in join */
200
#if MAX_INDEXES <= 64
201
typedef Bitmap<64> key_map; /* Used for finding keys */
203
typedef Bitmap<((MAX_INDEXES+7)/8*8)> key_map; /* Used for finding keys */
205
39
typedef uint32_t nesting_map; /* Used for flags of nesting constructs */