#include <iostream>
#include <assert.h>
#include "bm.h"
#include "bmserial.h"
#include "bmintervals.h"
#include "bmundef.h"
using namespace std;
template<class T> void PrintContainer(T first, T last)
{
if (first == last)
cout << "<EMPTY SET>";
else
for(;first != last; ++first)
cout << *first << ", ";
cout << endl;
}
int main(void)
{
try
{
bm::bvector<> bv(bm::BM_GAP);
bv.set_range(100, 110);
bv.optimize();
cout << "Source set:";
PrintContainer(bv.first(), bv.end());
cout << "bvector<>::is_all_one_range() demo" << endl;
bool all_one = bv.is_all_one_range(100, 110); cout << all_one << endl;
all_one = bv.is_all_one_range(100, 111); cout << all_one << endl;
cout << "bvector<>::is_interval() demo" << endl;
bool is_int = bm::is_interval(bv, 100, 110); cout << is_int << endl;
is_int = bm::is_interval(bv, 99, 110); cout << is_int << endl;
cout << "bvector<>::any_range() demo" << endl;
bool any_one = bv.any_range(0, 99); cout << any_one << endl;
any_one = bv.any_range(0, 100); cout << any_one << endl;
cout << "bvector<>::find_reverse() demo" << endl;
bm::bvector<>::size_type pos;
bool found = bv.find_reverse(256, pos);
assert(found);
cout << pos << endl;
cout << "bvector<>::find_interval demo" << endl;
found = bm::find_interval_end(bv, 100, pos);
if (found)
cout << pos << endl; else
cout << "Not found." << endl;
found = bm::find_interval_end(bv, 99, pos);
if (found)
cout << pos << endl;
else
cout << "Not found." << endl;
found = bm::find_interval_start(bv, 105, pos);
if (found)
cout << pos << endl; else
cout << "Not found." << endl;
bm::bvector<> bv3(bv);
cout << endl;
bm::bvector<> bv2;
bv2.copy_range(bv, 101, 105);
bv.clear_range(99, 100); PrintContainer(bv.first(), bv.end());
bv.keep_range(99, 105); PrintContainer(bv.first(), bv.end());
PrintContainer(bv2.first(), bv2.end());
bool eq = bv.equal(bv2); cout << eq << endl;
{
bm::serializer<bm::bvector<> > ser;
ser.set_bookmarks(true, 64);
bm::serializer<bm::bvector<> >::buffer buf;
ser.serialize(bv3, buf);
cout << "BLOB size=" << buf.size() << endl;
bm::bvector<> bv4;
bm::deserialize_range(bv4, buf.data(), 101, 105);
PrintContainer(bv4.first(), bv4.end());
eq = bv4.equal(bv2); cout << eq << endl; }
}
catch(std::exception& ex)
{
std::cerr << ex.what() << std::endl;
return 1;
}
return 0;
}