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() <<
")" <<
": [";
{
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.
pre-processor un-defines to avoid global space pollution (internal)
bool is_null(size_type idx) const BMNOEXCEPT
test if specified element is NULL
Constant iterator designed to enumerate "ON" bits.
bool valid() const BMNOEXCEPT
Checks if iterator is still valid.
Bitvector Bit-vector container with runtime compression of bits.
size_type count() const BMNOEXCEPT
population count (count of ON bits)
enumerator first() const
Returns enumerator pointing on the first non-zero bit.
succinct sparse vector with runtime compression using bit-slicing / 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
void print_svector(const SV &sv, bool show_nulls=false)
Prints the vector using is_null() and get() Please note, that random access is not the fastest,...
bm::sparse_vector< bm::id_t, bm::bvector<> > sparse_vector_u32
void print_bvector(const bm::bvector<> &bv)