Example how to use for bvector re-mapping / transformation based on sparse_vector as a translation table.
Example how to use for bvector re-mapping / transformation based on sparse_vector as a translation table.Example discusses how use of NULL (unassigned) sparse_vector<> semantics affects behavior of image transformation algorithm.
#include <iostream>
#include <vector>
using namespace std;
static
{
{
cout << sv.
size() <<
": [ EMPTY ]" << endl;
return;
}
cout << sv.
size() <<
": [ ";
for (
unsigned i = 0; i < sv.
size(); ++i)
{
if (is_null)
cout << "NULL";
else
cout << v << "";
cout << " ]";
else
cout << ", ";
}
cout << endl;
}
inline
{
cout <<
"( count = " << bv.
count() <<
")" <<
": [";
bm::bvector<>::enumerator en = bv.
first();
for (; en.valid(); ++en)
{
cout << *en << ", ";
}
cout << "]" << endl;
}
{
try
{
sv_transform.set(2, 25);
sv_transform.set(3, 35);
sv_transform.set(7, 75);
sv_transform.set(1000, 2000);
sv_transform.set(256, 2001);
func.
run(bv_in, sv_transform, bv_out);
std::cout << "re-mapped vector:" << endl;
bool found = func.
remap(1, sv_transform, to);
if (!found)
std::cout << from << " not mapped" << std::endl;
else
std::cout << from << " mapped to " << to << std::endl;
sv_transform2.
set(2, 25);
sv_transform2.
set(3, 35);
sv_transform2.
set(7, 75);
sv_transform2.
set(1000, 2000);
sv_transform2.
set(256, 2001);
found = func.
remap(1, sv_transform2, to);
if (!found)
std::cout << from << " not mapped" << std::endl;
else
std::cout << from << " mapped to " << to << std::endl;
func.
run(bv_in, sv_transform2, bv_out);
std::cout << "re-mapped vector2:" << 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.
Sparse constainer sparse_vector<> for integer types using bit-transposition transform.
Algorithms for bm::sparse_vector.
bool is_null(size_type idx) const BMNOEXCEPT
test if specified element is NULL
size_type count() const BMNOEXCEPT
population cout (count of ON bits)
enumerator first() const
Returns enumerator pointing on the first non-zero bit.
sparse vector with runtime compression using bit transposition method
value_type at(size_type idx) const
access specified element with bounds checking
size_type size() const BMNOEXCEPT
return size of the vector
void set(size_type idx, value_type v)
set specified element with bounds checking and automatic resize
@ use_null
support "non-assigned" or "NULL" logic
static void print_bvector(const bm::bvector<> &bv)
static void print_svector(const bm::sparse_vector< unsigned, bm::bvector<> > &sv)
bm::sparse_vector< unsigned, bm::bvector<> > sparse_vector_u32