63
63
<span class="preprocessor">#include <stdlib.h></span>
64
64
<span class="preprocessor">#include <iostream></span>
65
<span class="preprocessor">#include "<a class="code" href="a00088.html">bm.h</a>"</span>
65
<span class="preprocessor">#include "<a class="code" href="a00087.html">bm.h</a>"</span>
67
67
<span class="keyword">using namespace </span>std;
69
<span class="keyword">const</span> <span class="keywordtype">unsigned</span> <a name="a0"></a><a class="code" href="a00109.html#a8652d848be89c1f9b0a77327ee32fc0f">MAX_VALUE</a> = 1000000;
69
<span class="keyword">const</span> <span class="keywordtype">unsigned</span> <a name="a0"></a><a class="code" href="a00108.html#a8652d848be89c1f9b0a77327ee32fc0f">MAX_VALUE</a> = 1000000;
71
71
<span class="comment">// This procedure creates very dense bitvectors.</span>
72
72
<span class="comment">// The resulting set will consists mostly from ON (1) bits</span>
73
73
<span class="comment">// interrupted with small gaps of 0 bits.</span>
75
<span class="keywordtype">void</span> <a name="a1"></a><a class="code" href="a00109.html#a6c4e3c21afef90ce9111f8f5e60d4c13">fill_bvector</a>(<a name="_a2"></a><a class="code" href="a00044.html" title="bitvector with runtime compression of bits.">bm::bvector<></a>* bv1, <a class="code" href="a00044.html" title="bitvector with runtime compression of bits.">bm::bvector<></a>* bv2)
75
<span class="keywordtype">void</span> <a name="a1"></a><a class="code" href="a00108.html#a6c4e3c21afef90ce9111f8f5e60d4c13">fill_bvector</a>(<a name="_a2"></a><a class="code" href="a00043.html" title="bitvector with runtime compression of bits.">bm::bvector<></a>* bv1, <a class="code" href="a00043.html" title="bitvector with runtime compression of bits.">bm::bvector<></a>* bv2)
77
<span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0; i < <a class="code" href="a00109.html#a8652d848be89c1f9b0a77327ee32fc0f">MAX_VALUE</a>; ++i)
77
<span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0; i < <a class="code" href="a00108.html#a8652d848be89c1f9b0a77327ee32fc0f">MAX_VALUE</a>; ++i)
79
79
<span class="keywordflow">if</span> (rand() % 2500)
81
bv1-><a name="a3"></a><a class="code" href="a00044.html#a1769d9ed3a4ee41b03fc3ca4a0e5a58e" title="Sets bit n.">set_bit</a>(i);
82
bv2-><a class="code" href="a00044.html#a1769d9ed3a4ee41b03fc3ca4a0e5a58e" title="Sets bit n.">set_bit</a>(i);
81
bv1-><a name="a3"></a><a class="code" href="a00043.html#aecf79c2c05bda3445ade2e10b61066b7" title="Sets bit n.">set_bit</a>(i);
82
bv2-><a class="code" href="a00043.html#aecf79c2c05bda3445ade2e10b61066b7" title="Sets bit n.">set_bit</a>(i);
88
<span class="keywordtype">void</span> <a name="a4"></a><a class="code" href="a00109.html#aeb4ca6f0a986ad6ae67d1f7124fdc400">print_statistics</a>(<span class="keyword">const</span> <a class="code" href="a00044.html" title="bitvector with runtime compression of bits.">bm::bvector<></a>& bv)
88
<span class="keywordtype">void</span> <a name="a4"></a><a class="code" href="a00108.html#aeb4ca6f0a986ad6ae67d1f7124fdc400">print_statistics</a>(<span class="keyword">const</span> <a class="code" href="a00043.html" title="bitvector with runtime compression of bits.">bm::bvector<></a>& bv)
90
<a name="_a5"></a><a class="code" href="a00086.html" title="Statistical information about bitset&#39;s memory allocation details.">bm::bvector<>::statistics</a> st;
91
bv.<a name="a6"></a><a class="code" href="a00044.html#a1eaaac76a97b9eb1d3c11f21cf9385ac" title="Calculates bitvector statistics.">calc_stat</a>(&st);
90
<a name="_a5"></a><a class="code" href="a00085.html" title="Statistical information about bitset&#39;s memory allocation details.">bm::bvector<>::statistics</a> st;
91
bv.<a name="a6"></a><a class="code" href="a00043.html#a61cd78a95b33d4759b5b8b535713dc50" title="Calculates bitvector statistics.">calc_stat</a>(&st);
93
cout << <span class="stringliteral">"Bits count:"</span> << bv.<a name="a7"></a><a class="code" href="a00044.html#a71077c1315555301532e24d4d2b95ea2" title="Returns count of bits which are 1.">count</a>() << endl;
94
cout << <span class="stringliteral">"Bit blocks:"</span> << st.<a name="a8"></a><a class="code" href="a00043.html#a4ec8ba190b4ba31c431c008402881c62" title="Number of bit blocks.">bit_blocks</a> << endl;
95
cout << <span class="stringliteral">"GAP blocks:"</span> << st.<a name="a9"></a><a class="code" href="a00043.html#a4dcfd64e9ab0be5472e3c2b04e551f81" title="Number of GAP blocks.">gap_blocks</a> << endl;
96
cout << <span class="stringliteral">"Memory used:"</span><< st.<a name="a10"></a><a class="code" href="a00043.html#ad3b2190eb4afe24ecd56323cbc0a7666" title="Memory used by bitvector including temp and service blocks.">memory_used</a> << endl;
97
cout << <span class="stringliteral">"Max.serialize mem.:"</span> << st.<a name="a11"></a><a class="code" href="a00043.html#a92f800e8649a1455c17019c8ec882b4b" title="Estimated maximum of memory required for serialization.">max_serialize_mem</a> << endl << endl;;
93
cout << <span class="stringliteral">"Bits count:"</span> << bv.<a name="a7"></a><a class="code" href="a00043.html#aceb122f712580c4be455099784bea72f" title="Returns count of bits which are 1.">count</a>() << endl;
94
cout << <span class="stringliteral">"Bit blocks:"</span> << st.<a name="a8"></a><a class="code" href="a00042.html#a4ec8ba190b4ba31c431c008402881c62" title="Number of bit blocks.">bit_blocks</a> << endl;
95
cout << <span class="stringliteral">"GAP blocks:"</span> << st.<a name="a9"></a><a class="code" href="a00042.html#a4dcfd64e9ab0be5472e3c2b04e551f81" title="Number of GAP blocks.">gap_blocks</a> << endl;
96
cout << <span class="stringliteral">"Memory used:"</span><< st.<a name="a10"></a><a class="code" href="a00042.html#ad3b2190eb4afe24ecd56323cbc0a7666" title="Memory used by bitvector including temp and service blocks.">memory_used</a> << endl;
97
cout << <span class="stringliteral">"Max.serialize mem.:"</span> << st.<a name="a11"></a><a class="code" href="a00042.html#a92f800e8649a1455c17019c8ec882b4b" title="Estimated maximum of memory required for serialization.">max_serialize_mem</a> << endl << endl;;
101
<span class="keywordtype">int</span> <a name="a12"></a><a class="code" href="a00106.html#a840291bc02cba5474a4cb46a9b9566fe">main</a>(<span class="keywordtype">void</span>)
101
<span class="keywordtype">int</span> <a name="a12"></a><a class="code" href="a00105.html#a840291bc02cba5474a4cb46a9b9566fe">main</a>(<span class="keywordtype">void</span>)
103
<a class="code" href="a00044.html" title="bitvector with runtime compression of bits.">bm::bvector<></a> bv1;
104
<a class="code" href="a00044.html" title="bitvector with runtime compression of bits.">bm::bvector<></a> bv2;
106
bv2.<a name="a13"></a><a class="code" href="a00044.html#ab1094180d03cbc961d62f0f453097452" title="Sets new blocks allocation strategy.">set_new_blocks_strat</a>(<a name="a14"></a><a class="code" href="a00119.html#ggad0b87b3b7292383a864d27feaf1c9effa7fe09d1d7c62a813db922c396c0cbc9c" title="GAP compression is ON.">bm::BM_GAP</a>); <span class="comment">// set DGAP compression mode ON</span>
108
<a class="code" href="a00109.html#a6c4e3c21afef90ce9111f8f5e60d4c13">fill_bvector</a>(&bv1, &bv2); <span class="comment">// Fill both bvectors with the same values</span>
103
<a class="code" href="a00043.html" title="bitvector with runtime compression of bits.">bm::bvector<></a> bv1;
104
<a class="code" href="a00043.html" title="bitvector with runtime compression of bits.">bm::bvector<></a> bv2;
106
bv2.<a name="a13"></a><a class="code" href="a00043.html#a653ee052b297a49c35344704df67a452" title="Sets new blocks allocation strategy.">set_new_blocks_strat</a>(<a name="a14"></a><a class="code" href="a00118.html#ggad0b87b3b7292383a864d27feaf1c9effa7fe09d1d7c62a813db922c396c0cbc9c" title="GAP compression is ON.">bm::BM_GAP</a>); <span class="comment">// set DGAP compression mode ON</span>
108
<a class="code" href="a00108.html#a6c4e3c21afef90ce9111f8f5e60d4c13">fill_bvector</a>(&bv1, &bv2); <span class="comment">// Fill both bvectors with the same values</span>
110
110
<span class="comment">// For a given distrubution statistics should demonstrate</span>
111
111
<span class="comment">// lower memory consumption for the vector with compression</span>
113
<a class="code" href="a00109.html#aeb4ca6f0a986ad6ae67d1f7124fdc400">print_statistics</a>(bv1);
114
<a class="code" href="a00109.html#aeb4ca6f0a986ad6ae67d1f7124fdc400">print_statistics</a>(bv2);
113
<a class="code" href="a00108.html#aeb4ca6f0a986ad6ae67d1f7124fdc400">print_statistics</a>(bv1);
114
<a class="code" href="a00108.html#aeb4ca6f0a986ad6ae67d1f7124fdc400">print_statistics</a>(bv2);
116
116
<span class="comment">// Now run optimization procedure for bv1 and see statistics.</span>
118
bv1.<a name="a15"></a><a class="code" href="a00044.html#abd522c13e26c2b8f84636fe8b6648dcb" title="Optimize memory bitvector&#39;s memory allocation.">optimize</a>();
118
bv1.<a name="a15"></a><a class="code" href="a00043.html#a622e6827d799a561e2f0db28f7ac19d2" title="Optimize memory bitvector&#39;s memory allocation.">optimize</a>();
120
<a class="code" href="a00109.html#aeb4ca6f0a986ad6ae67d1f7124fdc400">print_statistics</a>(bv1);
120
<a class="code" href="a00108.html#aeb4ca6f0a986ad6ae67d1f7124fdc400">print_statistics</a>(bv1);
122
122
<span class="keywordflow">return</span> 0;
125
125
</pre></div> </div>
126
<hr size="1"/><address style="text-align: right;"><small>Generated on Tue Mar 23 20:47:54 2010 for BitMagic by
126
<hr size="1"/><address style="text-align: right;"><small>Generated on Sun Apr 25 09:37:27 2010 for BitMagic by
127
127
<a href="http://www.doxygen.org/index.html">
128
128
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>