61 const unsigned max_coll = 850000,
62 unsigned repeat = 220)
66 for (
unsigned i = 10; i < max_coll; i += unsigned(rand() % 3))
70 case 0: str =
"xnssv";
break;
71 default: str =
"xrs";
break;
73 str.append(to_string(i));
75 for (
unsigned k = 0; k < repeat; ++k, ++i)
76 str_vec.emplace_back(str);
80 std::random_device rd;
82 std::shuffle(str_vec.begin() + str_vec.size()/2, str_vec.end(), g);
99 while((i < last) && (strsv.
compare(stype(i), stype(pivot)) <= 0))
101 while(strsv.
compare(stype(j), stype(pivot)) > 0)
104 strsv.
swap(stype(i), stype(j));
106 strsv.
swap(stype(pivot), stype(j));
133 strsv.
get(stype(pivot), pivot_buf,
sizeof(pivot_buf));
137 while((i < last) && (strsv.
compare(stype(i), pivot_buf) <= 0))
139 while(strsv.
compare(stype(j), pivot_buf) > 0)
142 strsv.
swap(stype(i), stype(j));
144 strsv.
swap(stype(pivot), stype(j));
161 for (
const string& s : str_vec)
163 const char* cs = s.c_str();
183 vector<string> str_vec;
187 cout <<
"Loading " << str_vec.size() <<
" elements..." << endl;
190 for (
const string& term : str_vec)
209 str_sv_type::statistics st;
211 size_t std_vect_mem =
sizeof(str_vec);
212 for (
const string& term : str_vec)
213 std_vect_mem += term.size() +
sizeof(term);
215 cout <<
"std::vector<string> mem = " << std_vect_mem << endl;
216 cout <<
"Succinct vector vector mem = " << st.memory_used << endl;
220 cout <<
"Quick Sort... 1" << endl;
226 cout <<
"Quick Sort... 2" << endl;
232 cout <<
"Insertion Sort... " << endl;
238 cout <<
"std::sort..." << endl;
241 std::sort(str_vec.begin(), str_vec.end());
246 bool eq = str_sv.
equal(str_sv2);
249 cerr <<
"post-sort vector mismatch! (qsort 1-2)" << endl;
256 vector<string>::const_iterator sit = str_vec.begin();
257 str_sv_type::const_iterator it = str_sv.
begin();
258 str_sv_type::const_iterator it_end = str_sv.
end();
259 str_sv_type::const_iterator it3 = str_sv3.
begin();
260 for (; it != it_end; ++it, ++sit, ++it3)
265 cerr <<
"Mismatch at:" << s <<
"!=" << *sit << endl;
272 cerr <<
"Mismatch at:" << s <<
"!=" << s3 << endl;
278 cout <<
"Sort validation Ok." << endl;
284 catch(std::exception& ex)
286 std::cerr << ex.what() << std::endl;
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
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.
std::map< std::string, statistics > duration_map_type
test name to duration map
static void print_duration_map(TOut &tout, const duration_map_type &dmap, format fmt=ct_time)
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
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
void calc_stat(struct str_sparse_vector< CharType, BV, STR_SIZE >::statistics *st) const BMNOEXCEPT
Calculates memory statistics.
bool equal(const str_sparse_vector< CharType, BV, STR_SIZE > &sv, bm::null_support null_able=bm::use_null) const BMNOEXCEPT
check if another sparse vector has the same content and size
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.
size_type get(size_type idx, value_type *str, size_type buf_size) const BMNOEXCEPT
get specified element
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,...
void swap(size_type idx1, size_type idx2)
swap two vector elements between each other
bvector_type::size_type size_type
bm::chrono_taker ::duration_map_type timing_map
bm::str_sparse_vector< char, bvector_type, 32 > str_sv_type
void quicksort2(str_sv_type &strsv, int first, int last)
Faster variant of quicksort, uses different variant of pivot compare, with decompressed argument.
void quicksort(str_sv_type &strsv, int first, int last)
quick-sort
static void generate_string_set(vector< string > &str_vec, const unsigned max_coll=850000, unsigned repeat=220)
generate collection of strings from integers with common prefixes ... and shuffle it
static void insertion_sort(str_sv_type &str_sv, const vector< string > &str_vec)
insertion sort for performance comnparison