Example on ranges and intervals.BitMagic bvector<> implements high performance operation on RLE coded bit-vectors, transparently supporting all logical operations like intersections. Serialization uses compressive encoding (binary interpolative codes) to efficiently store collections of intervals.
This creates a use case to use compressed bit-vector as an engine for ranges and intervals.
#include <iostream>
#include <assert.h>
using namespace std;
{
if (first == last)
cout << "<EMPTY SET>";
else
for(;first != last; ++first)
cout << *first << ", ";
cout << endl;
}
{
try
{
bv.set_range(100, 110);
bv.optimize();
cout << "Source set:";
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;
cout << is_int << endl;
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;
bool found = bv.find_reverse(256, pos);
assert(found);
cout << pos << endl;
cout << "bvector<>::find_interval demo" << endl;
if (found)
cout << pos << endl;
else
cout << "Not found." << endl;
if (found)
cout << pos << endl;
else
cout << "Not found." << endl;
if (found)
cout << pos << endl;
else
cout << "Not found." << endl;
cout << endl;
bv.clear_range(99, 100);
bv.keep_range(99, 105);
bool eq = bv.equal(bv2);
cout << eq << endl;
{
cout << "BLOB size=" << buf.size() << endl;
cout << eq << 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.
Algorithms for bit ranges and intervals.
Serialization / compression of bvector<>. Set theoretical operations on compressed BLOBs.
pre-processor un-defines to avoid global space pollution (internal)
Bitvector Bit-vector container with runtime compression of bits.
bool equal(const bvector< Alloc > &bvect) const BMNOEXCEPT
Equal comparison with an agr bit-vector.
bvector_size_type size_type
enumerator first() const
Returns enumerator pointing on the first non-zero bit.
enumerator end() const
Returns enumerator pointing on the next bit after the last.
void copy_range(const bvector< Alloc > &bvect, size_type left, size_type right)
Copy all bits in the specified closed interval [left,right].
Bit-vector serialization class.
void set_bookmarks(bool enable, unsigned bm_interval=256) BMNOEXCEPT
Add skip-markers to serialization BLOB for faster range decode at the expense of some BLOB size incre...
size_type serialize(const BV &bv, unsigned char *buf, size_t buf_size)
Bitvector serialization into memory block.
@ BM_GAP
GAP compression is ON.
bool find_interval_end(const BV &bv, typename BV::size_type from, typename BV::size_type &pos) BMNOEXCEPT
Reverse find index of first 1 bit gap (01110) starting from position Reverse scan for the first 1 in ...
bool find_interval_start(const BV &bv, typename BV::size_type from, typename BV::size_type &pos) BMNOEXCEPT
Reverse find index of first 1 bit gap (01110) starting from position Reverse scan for the first 1 in ...
bool is_interval(const BV &bv, typename BV::size_type left, typename BV::size_type right) BMNOEXCEPT
Returns true if range is all 1s flanked with 0s Function performs the test on a closed range [left,...
void deserialize_range(BV &bv, const unsigned char *buf, typename BV::size_type from, typename BV::size_type to, const bm::bv_ref_vector< BV > *ref_vect=0)
Bitvector range deserialization from a memory BLOB.
void PrintContainer(T first, T last)