18 #ifndef NDB_SPARSE_BITMASK_H
19 #define NDB_SPARSE_BITMASK_H
21 #include <ndb_global.h>
22 #include <util/Vector.hpp>
23 #include <util/BaseString.hpp>
30 STATIC_CONST( NotFound = (
unsigned)-1 );
32 SparseBitmask(
unsigned max_size = NotFound - 1) : m_max_size(max_size) {}
34 unsigned max_size()
const {
return m_max_size; }
37 void set(
unsigned n) {
38 assert(
n <= m_max_size);
40 unsigned i = m_vec.size();
43 const unsigned j = m_vec[i-1];
56 bool get(
unsigned n)
const {
57 assert(
n <= m_max_size);
59 for (
unsigned i = 0;
i < m_vec.size();
i++)
61 const unsigned j = m_vec[
i];
71 int clear(
unsigned n) {
72 assert(n <= m_max_size);
73 for (
unsigned i = 0;
i < m_vec.size();
i++)
75 const unsigned j = m_vec[
i];
91 unsigned find(
unsigned n)
const {
92 for (
unsigned i = 0;
i < m_vec.size();
i++)
94 const unsigned j = m_vec[
i];
102 unsigned count()
const {
return m_vec.size(); }
104 bool isclear()
const {
return count() == 0; }
106 unsigned getBitNo(
unsigned n)
const {
107 assert(n < m_vec.size());
111 void print(
void)
const {
112 for (
unsigned i = 0;
i < m_vec.size();
i++)
114 const unsigned j = m_vec[
i];
115 printf(
"[%u]: %u\n",
i, j);
120 if (obj.count() != count())
123 for (
unsigned i = 0;
i<count();
i++)
124 if (!obj.get(m_vec[
i]))
131 for (
unsigned i = 0;
i<count();
i++)
132 if (!obj.get(m_vec[
i]))
135 for (
unsigned i = 0; i<obj.count(); i++)
136 if (!
get(obj.getBitNo(i)))
144 for (
unsigned i = 0;
i<m_vec.size();
i++)
146 tmp.
appfmt(
"%s%u", sep, m_vec[
i]);