Example for finding first and last bits in bit-vector (dynamic range).Ranges of bit-vectors can be used to find probability of intersection. For instance, in some corner cases AND product can be predicted empty if vectors belong to different ranges.
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <cassert>
using namespace std;
static
{
unsigned start =
MAX_VALUE / (unsigned)(rand()%10);
{
if ((rand() % 10))
{
}
}
}
{
try
{
cout <<
"bv1 count = " << bv1.
count() << endl;
cout <<
"bv2 count = " << bv2.
count() << endl;
bool found;
if (found)
cout << "bv1 first = " << first << endl;
found = bv1.
find(first, pos);
assert (found);
{
cout << "bv1 pos = " << pos << endl;
assert(pos == first);
}
found = bv1.
find(first+1, second);
assert (found);
{
cout << "bv1 second = " << second << endl;
assert(second > first);
assert(bv1.
test(second));
}
if (found)
cout << "bv1 last = " << last << endl;
if (found)
cout << "bv2 first = " << first << endl;
if (found)
cout << "bv2 last = " << last << endl;
if (found)
cout << "bv1 range = [" << first << ", " << last << "]" << endl;
if (found)
cout << "bv2 range = [" << first << ", " << last << "]" << 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 find(size_type &pos) const BMNOEXCEPT
Finds index of first 1 bit.
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)
bool find_range(size_type &first, size_type &last) const BMNOEXCEPT
Finds dynamic range of bit-vector [first, last].
bvector< Alloc > & set(size_type n, bool val=true)
Sets bit n if val is true, clears bit n if val is false.
bvector_size_type size_type
bool find_reverse(size_type &pos) const BMNOEXCEPT
Finds last index of 1 bit.
static void fill_bvector(bm::bvector<> *bv)