Example of how to use bm::sparse_vector<> template class to set or import values.bm::sparse_vector<> uses bit-splicing method to keep bit-planes separate to provide on-the fly succinct data vector.
#include <iostream>
#include <algorithm>
using namespace std;
static
{
unsigned arr[3] = {1,2,3};
{
}
cout <<
"sv1.size() = " << sv1.
size() << endl;
cout << "sv[]:";
for (
unsigned i = 0; i < sv1.
size(); ++i)
{
cout << sv1.
at(i) <<
",";
}
cout << endl;
unsigned arr2[5] = {10, 20, 30, 40, 50};
cout <<
"sv1.size() = " << sv1.
size() << endl;
cout << "sv[]:";
[](value_type n) { cout << n << ", "; });
cout << endl;
}
static
{
int arr[3] = {1,-2,3};
int arr2[5] = {-10, 20, 30, 40, -50};
{
}
cout <<
"sv1.size() = " << sv1.
size() << endl;
cout << "sv[]:";
std::for_each(sv1.
begin(), sv1.
end(), [] (
auto n) { cout << n <<
", "; }
);
cout << endl;
}
{
try
{
cout << endl << 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.
#define BM_DECLARE_TEMP_BLOCK(x)
Sparse constainer sparse_vector<> for integer types using bit-transposition transform.
pre-processor un-defines to avoid global space pollution (internal)
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
const_iterator end() const BMNOEXCEPT
Provide const iterator access to the end
const_iterator begin() const BMNOEXCEPT
Provide const iterator access to container content
void import(const value_type *arr, size_type arr_size, size_type offset=0, bool set_not_null=true)
Import list of elements from a C-style array.
void optimize(bm::word_t *temp_block=0, typename bvector_type::optmode opt_mode=bvector_type::opt_compress, typename sparse_vector< Val, BV >::statistics *stat=0)
run memory optimization for all vector planes
static void Demo1()
bm::sparse_vector for unsigned int data
bm::sparse_vector< unsigned, bm::bvector<> > sparse_vector_u32
bm::sparse_vector< int, bm::bvector<> > sparse_vector_i32
static void Demo2()
bm::sparse_vector can also support signed ints.