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.
- See also
- bm::bvector::set_range
-
bm::bvector::clear_range
-
bm::bvector::keep_range
-
bm::bvector::is_all_one_range
-
bm::bvector::any_range
-
bm::is_interval
-
bm::find_interval_end
-
bm::find_interval_start
-
bm::deserialize_range
-
sample23.cpp
-
Algorithms for bit intervals
#include <iostream>
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_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;
}
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 ...
void copy_range(const bvector< Alloc > &bvect, size_type left, size_type right)
Copy all bits in the specified closed interval [left,right].
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.
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 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,...