Example how to use bvector<> to set bits and then retrieve indexes of ON bits.
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()
-
bm::bvector<>::swap()
#include <cassert>
#include <iostream>
using namespace std;
{
try
{
cout <<
"1. bitcount: " << bv.
count() << endl;
cout <<
"2. bitcount: " << bv.
count() << endl;
do
{
cout << value;
if (value)
{
cout << ",";
}
else
{
break;
}
} while(1);
cout << endl;
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;
cout <<
"6. 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.
bool test(size_type n) const BMNOEXCEPT
returns true if bit n is set and false is bit n is 0.
size_type count() const BMNOEXCEPT
population count (count of ON bits)
bvector< Alloc > & set(size_type n, bool val=true)
Sets bit n if val is true, clears bit n if val is false.
size_type get_next(size_type prev) const BMNOEXCEPT
Finds the number of the next bit ON.
void swap(bvector< Alloc > &bvect) BMNOEXCEPT
Exchanges content of bv and this bvector.
size_type get_first() const BMNOEXCEPT
find first 1 bit in vector. Function may return 0 and this requires an extra check if bit 0 is actual...
void clear(const size_type *ids, size_type ids_size, bm::sort_order so=bm::BM_UNKNOWN)
clear list of bits in this bitset