Example how to use bvector<> to set bits and then retrieve indexes of ON bits
- See also
- bm::bvector<>::get_next()
-
bm::bvector<>::get_first()
-
bm::bvector<>::set()
-
bm::bvector<>::count()
-
bm::bvector<>::clear()
#include <iostream>
using namespace std;
{
try
{
cout <<
"1. bitcount: " << bv.
count() << endl;
bv.set(10);
bv.set(100);
bv.set(1000000);
cout << "2. bitcount: " << bv.count() << endl;
auto value = bv.get_first();
do
{
cout << value;
value = bv.get_next(value);
if (value)
{
cout << ",";
}
else
{
break;
}
} while(1);
cout << endl;
bv.clear();
cout << "3. bitcount: " << bv.count() << endl;
bv[10] = true;
bv[100] = true;
bv[10000] = true;
cout << "4. bitcount: " << bv.count() << endl;
if (bv[10])
{
bv[10] = false;
}
cout << "5. bitcount: " << bv.count() << endl;
}
catch(std::exception& ex)
{
std::cerr << ex.what() << std::endl;
return 1;
}
return 0;
}
Compressed bit-vector bvector<> container, set algebraic methods, traversal iterators.
pre-processor un-defines to avoid global space pollution (internal)
Bitvector Bit-vector container with runtime compression of bits.
size_type count() const BMNOEXCEPT
population count (count of ON bits)