Example of how to use bm::str_sparse_vector<> - succinct container for bit-transposed string collections.
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>
#include <fstream>
using namespace std;
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);
}
{
try
{
vector<string> str_vec;
std::sort(str_vec.begin(), str_vec.end());
{
size_t vect_size = 0;
{
for (auto str : str_vec)
{
bi = str;
size_t str_size = str.size() + sizeof(str);
vect_size += str_size;
}
cout << "STL vector<string> approx.memory consumption:"
<< vect_size << endl;
}
cout <<
"Used memory: " << st.
memory_used << std::endl;
cout << "Used memory after remap and optimization: "
<< std::endl;
}
{
std::string fname = "test.sv";
std::ofstream fout(fname.c_str(), std::ios::binary);
if (!fout.good())
{
return -1;
}
const char* buf = (
char*)sv_lay.
buf();
fout.write(buf, (
unsigned)sv_lay.
size());
if (!fout.good())
{
return -1;
}
fout.close();
cout <<
"Saved size: " << sv_lay.
size() << 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)
Serialization for sparse_vector<>
string sparse vector based on bit-transposed matrix
Back insert iterator implements buffered insert, faster than generic access assignment.
void flush()
flush the accumulated buffer
sparse vector for strings with compression using bit transposition method
void remap_from(const str_sparse_vector &str_sv)
Build remapping profile and load content from another sparse vector.
back_insert_iterator get_back_inserter()
Provide back insert iterator Back insert iterator implements buffered insertion, which is faster,...
void calc_stat(struct str_sparse_vector< CharType, BV, MAX_STR_SIZE >::statistics *st) const BMNOEXCEPT
Calculates memory statistics.
void optimize(bm::word_t *temp_block=0, typename bvector_type::optmode opt_mode=bvector_type::opt_compress, typename str_sparse_vector< CharType, BV, MAX_STR_SIZE >::statistics *stat=0)
run memory optimization for all vector plains
void sparse_vector_serialize(const SV &sv, sparse_vector_serial_layout< SV > &sv_layout, bm::word_t *temp_block=0)
Serialize sparse vector into a memory buffer(s) structure.
bm::str_sparse_vector< char, bvector_type, 32 > str_sv_type
static void generate_string_set(vector< string > &str_vec)
size_t memory_used
memory usage for all blocks and service tables
layout class for serialization buffer structure
size_t size() const
return current serialized size
const unsigned char * buf() const
Return serialization buffer pointer.