~ubuntu-branches/ubuntu/trusty/bmagic/trusty

« back to all changes in this revision

Viewing changes to doc/html/a00003.html

  • Committer: Bazaar Package Importer
  • Author(s): Roberto C. Sanchez
  • Date: 2010-01-24 14:45:39 UTC
  • mfrom: (4.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20100124144539-4ipk5rt64dpp38hl
Tags: 3.6.3-1
* New upstream release
* debian/patches/config.guess.patch: drop obsolete patch
* Add ${misc:Depends} as requested by lintian

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
</div>
23
23
<div class="contents">
24
24
<h1>sample3.cpp</h1><p>Exmaple demonstrates using bitvectors with different initial block allocation strategy. Bitvector 1 (bv1) by default working without RLE compression option (best performance, maximum memory consumption). Bitvector 2 (bv2) will be working in compression mode and use less memory.</p>
25
 
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="a00043.html#ab1094180d03cbc961d62f0f453097452" title="Sets new blocks allocation strategy.">bm::bvector&lt;&gt;::set_new_blocks_strat()</a></dd></dl>
 
25
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="a00044.html#ab1094180d03cbc961d62f0f453097452" title="Sets new blocks allocation strategy.">bm::bvector&lt;&gt;::set_new_blocks_strat()</a></dd></dl>
26
26
<p>For more information please visit: <a href="http://bmagic.sourceforge.net">http://bmagic.sourceforge.net</a></p>
27
27
<div class="fragment"><pre class="fragment"><span class="comment">/*</span>
28
28
<span class="comment">Copyright(c) 2002-2005 Anatoliy Kuznetsov(anatoliy_kuznetsov at yahoo.com)</span>
62
62
 
63
63
<span class="preprocessor">#include &lt;stdlib.h&gt;</span>
64
64
<span class="preprocessor">#include &lt;iostream&gt;</span>
65
 
<span class="preprocessor">#include &quot;<a class="code" href="a00084.html">bm.h</a>&quot;</span>
 
65
<span class="preprocessor">#include &quot;<a class="code" href="a00087.html">bm.h</a>&quot;</span>
66
66
 
67
67
<span class="keyword">using namespace </span>std;
68
68
 
69
 
<span class="keyword">const</span> <span class="keywordtype">unsigned</span> <a name="a0"></a><a class="code" href="a00103.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;
70
70
 
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>
74
74
 
75
 
<span class="keywordtype">void</span> <a name="a1"></a><a class="code" href="a00103.html#a6c4e3c21afef90ce9111f8f5e60d4c13">fill_bvector</a>(<a name="_a2"></a><a class="code" href="a00043.html" title="bitvector with runtime compression of bits.">bm::bvector&lt;&gt;</a>* bv1, <a class="code" href="a00043.html" title="bitvector with runtime compression of bits.">bm::bvector&lt;&gt;</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="a00044.html" title="bitvector with runtime compression of bits.">bm::bvector&lt;&gt;</a>* bv1, <a class="code" href="a00044.html" title="bitvector with runtime compression of bits.">bm::bvector&lt;&gt;</a>* bv2)
76
76
{
77
 
    <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0; i &lt; <a class="code" href="a00103.html#a8652d848be89c1f9b0a77327ee32fc0f">MAX_VALUE</a>; ++i)
 
77
    <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0; i &lt; <a class="code" href="a00108.html#a8652d848be89c1f9b0a77327ee32fc0f">MAX_VALUE</a>; ++i)
78
78
    {
79
79
        <span class="keywordflow">if</span> (rand() % 2500)
80
80
        {
81
 
            bv1-&gt;<a name="a3"></a><a class="code" href="a00043.html#a1769d9ed3a4ee41b03fc3ca4a0e5a58e" title="Sets bit n.">set_bit</a>(i);
82
 
            bv2-&gt;<a class="code" href="a00043.html#a1769d9ed3a4ee41b03fc3ca4a0e5a58e" title="Sets bit n.">set_bit</a>(i);
 
81
            bv1-&gt;<a name="a3"></a><a class="code" href="a00044.html#a1769d9ed3a4ee41b03fc3ca4a0e5a58e" title="Sets bit n.">set_bit</a>(i);
 
82
            bv2-&gt;<a class="code" href="a00044.html#a1769d9ed3a4ee41b03fc3ca4a0e5a58e" title="Sets bit n.">set_bit</a>(i);
83
83
        }
84
84
    }
85
85
}
86
86
 
87
87
 
88
 
<span class="keywordtype">void</span> <a name="a4"></a><a class="code" href="a00103.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&lt;&gt;</a>&amp; 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="a00044.html" title="bitvector with runtime compression of bits.">bm::bvector&lt;&gt;</a>&amp; bv)
89
89
{
90
 
    <a name="_a5"></a><a class="code" href="a00082.html" title="Statistical information about bitset&amp;#39;s memory allocation details.">bm::bvector&lt;&gt;::statistics</a> st;
91
 
    bv.<a name="a6"></a><a class="code" href="a00043.html#a1eaaac76a97b9eb1d3c11f21cf9385ac" title="Calculates bitvector statistics.">calc_stat</a>(&amp;st);
 
90
    <a name="_a5"></a><a class="code" href="a00085.html" title="Statistical information about bitset&amp;#39;s memory allocation details.">bm::bvector&lt;&gt;::statistics</a> st;
 
91
    bv.<a name="a6"></a><a class="code" href="a00044.html#a1eaaac76a97b9eb1d3c11f21cf9385ac" title="Calculates bitvector statistics.">calc_stat</a>(&amp;st);
92
92
 
93
 
    cout &lt;&lt; <span class="stringliteral">&quot;Bits count:&quot;</span> &lt;&lt; bv.<a name="a7"></a><a class="code" href="a00043.html#a71077c1315555301532e24d4d2b95ea2" title="Returns count of bits which are 1.">count</a>() &lt;&lt; endl;
94
 
    cout &lt;&lt; <span class="stringliteral">&quot;Bit blocks:&quot;</span> &lt;&lt; st.<a name="a8"></a><a class="code" href="a00042.html#a4ec8ba190b4ba31c431c008402881c62" title="Number of bit blocks.">bit_blocks</a> &lt;&lt; endl;
95
 
    cout &lt;&lt; <span class="stringliteral">&quot;GAP blocks:&quot;</span> &lt;&lt; st.<a name="a9"></a><a class="code" href="a00042.html#a4dcfd64e9ab0be5472e3c2b04e551f81" title="Number of GAP blocks.">gap_blocks</a> &lt;&lt; endl;
96
 
    cout &lt;&lt; <span class="stringliteral">&quot;Memory used:&quot;</span>&lt;&lt; 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> &lt;&lt; endl;
97
 
    cout &lt;&lt; <span class="stringliteral">&quot;Max.serialize mem.:&quot;</span> &lt;&lt; st.<a name="a11"></a><a class="code" href="a00042.html#a92f800e8649a1455c17019c8ec882b4b" title="Estimated maximum of memory required for serialization.">max_serialize_mem</a> &lt;&lt; endl &lt;&lt; endl;;
 
93
    cout &lt;&lt; <span class="stringliteral">&quot;Bits count:&quot;</span> &lt;&lt; bv.<a name="a7"></a><a class="code" href="a00044.html#a71077c1315555301532e24d4d2b95ea2" title="Returns count of bits which are 1.">count</a>() &lt;&lt; endl;
 
94
    cout &lt;&lt; <span class="stringliteral">&quot;Bit blocks:&quot;</span> &lt;&lt; st.<a name="a8"></a><a class="code" href="a00043.html#a4ec8ba190b4ba31c431c008402881c62" title="Number of bit blocks.">bit_blocks</a> &lt;&lt; endl;
 
95
    cout &lt;&lt; <span class="stringliteral">&quot;GAP blocks:&quot;</span> &lt;&lt; st.<a name="a9"></a><a class="code" href="a00043.html#a4dcfd64e9ab0be5472e3c2b04e551f81" title="Number of GAP blocks.">gap_blocks</a> &lt;&lt; endl;
 
96
    cout &lt;&lt; <span class="stringliteral">&quot;Memory used:&quot;</span>&lt;&lt; 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> &lt;&lt; endl;
 
97
    cout &lt;&lt; <span class="stringliteral">&quot;Max.serialize mem.:&quot;</span> &lt;&lt; st.<a name="a11"></a><a class="code" href="a00043.html#a92f800e8649a1455c17019c8ec882b4b" title="Estimated maximum of memory required for serialization.">max_serialize_mem</a> &lt;&lt; endl &lt;&lt; endl;;
98
98
}
99
99
 
100
100
 
101
 
<span class="keywordtype">int</span> <a name="a12"></a><a class="code" href="a00101.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>)
102
102
{
103
 
    <a class="code" href="a00043.html" title="bitvector with runtime compression of bits.">bm::bvector&lt;&gt;</a>   bv1;    
104
 
    <a class="code" href="a00043.html" title="bitvector with runtime compression of bits.">bm::bvector&lt;&gt;</a>   bv2;
105
 
 
106
 
    bv2.<a name="a13"></a><a class="code" href="a00043.html#ab1094180d03cbc961d62f0f453097452" title="Sets new blocks allocation strategy.">set_new_blocks_strat</a>(<a name="a14"></a><a class="code" href="a00113.html#ggad0b87b3b7292383a864d27feaf1c9effa7fe09d1d7c62a813db922c396c0cbc9c" title="GAP compression is ON.">bm::BM_GAP</a>);  <span class="comment">//  set DGAP compression mode ON</span>
107
 
 
108
 
    <a class="code" href="a00103.html#a6c4e3c21afef90ce9111f8f5e60d4c13">fill_bvector</a>(&amp;bv1, &amp;bv2);  <span class="comment">// Fill both bvectors with the same values</span>
 
103
    <a class="code" href="a00044.html" title="bitvector with runtime compression of bits.">bm::bvector&lt;&gt;</a>   bv1;    
 
104
    <a class="code" href="a00044.html" title="bitvector with runtime compression of bits.">bm::bvector&lt;&gt;</a>   bv2;
 
105
 
 
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="a00118.html#ggad0b87b3b7292383a864d27feaf1c9effa7fe09d1d7c62a813db922c396c0cbc9c" title="GAP compression is ON.">bm::BM_GAP</a>);  <span class="comment">//  set DGAP compression mode ON</span>
 
107
 
 
108
    <a class="code" href="a00108.html#a6c4e3c21afef90ce9111f8f5e60d4c13">fill_bvector</a>(&amp;bv1, &amp;bv2);  <span class="comment">// Fill both bvectors with the same values</span>
109
109
 
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>
112
112
 
113
 
    <a class="code" href="a00103.html#aeb4ca6f0a986ad6ae67d1f7124fdc400">print_statistics</a>(bv1);    
114
 
    <a class="code" href="a00103.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);
115
115
 
116
116
    <span class="comment">// Now run optimization procedure for bv1 and see statistics.</span>
117
117
 
118
 
    bv1.<a name="a15"></a><a class="code" href="a00043.html#abd522c13e26c2b8f84636fe8b6648dcb" title="Optimize memory bitvector&amp;#39;s memory allocation.">optimize</a>();
 
118
    bv1.<a name="a15"></a><a class="code" href="a00044.html#abd522c13e26c2b8f84636fe8b6648dcb" title="Optimize memory bitvector&amp;#39;s memory allocation.">optimize</a>();
119
119
 
120
 
    <a class="code" href="a00103.html#aeb4ca6f0a986ad6ae67d1f7124fdc400">print_statistics</a>(bv1);    
 
120
    <a class="code" href="a00108.html#aeb4ca6f0a986ad6ae67d1f7124fdc400">print_statistics</a>(bv1);    
121
121
 
122
122
    <span class="keywordflow">return</span> 0;
123
123
}
124
124
 
125
125
</pre></div> </div>
126
 
<hr size="1"/><address style="text-align: right;"><small>Generated on Sun Nov 22 10:49:34 2009 for BitMagic by&nbsp;
 
126
<hr size="1"/><address style="text-align: right;"><small>Generated on Fri Jan 8 20:09:19 2010 for BitMagic by&nbsp;
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>
129
129
</body>