summaryrefslogtreecommitdiff
path: root/sql/sql_bitmap.h
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_bitmap.h')
-rw-r--r--sql/sql_bitmap.h63
1 files changed, 48 insertions, 15 deletions
diff --git a/sql/sql_bitmap.h b/sql/sql_bitmap.h
index 54a207c8adf..cd3442d306c 100644
--- a/sql/sql_bitmap.h
+++ b/sql/sql_bitmap.h
@@ -64,13 +64,13 @@ public:
}
void subtract(Bitmap& map2) { bitmap_subtract(&map, &map2.map); }
void merge(Bitmap& map2) { bitmap_union(&map, &map2.map); }
- my_bool is_set(uint n) const { return bitmap_is_set(&map, n); }
- my_bool is_prefix(uint n) const { return bitmap_is_prefix(&map, n); }
- my_bool is_clear_all() const { return bitmap_is_clear_all(&map); }
- my_bool is_set_all() const { return bitmap_is_set_all(&map); }
- my_bool is_subset(const Bitmap& map2) const { return bitmap_is_subset(&map, &map2.map); }
- my_bool is_overlapping(const Bitmap& map2) const { return bitmap_is_overlapping(&map, &map2.map); }
- my_bool operator==(const Bitmap& map2) const { return bitmap_cmp(&map, &map2.map); }
+ bool is_set(uint n) const { return bitmap_is_set(&map, n); }
+ bool is_prefix(uint n) const { return bitmap_is_prefix(&map, n); }
+ bool is_clear_all() const { return bitmap_is_clear_all(&map); }
+ bool is_set_all() const { return bitmap_is_set_all(&map); }
+ bool is_subset(const Bitmap& map2) const { return bitmap_is_subset(&map, &map2.map); }
+ bool is_overlapping(const Bitmap& map2) const { return bitmap_is_overlapping(&map, &map2.map); }
+ bool operator==(const Bitmap& map2) const { return bitmap_cmp(&map, &map2.map); }
char *print(char *buf) const
{
char *s=buf;
@@ -97,6 +97,34 @@ public:
}
};
+/* An iterator to quickly walk over bits in unlonglong bitmap. */
+class Table_map_iterator
+{
+ ulonglong bmp;
+ uint no;
+public:
+ Table_map_iterator(ulonglong t) : bmp(t), no(0) {}
+ int next_bit()
+ {
+ static const char last_bit[16]= {32, 0, 1, 0,
+ 2, 0, 1, 0,
+ 3, 0, 1, 0,
+ 2, 0, 1, 0};
+ uint bit;
+ while ((bit= last_bit[bmp & 0xF]) == 32)
+ {
+ no += 4;
+ bmp= bmp >> 4;
+ if (!bmp)
+ return BITMAP_END;
+ }
+ bmp &= ~(1LL << bit);
+ return no + bit;
+ }
+ int operator++(int) { return next_bit(); }
+ enum { BITMAP_END= 64 };
+};
+
template <> class Bitmap<64>
{
ulonglong map;
@@ -122,15 +150,20 @@ public:
void intersect_extended(ulonglong map2) { map&= map2; }
void subtract(Bitmap<64>& map2) { map&= ~map2.map; }
void merge(Bitmap<64>& map2) { map|= map2.map; }
- my_bool is_set(uint n) const { return test(map & (((ulonglong)1) << n)); }
- my_bool is_prefix(uint n) const { return map == (((ulonglong)1) << n)-1; }
- my_bool is_clear_all() const { return map == (ulonglong)0; }
- my_bool is_set_all() const { return map == ~(ulonglong)0; }
- my_bool is_subset(const Bitmap<64>& map2) const { return !(map & ~map2.map); }
- my_bool is_overlapping(const Bitmap<64>& map2) const { return (map & map2.map)!= 0; }
- my_bool operator==(const Bitmap<64>& map2) const { return map == map2.map; }
- char *print(char *buf) const { longlong2str(map,buf,16); return buf; }
+ bool is_set(uint n) const { return test(map & (((ulonglong)1) << n)); }
+ bool is_prefix(uint n) const { return map == (((ulonglong)1) << n)-1; }
+ bool is_clear_all() const { return map == (ulonglong)0; }
+ bool is_set_all() const { return map == ~(ulonglong)0; }
+ bool is_subset(const Bitmap<64>& map2) const { return !(map & ~map2.map); }
+ bool is_overlapping(const Bitmap<64>& map2) const { return (map & map2.map)!= 0; }
+ bool operator==(const Bitmap<64>& map2) const { return map == map2.map; }
+ char *print(char *buf) const { longlong2str(map,buf,16,1); return buf; }
ulonglong to_ulonglong() const { return map; }
+ class Iterator : public Table_map_iterator
+ {
+ public:
+ Iterator(Bitmap<64> &bmp) : Table_map_iterator(bmp.map) {}
+ };
};