Example of how to use bm::str_sparse_vector<> - succinct container for bit-transposed string collections
#include <iostream>
#include <string>
#include <vector>
#include <random>
#include <algorithm>
using namespace std;
static
{
const unsigned max_coll = 50000;
str_vec.resize(0);
string str;
for (unsigned i = 10; i < max_coll; i += unsigned(rand() % 3))
{
str = to_string(i);
str_vec.emplace_back(str);
}
std::random_device rd;
std::mt19937 g(rd());
std::shuffle(str_vec.begin(), str_vec.end(), g);
}
static
{
for (const string& s : str_vec)
{
const char* cs = s.c_str();
(void)found;
}
}
{
try
{
vector<string> str_vec;
{
}
std::sort(str_vec.begin(), str_vec.end());
{
vector<string>::const_iterator sit = str_vec.begin();
for (; it != it_end; ++it, ++sit)
{
string s = *it;
if (*sit != s)
{
cerr << "Mismatch at:" << s << "!=" << *sit << endl;
return 1;
}
}
}
cout << "Sort validation Ok." << 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)
Algorithms for bm::sparse_vector.
string sparse vector based on bit-transposed matrix
pre-processor un-defines to avoid global space pollution (internal)
Bitvector Bit-vector container with runtime compression of bits.
algorithms for sparse_vector scan/search
bool lower_bound_str(const SV &sv, const value_type *str, size_type &pos)
lower bound search for an array position
Const iterator to do quick traverse of the sparse vector.
succinct sparse vector for strings with compression using bit-slicing ( transposition) method
void insert(size_type idx, const value_type *str)
insert the specified element
const_iterator end() const BMNOEXCEPT
Provide const iterator access to the end
void optimize(bm::word_t *temp_block=0, typename bvector_type::optmode opt_mode=bvector_type::opt_compress, typename str_sparse_vector< CharType, BV, STR_SIZE >::statistics *stat=0)
run memory optimization for all vector planes
const_iterator begin() const BMNOEXCEPT
Provide const iterator access to container content
bvector_type::size_type size_type
bm::str_sparse_vector< char, bvector_type, 32 > str_sv_type
static void generate_string_set(vector< string > &str_vec)
static void insertion_sort(str_sv_type &str_sv, const vector< string > &str_vec)