#include <iostream>
#include "bm.h"
#include "bmundef.h"
using namespace std;
static
void print_bvector(const bm::bvector<>& bv)
{
bm::bvector<>::size_type value = bv.get_first();
do
{
cout << value;
value = bv.get_next(value);
if (value)
{
cout << ",";
}
else
{
break;
}
} while(1);
cout << endl;
}
int main(void)
{
try
{
bm::bvector<> bv1;
bm::bvector<> bv2;
bm::bvector<> bv3;
bv1.set(10);
bv1.set(100);
bv1.set(1000000);
bv2.set(10);
bv2.set(100);
bv3 = bv1 & bv2;
print_bvector(bv3);
bv2 &= bv1; print_bvector(bv2);
bv3 = bv1 | bv2;
print_bvector(bv3);
bv2 |= bv1; print_bvector(bv2);
bv1.set(1000000, false);
bv3 = bv2 - bv1;
print_bvector(bv3);
bv2 -= bv1; print_bvector(bv2);
bv3 = bv2 ^ bv1;
print_bvector(bv3);
{
bm::bvector<>::size_type pos;
bool f = bv3.find(pos);
if (f)
{
cout << "XOR mismatch position = " << pos << endl;
}
f = bv2.find_first_mismatch(bv1, pos);
if (f)
{
cout << "search mismatch position = " << pos << endl;
}
}
bv2 ^= bv1; print_bvector(bv2);
if (bv2 == bv3)
{
cerr << "Equivalent. Comparison result = "
<< bv2.compare(bv3) << endl;
}
else
{
cout << "Error." << endl;
return 1;
}
}
catch(std::exception& ex)
{
std::cerr << ex.what() << std::endl;
}
return 0;
}