BitMagic-C++
xsample01.cpp
Go to the documentation of this file.
1/*
2Copyright(c) 2002-2017 Anatoliy Kuznetsov(anatoliy_kuznetsov at yahoo.com)
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15
16For more information please visit: http://bitmagic.io
17*/
18
19/** \example xsample01.cpp
20 Demo and a benchmark on memory consumption control and logical operation
21*/
22/*! \file xsample01.cpp
23 \brief Example: Example: memory consumption techniques
24*/
25
26
27#include <iostream>
28#include <memory>
29#include <map>
30#include <vector>
31#include <chrono>
32#include <algorithm>
33#include <stdexcept>
34
35using namespace std;
36
37#include "bm.h"
38#include "bmalgo.h"
39#include "bmtimer.h"
40#include "bmserial.h"
41#include "bmsparsevec.h"
42
43#include "bmsparsevec_algo.h"
44#include "bmsparsevec_serial.h"
45#include "bmalgo_similarity.h"
46
47#include "bmdbg.h"
48#include "bmundef.h" /* clear the pre-proc defines from BM */
49
50// ----------------------------------------------------
51// Global parameters and types
52// ----------------------------------------------------
53
54// Number of vectors generated for the test
55const unsigned index_size = 1000000;
56
57// Dynamic range for constructed sets
58const unsigned max_size = 2000000;
59
60// Number of bits per one vector
61const unsigned bits_per_vect = 5;
62
63// benchmark operation count
64const unsigned benchmark_ops = 1000;
65
66// subset of vectors used as a sample
67const unsigned sample_cnt = 250;
68
69// index values to extract
70const unsigned result_set_cnt = 200;
71
72
73// bit-vector type for this example
75
76
77// timing storage for benchmarking
79
80
81
82/* BitMagic provides two GAP length tables for situations when we have
83 standard or embarassingly sparse vectors.
84 bm::gap_len_table - default standard
85 bm::gap_len_table_min - option for smaller vectors
86
87 Here we define an alternative table for very sparse vectors
88*/
89template<bool T> struct gap_len_table_sparse
90{
92};
93template<bool T>
95 { 8, 32, 128, 512 };
96
97
98// simple bit-vector class factory for the project
99//
100static
102{
103 // in this example we plan to keep lots of vectors in memory, thus
104 // use parameters to minimize memory consumption
105 //
106 TBVector* bv =
107 new TBVector(bm::BM_GAP, // use GAP compressed mode
108 gap_len_table_sparse<true>::_len, // custom lens for super sparse vectors
109 max_size // limit the maximum size
110 );
111 return bv;
112}
113
114// Generic utility to destroy map of pointers
115template<typename TM>
116void destroy_map(TM& id_map)
117{
118 for (typename TM::iterator it = id_map.begin();
119 it != id_map.end();
120 ++it)
121 {
122 typename TM::mapped_type mp = it->second;
123 delete mp;
124 } // for
125 id_map.clear();
126}
127
128// ------------------------------------------------------------------
129// Sample data structures
130// ------------------------------------------------------------------
131
132// Sample index structure to keep a map of in-memory bit-vectors
133//
135{
136 typedef std::map<unsigned, TBVector*> map_type;
138 {
140 }
142};
143
144// Sample index structure to keep map of in-memory serialized/compressed bit-vectors
145//
147{
148 typedef std::vector<unsigned char> buffer_type;
149 typedef std::map<unsigned, buffer_type> map_type;
150
152};
153
154// Sample index structure to keep map of in-memory vector<unsigned int>
155//
157{
158 typedef std::vector<unsigned int> buffer_type;
159 typedef std::map<unsigned, buffer_type> map_type;
160
162};
163
164
165// Sample index structure as in-memory sparse_vector
166//
168{
170 {
171 unsigned offset;
172 unsigned size;
173 };
174
176 typedef std::map<unsigned, vect_addr> map_type;
177 typedef std::vector< std::pair<uint64_t, unsigned> > delta_sum_map_type;
178
179
180 void get_vector(unsigned id, std::vector<unsigned>& vect) const;
181
182
186};
187
188void sparse_vect_index::get_vector(unsigned id, std::vector<unsigned>& vect) const
189{
190 map_type::const_iterator it = idx_.find(id);
191 if (it != idx_.end())
192 {
193 const sparse_vect_index::vect_addr& vaddr = it->second;
194 vect.resize(vaddr.size+1);
195 vect[0] = sv_storage1_.get(id);
196 for (unsigned j = 1; j < vect.size(); ++j)
197 {
198 unsigned a = sv_storage_.get(j + vaddr.offset - 1);
199 a += (vect[j-1] + 1);
200 vect[j] = a;
201 } // for j
202 }
203 else
204 {
205 vect.resize(0);
206 }
207}
208
209// --------------------------------------------------------------------
210
211
212// set bits in a vector using various methods picked at random
213///
214// one method will generate a plato of non-random integers,
215// another random integers of near neighbors
216// the other adds ints randomly without following any system
217//
218static
220{
221 unsigned method = rand() % 5; // pick a generation method
222 if (method == 0) // generate a incremental linear sequence at random location
223 {
224 unsigned seed_id = unsigned(rand()) % max_size;
225 for (unsigned i = seed_id; i < seed_id+bits_per_vect; ++i)
226 {
227 if (i >= max_size)
228 break;
229 bv->set_bit(i);
230 } // for i
231 }
232 else
233 if (method == 1) // generate near neighbors
234 {
235 unsigned seed_id = unsigned(rand()) % max_size;
236 unsigned id = seed_id;
237 for (unsigned i = 0; i < bits_per_vect; ++i)
238 {
239 if (id >= max_size)
240 break;
241 bv->set_bit(id);
242 id += (rand() % 10);
243 if (id >= max_size)
244 id = unsigned(rand()) % max_size;
245 } // for i
246 }
247 else // generate completely random bits
248 {
249 for (unsigned i = 0; i < bits_per_vect; ++i)
250 {
251 unsigned id = unsigned(rand()) % max_size;
252 if (i >= max_size) // paranoiya check
253 break;
254 bv->set_bit(id);
255 } // for i
256 }
257}
258
259// generate map of bit-vectors, each filled with just a few bits
260//
261static
263{
264 for (unsigned i = 0; i < index_size; ++i)
265 {
266 std::unique_ptr<TBVector> ap(construct_bvector());
267
268 generate_random_vector(ap.get());
269
270 if (!ap->any()) // integrity check
271 {
272 // this should never happen
273 std::cerr << "Warning. Empty vector generated!" << std::endl;
274 }
275
276 bvi.idx_[i] = ap.release();
277 }
278}
279
280// calculate memory footprint for in memory index
281//
282static
284{
285 size_t mem_total = 0;
286 for (bv_index::map_type::const_iterator it = bvi.idx_.begin();
287 it != bvi.idx_.end();
288 ++it)
289 {
290 const TBVector* mp = it->second;
291
293 mp->calc_stat(&st);
294 mem_total += st.memory_used;
295
296 mem_total += sizeof(void*);
297 } // for
298
299 return mem_total;
300}
301
302// convert bit-vector index to bit-vector serialized index
303//
304static
305size_t convert_bv2bvs(const bv_index& bvi, bvs_index& bvs)
306{
307 size_t mem_total = 0;
308 std::vector<unsigned char> buf; // prepare a temporary buffer
309 buf.reserve(1024);
310
311 // bit-vector serializer
312 // (keep it out of the serialization loop to minimize buffers re-allocations)
313 //
315 bvsr.byte_order_serialization(false);
316 bvsr.gap_length_serialization(false);
317 bvsr.set_compression_level(4);
318
319 for (bv_index::map_type::const_iterator it = bvi.idx_.begin();
320 it != bvi.idx_.end();
321 ++it)
322 {
323 unsigned id = it->first;
324 const TBVector* bvp = it->second;
325
327 bvp->calc_stat(&st); // calculate max. serialized size
328
329 buf.resize(st.max_serialize_mem); // prepare the temp buffer
330
331 // run serialization, actual serialization size is expacted to be smaller
332 //
333 unsigned bvs_size = bvsr.serialize(*bvp, buf.data(), st.max_serialize_mem);
334
335 // move from temp serialization buffer to compressed in-memory index
336 //
337 bvs_index::buffer_type& vbuf = bvs.idx_[id];
338 vbuf.resize(bvs_size);
339 ::memcpy(vbuf.data(), buf.data(), bvs_size);
340
341 mem_total += bvs_size;
342
343 mem_total += sizeof(std::vector<unsigned char>::size_type);
344
345
346 // paranoia check compare source and desirialized vectors
347 //
348 #ifdef DEBUG
349 {
350 TBVector bv1;
351 bm::deserialize(bv1, vbuf.data());
352 if (bv1.compare(*bvp) !=0 )
353 {
354 throw std::runtime_error("deserialization check failed");
355 }
356 }
357 #endif
358
359 } // for
360
361 return mem_total;
362}
363
364// convert bit-vector index to vector<usingned>
365//
366static
367size_t convert_bv2vect(const bv_index& bvi, vect_index& vidx)
368{
369 size_t mem_total = 0;
370
371 for (bv_index::map_type::const_iterator it = bvi.idx_.begin();
372 it != bvi.idx_.end();
373 ++it)
374 {
375 unsigned id = it->first;
376 const TBVector* bvp = it->second;
377
378 unsigned count = bvp->count(); // population count
379
380 vect_index::buffer_type& vect = vidx.idx_[id];
381 vect.resize(count);
382
383 for (TBVector::enumerator en = bvp->first(); en.valid(); ++en)
384 {
385 vect.push_back(*en);
386 }
387
388 mem_total +=
389 sizeof(vect_index::buffer_type::value_type) * vect.size() +
390 sizeof(vect_index::buffer_type::size_type);
391
392 } // for
393 return mem_total;
394}
395
396static
397void bv2delta(const TBVector& bv, std::vector<unsigned>& vect)
398{
399 // convert into a plain vector first
400 //
401 vect.resize(0);
402 for (TBVector::enumerator en = bv.first(); en.valid(); ++en)
403 {
404 vect.push_back(*en);
405 }
406
407 // convert into delta-vector
408 //
409 {
410 for (size_t k = vect.size()-1; k >= 1; --k)
411 {
412 vect[k] -= vect[k-1];
413 --vect[k];
414 } // for
415 }
416}
417
418// convert bit-vector index to bm::sparse_vector
419//
420static
421size_t convert_bv2sv(const bv_index& bvi, sparse_vect_index& sv_idx)
422{
423 size_t mem_total = 0;
424
425 std::vector<unsigned> vect;
426
428
429 for (bv_index::map_type::const_iterator it = bvi.idx_.begin();
430 it != bvi.idx_.end();
431 ++it)
432 {
433 unsigned id = it->first;
434 const TBVector* bvp = it->second;
435
436 bv2delta(*bvp, vect);
437
438 // compute sum of the delta-vector elements add to the sort map
439 {
440 uint64_t sum = 0;
441 for (unsigned k = 1; k < vect.size(); ++k)
442 {
443 sum += vect[k];
444 } // for
445 delta_map.push_back(std::make_pair(sum, id));
446 }
447
448 } // for
449
450 // sort by "enthropy" (sort of)
451 //
452 std::sort(delta_map.begin(), delta_map.end());
453 if (delta_map.size() != bvi.idx_.size()) // paranoia check
454 {
455 throw std::runtime_error("delta map size is incorrect");
456 }
457
458 unsigned sv_pos = 0; // current position in sparse vector
459 for (unsigned j = 0; j < delta_map.size(); ++j)
460 {
461 unsigned id = delta_map[j].second;
462
463 bv_index::map_type::const_iterator it = bvi.idx_.find(id);
464 if (it == bvi.idx_.end())
465 continue;
466 const TBVector& bv = *(it->second);
467
468 // convert into a plain delta vector again
469 bv2delta(bv, vect);
470
472 vaddr.offset = sv_pos;
473 vaddr.size = (unsigned)(vect.size() - 1);
474
475 sv_idx.sv_storage1_.set(id, vect[0]);
476
477 if (vaddr.size)
478 {
479 sv_idx.sv_storage_.import(&vect[1], vaddr.size, vaddr.offset);
480 sv_pos += vaddr.size;
481 }
482
483 sv_idx.idx_[id] = vaddr;
484 } // for
485
486
487 // optimize sparse vector storage, compute memory consumption
488 {
489 sparse_vect_index::sparse_vector_type::statistics st;
490
493 mem_total += st.memory_used;
495 mem_total += st.memory_used;
496 }
497
498 // check
499 for (bv_index::map_type::const_iterator it = bvi.idx_.begin();
500 it != bvi.idx_.end();
501 ++it)
502 {
503 unsigned id = it->first;
504 const TBVector* bvp = it->second;
505
506 // convert into a plain vector first
507 //
508 vect.resize(0);
509 for (TBVector::enumerator en = bvp->first(); en.valid(); ++en)
510 {
511 vect.push_back(*en);
512 }
513
514
515 std::vector<unsigned> svect;
516 sv_idx.get_vector(id, svect);
517 if (svect.size() != vect.size())
518 {
519 std::cerr << "Size check failed! id = " << id
520 << "size() = " << svect.size()
521 << std::endl;
522 throw std::runtime_error("sparse vector content check failed");
523 }
524
525 for (unsigned k = 0; k < vect.size(); ++k)
526 {
527 if (vect[k] != svect[k])
528 {
529 std::cerr << "SV content check failed! id = " << id
530 << " i=" << k << std::endl;
531 for (unsigned h = 0; h < vect.size(); ++h)
532 {
533 std::cout << "[" << vect[h] << "=" << svect[h] << "], ";
534 } // for h
535 std::cout << std::endl;
536 throw std::runtime_error("sparse vector content check failed");
537 }
538 } // for k
539
540 } // for
541
542 #ifdef DEBUG
543 bm::print_svector_stat(sv_idx.sv_storage_, true);
544 bm::print_svector_stat(sv_idx.sv_storage1_, true);
545 #endif
546
547 return mem_total;
548}
549
550
551// speed test for in-memory bit vectors
552// benchmark performs a mix of logical operations
553//
554static
556{
557 TBVector bv_join; // OR join vector
558
559 bm::chrono_taker tt1(cout, "1. bm::bvector<> index", 1, &timing_map);
560
561 // join all vectors using OR operation
562 for (bv_index::map_type::const_iterator it = bvi.idx_.begin();
563 it != bvi.idx_.end();
564 ++it)
565 {
566 const TBVector* bvp = it->second;
567 bv_join |= *bvp;
568 } // for
569 bv_join.optimize();
570
571 // a group of random vectors from the index map, compute OR
572 // then compute AND with the join vector
573 //
574 TBVector bv_res(bm::BM_GAP);
575 std::vector<unsigned> result_set;
576 result_set.reserve(result_set_cnt); // memory reservation to avoid reallocs
577
578 for (unsigned i = 0; i < benchmark_ops; ++i)
579 {
580 bv_res.clear(true); // free all blocks
581 result_set.resize(0);
582
583 for (unsigned j = 0; j < sample_cnt; ++j)
584 {
585 unsigned id = unsigned(rand()) % index_size;
586 bv_index::map_type::const_iterator it = bvi.idx_.find(id);
587 if (it == bvi.idx_.end())
588 continue;
589 const TBVector& bv = *(it->second);
590 bv_res |= bv;
591 }
592
593 bv_res &= bv_join;
594
595 // enumerate the final result set, extract first N elements
596 //
597 TBVector::enumerator en = bv_res.first();
598 for (unsigned k = 0; en.valid() && k < result_set_cnt; ++k, ++en)
599 {
600 result_set.push_back(*en);
601 }
602
603 } // for i
604
605 tt1.add_repeats(benchmark_ops + 1);
606}
607
608// speed test for in-memory serialized bit vectors
609// this function uses bm::operation_deserializer
610// to perform logical operation between a BLOB and bvector<> in memory
611// and avoids extra decompression overhead
612//
613static
615{
616 TBVector bv_join; // OR join vector
617
619
621
622 bm::chrono_taker tt1(cout, "2. serialized bvector", 1, &timing_map);
623
624 // join all vectors using OR operation
625 for (bvs_index::map_type::const_iterator it = bvs.idx_.begin();
626 it != bvs.idx_.end();
627 ++it)
628 {
629 const bvs_index::buffer_type& svect = it->second;
630 if (svect.size() == 0)
631 {
632 throw std::runtime_error("empty buffer error");
633 }
634 const unsigned char* buf = it->second.data();
635
636 des.deserialize(bv_join, buf, tb, bm::set_OR);
637 } // for
638 bv_join.optimize();
639
640 // a group of random vectors from the index map, compute OR
641 // then compute AND with the join vector
642 //
643 TBVector bv_res(bm::BM_GAP);
644 std::vector<unsigned> result_set;
645 result_set.reserve(result_set_cnt); // memory reservation to avoid reallocs
646
647 for (unsigned i = 0; i < benchmark_ops; ++i)
648 {
649 bv_res.clear(true); // free all blocks
650 result_set.resize(0);
651
652 for (unsigned j = 0; j < sample_cnt; ++j)
653 {
654 unsigned id = unsigned(rand()) % index_size;
655 bvs_index::map_type::const_iterator it = bvs.idx_.find(id);
656 if (it == bvs.idx_.end())
657 continue;
658
659 const unsigned char* buf = it->second.data();
660 des.deserialize(bv_res, buf, tb, bm::set_OR);
661 } // for j
662
663 bv_res &= bv_join;
664
665 // enumerate the final result set, extract first N elements
666 //
667 TBVector::enumerator en = bv_res.first();
668 for (unsigned k = 0; en.valid() && k < result_set_cnt; ++k, ++en)
669 {
670 result_set.push_back(*en);
671 }
672 } // for i
673
674 tt1.add_repeats(benchmark_ops + 1);
675}
676
677static
679{
680 TBVector bv_join; // OR join vector
681
682 bm::chrono_taker tt1(cout, "3. std::vector<unsigned> ", 1, &timing_map);
683
684 // join all vectors using OR operation
685 for (vect_index::map_type::const_iterator it = vecti.idx_.begin();
686 it != vecti.idx_.end();
687 ++it)
688 {
689 const vect_index::buffer_type& vect = it->second;
690 if (vect.size() == 0)
691 {
692 throw std::runtime_error("empty buffer error");
693 }
694
695 bm::combine_or(bv_join, vect.begin(), vect.end());
696 } // for
697 bv_join.optimize();
698
699
700 // a group of random vectors from the index map, compute OR
701 // then compute AND with the join vector
702 //
703 TBVector bv_res(bm::BM_GAP);
704 std::vector<unsigned> result_set;
705 result_set.reserve(result_set_cnt); // memory reservation to avoid reallocs
706
707 for (unsigned i = 0; i < benchmark_ops; ++i)
708 {
709 bv_res.clear(true); // free all blocks
710 result_set.resize(0);
711
712 for (unsigned j = 0; j < sample_cnt; ++j)
713 {
714 unsigned id = unsigned(rand()) % index_size;
715 vect_index::map_type::const_iterator it = vecti.idx_.find(id);
716 if (it == vecti.idx_.end())
717 continue;
718
719 const vect_index::buffer_type& vect = it->second;
720
721 bm::combine_or(bv_join, vect.begin(), vect.end());
722 } // for j
723
724 bv_res &= bv_join;
725
726 // enumerate the final result set, extract first N elements
727 //
728 TBVector::enumerator en = bv_res.first();
729 for (unsigned k = 0; en.valid() && k < result_set_cnt; ++k, ++en)
730 {
731 result_set.push_back(*en);
732 }
733
734 } // for i
735
736 tt1.add_repeats(benchmark_ops + 1);
737}
738
739static
741{
742 TBVector bv_join; // OR join vector
743
744 bm::chrono_taker tt1(cout, "4. bm::sparse_vector<unsigned> ", 1, &timing_map);
745
746 std::vector<unsigned> vect;
747
748 // join all vectors using OR operation
749 for (sparse_vect_index::map_type::const_iterator it = svi.idx_.begin();
750 it != svi.idx_.end();
751 ++it)
752 {
753 unsigned id = it->first;
754 svi.get_vector(id, vect);
755
756 bm::combine_or(bv_join, vect.begin(), vect.end());
757 } // for
758 bv_join.optimize();
759
760
761 // a group of random vectors from the index map, compute OR
762 // then compute AND with the join vector
763 //
764 TBVector bv_res(bm::BM_GAP);
765 std::vector<unsigned> result_set;
766 result_set.reserve(result_set_cnt); // memory reservation to avoid reallocs
767
768 for (unsigned i = 0; i < benchmark_ops; ++i)
769 {
770 bv_res.clear(true); // free all blocks
771 result_set.resize(0);
772
773 for (unsigned j = 0; j < sample_cnt; ++j)
774 {
775 unsigned id = unsigned(rand()) % index_size;
776 svi.get_vector(id, vect);
777 if (vect.size() == 0)
778 continue;
779
780 bm::combine_or(bv_join, vect.begin(), vect.end());
781 } // for j
782
783 bv_res &= bv_join;
784
785 // enumerate the final result set, extract first N elements
786 //
787 TBVector::enumerator en = bv_res.first();
788 for (unsigned k = 0; en.valid() && k < result_set_cnt; ++k, ++en)
789 {
790 result_set.push_back(*en);
791 }
792
793 } // for i
794
795 tt1.add_repeats(benchmark_ops + 1);
796}
797
798
799
800int main(void)
801{
802 try
803 {
804 bv_index bvi; // regular in-memory index id to bvector<>
805 bvs_index bvs; // compressed in-memory index id to bvector<> BLOB
806 vect_index vecti; // index based on plain uncompressed vector<unsigned>
807 sparse_vect_index svi; // all ids in a sparse vector
808
809 // experiments generation, measuring memory footprints
810 //
812
813 size_t bv_mem_total = calc_memory_footprint(bvi);
814 size_t bv_mem_total_MB = bv_mem_total / (1024*1024);
815
816 std::cout << "bm::bvector<> memory footprint = "
817 << bv_mem_total << " (" << bv_mem_total_MB << "MB)"
818 << std::endl;
819
820 size_t bvs_mem_total = convert_bv2bvs(bvi, bvs);
821 size_t bvs_mem_total_MB = bvs_mem_total / (1024*1024);
822
823 std::cout << "bm::bvector<> BLOB memory footprint = "
824 << bvs_mem_total << " (" << bvs_mem_total_MB << "MB)"
825 << std::endl;
826
827 size_t vecti_mem_total = convert_bv2vect(bvi, vecti);
828 size_t vecti_mem_total_MB = vecti_mem_total / (1024*1024);
829
830 std::cout << "std::vector<unsigned> memory footprint = "
831 << vecti_mem_total << " (" << vecti_mem_total_MB << "MB)"
832 << std::endl;
833
834 size_t svi_mem_total = convert_bv2sv(bvi, svi);
835 size_t svi_mem_total_MB = svi_mem_total / (1024*1024);
836
837 std::cout << "bm::sparse_vector<> memory footprint = "
838 << svi_mem_total << " (" << svi_mem_total_MB << "MB)"
839 << std::endl;
840
841 // run performance tests
842 //
843
848
849
850 std::cout << std::endl << "Performance (ops/sec):" << std::endl;
852
853 //getchar(); // uncomment to check memory consumption at the OS level
854
855 }
856 catch(std::exception& ex)
857 {
858 std::cerr << ex.what() << std::endl;
859 return 1;
860 }
861
862 return 0;
863}
864
Compressed bit-vector bvector<> container, set algebraic methods, traversal iterators.
#define BM_DECLARE_TEMP_BLOCK(x)
Definition: bm.h:47
Algorithms for bvector<> (main include)
Serialization / compression of bvector<>. Set theoretical operations on compressed BLOBs.
Sparse constainer sparse_vector<> for integer types using bit-transposition transform.
Algorithms for bm::sparse_vector.
Serialization for sparse_vector<>
Timing utilities for benchmarking (internal)
pre-processor un-defines to avoid global space pollution (internal)
Constant iterator designed to enumerate "ON" bits.
Definition: bm.h:603
bool valid() const BMNOEXCEPT
Checks if iterator is still valid.
Definition: bm.h:283
Bitvector Bit-vector container with runtime compression of bits.
Definition: bm.h:115
@ opt_compress
compress blocks when possible (GAP/prefix sum)
Definition: bm.h:137
size_type count() const BMNOEXCEPT
population count (count of ON bits)
Definition: bm.h:2366
void resize(size_type new_size)
Change size of the bvector.
Definition: bm.h:2428
void optimize(bm::word_t *temp_block=0, optmode opt_mode=opt_compress, statistics *stat=0)
Optimize memory bitvector's memory allocation.
Definition: bm.h:3600
bool set_bit(size_type n, bool val=true)
Sets bit n.
Definition: bm.h:4192
enumerator first() const
Returns enumerator pointing on the first non-zero bit.
Definition: bm.h:1849
enumerator end() const
Returns enumerator pointing on the next bit after the last.
Definition: bm.h:1855
void clear(const size_type *ids, size_type ids_size, bm::sort_order so=bm::BM_UNKNOWN)
clear list of bits in this bitset
Definition: bm.h:4114
int compare(const bvector< Alloc > &bvect) const BMNOEXCEPT
Lexicographical comparison with a bitvector.
Definition: bm.h:3709
void calc_stat(struct bm::bvector< Alloc >::statistics *st) const BMNOEXCEPT
Calculates bitvector statistics.
Definition: bm.h:3943
Utility class to collect performance measurements and statistics.
Definition: bmtimer.h:41
std::map< std::string, statistics > duration_map_type
test name to duration map
Definition: bmtimer.h:66
void add_repeats(unsigned inc)
Definition: bmtimer.h:125
static void print_duration_map(TOut &tout, const duration_map_type &dmap, format fmt=ct_time)
Definition: bmtimer.h:150
Deserializer, performs logical operations between bit-vector and serialized bit-vector.
Definition: bmserial.h:930
size_type deserialize(bvector_type &bv, const unsigned char *buf, set_operation op, bool exit_on_one=false)
Deserialize bvector using buffer as set operation argument.
Definition: bmserial.h:6579
Bit-vector serialization class.
Definition: bmserial.h:76
void gap_length_serialization(bool value) BMNOEXCEPT
Set GAP length serialization (serializes GAP levels of the original vector)
Definition: bmserial.h:1275
void set_compression_level(unsigned clevel) BMNOEXCEPT
Set compression level.
Definition: bmserial.h:1254
void byte_order_serialization(bool value) BMNOEXCEPT
Set byte-order serialization (for cross platform compatibility)
Definition: bmserial.h:1281
size_type serialize(const BV &bv, unsigned char *buf, size_t buf_size)
Bitvector serialization into memory block.
Definition: bmserial.h:2706
succinct sparse vector with runtime compression using bit-slicing / transposition method
Definition: bmsparsevec.h:87
value_type get(size_type idx) const BMNOEXCEPT
get specified element without bounds checking
Definition: bmsparsevec.h:1741
void set(size_type idx, value_type v)
set specified element with bounds checking and automatic resize
Definition: bmsparsevec.h:1804
void import(const value_type *arr, size_type arr_size, size_type offset=0, bool set_not_null=true)
Import list of elements from a C-style array.
Definition: bmsparsevec.h:1154
void optimize(bm::word_t *temp_block=0, typename bvector_type::optmode opt_mode=bvector_type::opt_compress, typename sparse_vector< Val, BV >::statistics *stat=0)
run memory optimization for all vector planes
Definition: bmsparsevec.h:2094
@ set_OR
Definition: bmconst.h:169
@ BM_GAP
GAP compression is ON.
Definition: bmconst.h:147
size_t deserialize(BV &bv, const unsigned char *buf, bm::word_t *temp_block=0, const bm::bv_ref_vector< BV > *ref_vect=0)
Bitvector deserialization from a memory BLOB.
Definition: bmserial.h:3140
void combine_or(BV &bv, It first, It last)
OR Combine bitvector and the iterable sequence.
Definition: bmalgo_impl.h:1080
const unsigned gap_levels
Definition: bmconst.h:85
unsigned short gap_word_t
Definition: bmconst.h:78
size_t max_serialize_mem
estimated maximum memory for serialization
Definition: bmfunc.h:61
size_t memory_used
memory usage for all blocks and service tables
Definition: bmfunc.h:62
Statistical information about bitset's memory allocation details.
Definition: bm.h:125
std::map< unsigned, TBVector * > map_type
Definition: xsample01.cpp:136
map_type idx_
Definition: xsample01.cpp:141
std::map< unsigned, buffer_type > map_type
Definition: xsample01.cpp:149
std::vector< unsigned char > buffer_type
Definition: xsample01.cpp:148
map_type idx_
Definition: xsample01.cpp:151
static const bm::gap_word_t _len[bm::gap_levels]
Definition: xsample01.cpp:91
sparse_vector_type sv_storage1_
Definition: xsample01.cpp:184
bm::sparse_vector< unsigned, bm::bvector<> > sparse_vector_type
Definition: xsample01.cpp:175
std::map< unsigned, vect_addr > map_type
Definition: xsample01.cpp:176
std::vector< std::pair< uint64_t, unsigned > > delta_sum_map_type
Definition: xsample01.cpp:177
void get_vector(unsigned id, std::vector< unsigned > &vect) const
Definition: xsample01.cpp:188
sparse_vector_type sv_storage_
Definition: xsample01.cpp:183
std::map< unsigned, buffer_type > map_type
Definition: xsample01.cpp:159
map_type idx_
Definition: xsample01.cpp:161
std::vector< unsigned int > buffer_type
Definition: xsample01.cpp:158
static void generate_random_vector(TBVector *bv)
Definition: xsample01.cpp:219
bm::bvector TBVector
Definition: xsample01.cpp:74
static void generate_bv_index(bv_index &bvi)
Definition: xsample01.cpp:262
const unsigned index_size
Definition: xsample01.cpp:55
static void speed_test_vect_index(const vect_index &vecti)
Definition: xsample01.cpp:678
const unsigned benchmark_ops
Definition: xsample01.cpp:64
static TBVector * construct_bvector()
Definition: xsample01.cpp:101
const unsigned bits_per_vect
Definition: xsample01.cpp:61
int main(void)
Definition: xsample01.cpp:800
static void speed_test_bv_index(const bv_index &bvi)
Definition: xsample01.cpp:555
static size_t calc_memory_footprint(const bv_index &bvi)
Definition: xsample01.cpp:283
static void bv2delta(const TBVector &bv, std::vector< unsigned > &vect)
Definition: xsample01.cpp:397
static size_t convert_bv2bvs(const bv_index &bvi, bvs_index &bvs)
Definition: xsample01.cpp:305
void destroy_map(TM &id_map)
Definition: xsample01.cpp:116
const unsigned result_set_cnt
Definition: xsample01.cpp:70
bm::chrono_taker ::duration_map_type timing_map
Definition: xsample01.cpp:78
static void speed_test_sv_index(const sparse_vect_index &svi)
Definition: xsample01.cpp:740
static size_t convert_bv2vect(const bv_index &bvi, vect_index &vidx)
Definition: xsample01.cpp:367
const unsigned sample_cnt
Definition: xsample01.cpp:67
static size_t convert_bv2sv(const bv_index &bvi, sparse_vect_index &sv_idx)
Definition: xsample01.cpp:421
const unsigned max_size
Definition: xsample01.cpp:58
static void speed_test_bvs_index(const bvs_index &bvs)
Definition: xsample01.cpp:614