63 const unsigned max_coll = 250000)
67 for (
unsigned i = 10; i < max_coll; i += unsigned(rand() % 3))
70 str_vec.emplace_back(str);
75 std::random_device rd;
77 std::shuffle(str_vec.begin(), str_vec.end(), g);
85 std::vector<string> str_vec;
90 for (
auto it = str_vec.begin(); it != str_vec.end(); ++it)
105 std::vector<uint32_t> index(str_sv.
size());
106 std::generate(index.begin(), index.end(),
107 [n = 0] ()
mutable { return n++; });
117 std::sort(index.begin(), index.end(),
118 [&str_sv](
const uint32_t l,
const uint32_t r)
120 static thread_local string last_right_str;
121 static thread_local uint32_t last_right = uint32_t(-1);
125 str_sv.get(last_right, last_right_str);
127 return str_sv.
compare(l, last_right_str.c_str()) < 0;
136 std::sort(index.begin(), index.end(),
137 [&str_sv](
const uint32_t l,
const uint32_t r)
138 { return str_sv.compare(l, r) < 0; }
149 for (
auto it = index.begin(); it != index.end(); ++it)
152 str_sv.get(i, buf,
sizeof(buf));
153 bit = (
const char*)buf;
158 assert(str_sv_sorted.
size()==str_sv.size());
163 std::sort(str_vec.begin(), str_vec.end());
165 std::vector<string>::const_iterator sit = str_vec.begin();
166 auto it = str_sv_sorted.
begin();
167 auto it_end = str_sv_sorted.
end();
168 for (; it != it_end; ++it, ++sit)
173 cerr <<
"Mismatch at:" << s <<
"!=" << *sit << endl;
178 cout <<
"Sort validation Ok." << endl << endl;
179 cout <<
"Memory footprint statistics:\n" << endl;
185 cout <<
"SV sorted(before remap) memory_used : "
192 str_sv_sorted.
remap();
197 str_sv.calc_stat(&st);
200 cout <<
"SV unsorted memory_used : "
203 cout <<
"SV sorted(after remap) memory_used : "
207 catch(std::exception& ex)
209 std::cerr << ex.what() << std::endl;
Compressed bit-vector bvector<> container, set algebraic methods, traversal iterators.
Algorithms for bm::sparse_vector.
string sparse vector based on bit-transposed matrix
Timing utilities for benchmarking (internal)
pre-processor un-defines to avoid global space pollution (internal)
Bitvector Bit-vector container with runtime compression of bits.
Utility class to collect performance measurements and statistics.
void flush()
flush the accumulated buffer.
succinct sparse vector for strings with compression using bit-slicing ( transposition) method
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
void calc_stat(struct str_sparse_vector< CharType, BV, STR_SIZE >::statistics *st) const BMNOEXCEPT
Calculates memory statistics.
size_type size() const
return size of the vector
const_iterator begin() const BMNOEXCEPT
Provide const iterator access to container content
int compare(size_type idx, const value_type *str) const BMNOEXCEPT
Compare vector element with argument lexicographically.
void remap()
Build remapping profile and re-load content to save memory.
back_insert_iterator get_back_inserter()
Provide back insert iterator Back insert iterator implements buffered insertion, which is faster,...
static void generate_string_set(vector< string > &str_vec, const unsigned max_coll=250000)
generate collection of strings from integers and shuffle it
bm::str_sparse_vector< char, bvector_type, 3 > str_sv_type
size_t memory_used
memory usage for all blocks and service tables