~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_bitmap.h

  • Committer: Mark Atwood
  • Date: 2009-01-05 04:37:22 UTC
  • mto: (758.1.1 devel)
  • mto: This revision was merged to the branch mainline in revision 759.
  • Revision ID: me@mark.atwood.name-20090105043722-03l4mzcxi4yjjjih
replace sql_print_error etc with errmsg_print

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
  also be able to use 32 or 64 bits bitmaps very efficiently
27
27
*/
28
28
 
 
29
/// TODO: OMG FIX THIS
 
30
 
29
31
#include <mysys/my_bitmap.h>
 
32
#include <drizzled/util/test.h>
30
33
 
31
34
template <uint32_t default_width> class Bitmap
32
35
{
33
36
  MY_BITMAP map;
34
37
  uint32_t buffer[(default_width+31)/32];
35
38
public:
36
 
  Bitmap() { init(); }
37
 
  Bitmap(const Bitmap& from) { *this=from; }
38
 
  explicit Bitmap(uint32_t prefix_to_set) { init(prefix_to_set); }
 
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); }
39
42
  void init() { bitmap_init(&map, buffer, default_width, 0); }
40
43
  void init(uint32_t prefix_to_set) { init(); set_prefix(prefix_to_set); }
41
44
  uint32_t length() const { return default_width; }
161
164
{
162
165
  uint64_t map;
163
166
public:
164
 
  Bitmap<64>() { map= 0; }
165
 
  explicit Bitmap<64>(uint32_t prefix_to_set) { set_prefix(prefix_to_set); }
 
167
  Bitmap<64>() : map(0) { }
 
168
  explicit Bitmap<64>(uint32_t prefix_to_set) : map(0) { set_prefix(prefix_to_set); }
166
169
  void init() { }
167
170
  void init(uint32_t prefix_to_set) { set_prefix(prefix_to_set); }
168
171
  uint32_t length() const { return 64; }
194
197
};
195
198
 
196
199
 
197
 
/* An iterator to quickly walk over bits in unint64_t bitmap. */
198
 
class Table_map_iterator
199
 
{
200
 
  uint64_t bmp;
201
 
  uint32_t no;
202
 
public:
203
 
  Table_map_iterator(uint64_t t) : bmp(t), no(0) {}
204
 
  int next_bit()
205
 
  {
206
 
    static const char last_bit[16]= {32, 0, 1, 0, 
207
 
                                      2, 0, 1, 0, 
208
 
                                      3, 0, 1, 0,
209
 
                                      2, 0, 1, 0};
210
 
    uint32_t bit;
211
 
    while ((bit= last_bit[bmp & 0xF]) == 32)
212
 
    {
213
 
      no += 4;
214
 
      bmp= bmp >> 4;
215
 
      if (!bmp)
216
 
        return BITMAP_END;
217
 
    }
218
 
    bmp &= ~(1 << bit);
219
 
    return no + bit;
220
 
  }
221
 
  enum { BITMAP_END= 64 };
222
 
};
223
 
 
224
 
 
225
 
#if 0
226
 
void print_bits(table_map bmp)
227
 
{
228
 
  Table_map_iterator it(bmp);
229
 
  int i, first= 1;
230
 
  fprintf(stderr, "0x%llx = ", bmp);
231
 
  while ((i= it.next_bit()) != Table_map_iterator::BITMAP_END)
232
 
  {
233
 
    fprintf(stderr, " %s 2^%d", (first?"":"+"), i);
234
 
    if (first)
235
 
      first= 0;
236
 
  }
237
 
  fprintf(stderr, "\n");
238
 
}
239
 
 
240
 
int main()
241
 
{
242
 
  print_bits(1024);
243
 
  print_bits(3);
244
 
  print_bits(0xF);
245
 
  print_bits(0xF0);
246
 
  print_bits(35);
247
 
  print_bits(1LL<<63);
248
 
  print_bits(0);
249
 
  print_bits(-1LL);
250
 
}
 
200
typedef uint64_t table_map;          /* Used for table bits in join */
 
201
#if MAX_INDEXES <= 64
 
202
typedef Bitmap<64>  key_map;          /* Used for finding keys */
 
203
#else
 
204
typedef Bitmap<((MAX_INDEXES+7)/8*8)> key_map; /* Used for finding keys */
251
205
#endif
 
206
typedef uint32_t nesting_map;  /* Used for flags of nesting constructs */
 
207
 
 
208
/*
 
209
  Used to identify NESTED_JOIN structures within a join (applicable only to
 
210
  structures that have not been simplified away and embed more the one
 
211
  element)
 
212
*/
 
213
typedef uint64_t nested_join_map; /* Needed by sql_select.h and table.h */
 
214
 
 
215
/* useful constants */#
 
216
extern const key_map key_map_empty;
 
217
extern key_map key_map_full;          /* Should be threaded as const */
252
218
 
253
219
#endif /* _SQL_BITMAP_H_ */