Example of how to use bm::str_sparse_vector<> - succinct container for bit-transposed string collections
- See also
- bm::str_sparse_vector
-
bm::sparse_vector_scanner
#include <iostream>
#include <string>
#include <vector>
#include <random>
#include <algorithm>
static
{
const unsigned max_coll = 50000;
str_vec.resize(0);
string str;
for (unsigned i = 10; i < max_coll; i += 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;
}