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

« back to all changes in this revision

Viewing changes to doc/html/a00003.html

  • Committer: Bazaar Package Importer
  • Author(s): Roberto C. Sanchez
  • Date: 2009-10-30 18:48:35 UTC
  • mfrom: (4.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20091030184835-2tqroygiq2pevwij
Tags: 3.6.0-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 
2
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
 
3
<title>BitMagic: sample3.cpp</title>
 
4
<link href="doxygen.css" rel="stylesheet" type="text/css">
 
5
<link href="tabs.css" rel="stylesheet" type="text/css">
 
6
</head><body>
 
7
<!-- Generated by Doxygen 1.5.5 -->
 
8
<div class="navigation" id="top">
 
9
  <div class="tabs">
 
10
    <ul>
 
11
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
 
12
      <li><a href="modules.html"><span>Modules</span></a></li>
 
13
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
 
14
      <li><a href="classes.html"><span>Data&nbsp;Structures</span></a></li>
 
15
      <li><a href="files.html"><span>Files</span></a></li>
 
16
      <li><a href="examples.html"><span>Examples</span></a></li>
 
17
    </ul>
 
18
  </div>
 
19
</div>
 
20
<div class="contents">
 
21
<h1>sample3.cpp</h1>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>
 
22
<dl class="see" compact><dt><b>See also:</b></dt><dd><a class="el" href="a00040.html#b1094180d03cbc961d62f0f453097452" title="Sets new blocks allocation strategy.">bm::bvector&lt;&gt;::set_new_blocks_strat()</a></dd></dl>
 
23
For more information please visit: <a href="http://bmagic.sourceforge.net">http://bmagic.sourceforge.net</a><p>
 
24
<div class="fragment"><pre class="fragment"><span class="comment">/*</span>
 
25
<span class="comment">Copyright(c) 2002-2005 Anatoliy Kuznetsov(anatoliy_kuznetsov at yahoo.com)</span>
 
26
<span class="comment"></span>
 
27
<span class="comment">Permission is hereby granted, free of charge, to any person </span>
 
28
<span class="comment">obtaining a copy of this software and associated documentation </span>
 
29
<span class="comment">files (the "Software"), to deal in the Software without restriction, </span>
 
30
<span class="comment">including without limitation the rights to use, copy, modify, merge, </span>
 
31
<span class="comment">publish, distribute, sublicense, and/or sell copies of the Software, </span>
 
32
<span class="comment">and to permit persons to whom the Software is furnished to do so, </span>
 
33
<span class="comment">subject to the following conditions:</span>
 
34
<span class="comment"></span>
 
35
<span class="comment">The above copyright notice and this permission notice shall be included </span>
 
36
<span class="comment">in all copies or substantial portions of the Software.</span>
 
37
<span class="comment"></span>
 
38
<span class="comment">THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, </span>
 
39
<span class="comment">EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES </span>
 
40
<span class="comment">OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. </span>
 
41
<span class="comment">IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, </span>
 
42
<span class="comment">DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, </span>
 
43
<span class="comment">ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR </span>
 
44
<span class="comment">OTHER DEALINGS IN THE SOFTWARE.</span>
 
45
<span class="comment">*/</span>
 
46
<span class="comment"></span>
 
47
<span class="comment">/** \example sample3.cpp</span>
 
48
<span class="comment"> Exmaple demonstrates using bitvectors with different initial</span>
 
49
<span class="comment"> block allocation strategy. </span>
 
50
<span class="comment"> Bitvector 1 (bv1) by default working without RLE compression option</span>
 
51
<span class="comment"> (best performance, maximum memory consumption). </span>
 
52
<span class="comment"> Bitvector 2 (bv2) will be working in compression mode and use less memory.</span>
 
53
<span class="comment"> </span>
 
54
<span class="comment">  \sa bm::bvector&lt;&gt;::set_new_blocks_strat() </span>
 
55
<span class="comment"></span>
 
56
<span class="comment">  For more information please visit: http://bmagic.sourceforge.net</span>
 
57
<span class="comment"></span>
 
58
<span class="comment">*/</span>
 
59
 
 
60
<span class="preprocessor">#include &lt;stdlib.h&gt;</span>
 
61
<span class="preprocessor">#include &lt;iostream&gt;</span>
 
62
<span class="preprocessor">#include "<a class="code" href="a00082.html">bm.h</a>"</span>
 
63
 
 
64
<span class="keyword">using namespace </span>std;
 
65
 
 
66
<span class="keyword">const</span> <span class="keywordtype">unsigned</span> <a name="a0"></a><a class="code" href="a00099.html#8652d848be89c1f9b0a77327ee32fc0f">MAX_VALUE</a> = 1000000;
 
67
 
 
68
<span class="comment">// This procedure creates very dense bitvectors.</span>
 
69
<span class="comment">// The resulting set will consists mostly from ON (1) bits</span>
 
70
<span class="comment">// interrupted with small gaps of 0 bits.</span>
 
71
 
 
72
<span class="keywordtype">void</span> <a name="a1"></a><a class="code" href="a00099.html#6c4e3c21afef90ce9111f8f5e60d4c13">fill_bvector</a>(<a name="_a2"></a><a class="code" href="a00040.html" title="bitvector with runtime compression of bits.">bm::bvector&lt;&gt;</a>* bv1, <a class="code" href="a00040.html" title="bitvector with runtime compression of bits.">bm::bvector&lt;&gt;</a>* bv2)
 
73
{
 
74
    <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0; i &lt; <a class="code" href="a00099.html#8652d848be89c1f9b0a77327ee32fc0f">MAX_VALUE</a>; ++i)
 
75
    {
 
76
        <span class="keywordflow">if</span> (rand() % 2500)
 
77
        {
 
78
            bv1-&gt;<a name="a3"></a><a class="code" href="a00040.html#1769d9ed3a4ee41b03fc3ca4a0e5a58e" title="Sets bit n.">set_bit</a>(i);
 
79
            bv2-&gt;<a class="code" href="a00040.html#1769d9ed3a4ee41b03fc3ca4a0e5a58e" title="Sets bit n.">set_bit</a>(i);
 
80
        }
 
81
    }
 
82
}
 
83
 
 
84
 
 
85
<span class="keywordtype">void</span> <a name="a4"></a><a class="code" href="a00099.html#eb4ca6f0a986ad6ae67d1f7124fdc400">print_statistics</a>(<span class="keyword">const</span> <a class="code" href="a00040.html" title="bitvector with runtime compression of bits.">bm::bvector&lt;&gt;</a>&amp; bv)
 
86
{
 
87
    <a class="code" href="a00040.html" title="bitvector with runtime compression of bits.">bm::bvector&lt;&gt;::statistics</a> st;
 
88
    bv.<a name="a5"></a><a class="code" href="a00040.html#1eaaac76a97b9eb1d3c11f21cf9385ac" title="Calculates bitvector statistics.">calc_stat</a>(&amp;st);
 
89
 
 
90
    cout &lt;&lt; <span class="stringliteral">"Bits count:"</span> &lt;&lt; bv.<a name="a6"></a><a class="code" href="a00040.html#71077c1315555301532e24d4d2b95ea2" title="Returns count of bits which are 1.">count</a>() &lt;&lt; endl;
 
91
    cout &lt;&lt; <span class="stringliteral">"Bit blocks:"</span> &lt;&lt; st.bit_blocks &lt;&lt; endl;
 
92
    cout &lt;&lt; <span class="stringliteral">"GAP blocks:"</span> &lt;&lt; st.gap_blocks &lt;&lt; endl;
 
93
    cout &lt;&lt; <span class="stringliteral">"Memory used:"</span>&lt;&lt; st.memory_used &lt;&lt; endl;
 
94
    cout &lt;&lt; <span class="stringliteral">"Max.serialize mem.:"</span> &lt;&lt; st.max_serialize_mem &lt;&lt; endl &lt;&lt; endl;;
 
95
}
 
96
 
 
97
 
 
98
<span class="keywordtype">int</span> <a name="a7"></a><a class="code" href="a00097.html#840291bc02cba5474a4cb46a9b9566fe">main</a>(<span class="keywordtype">void</span>)
 
99
{
 
100
    <a class="code" href="a00040.html" title="bitvector with runtime compression of bits.">bm::bvector&lt;&gt;</a>   bv1;    
 
101
    <a class="code" href="a00040.html" title="bitvector with runtime compression of bits.">bm::bvector&lt;&gt;</a>   bv2;
 
102
 
 
103
    bv2.<a name="a8"></a><a class="code" href="a00040.html#b1094180d03cbc961d62f0f453097452" title="Sets new blocks allocation strategy.">set_new_blocks_strat</a>(<a name="a9"></a><a class="code" href="a00109.html#ggd0b87b3b7292383a864d27feaf1c9eff7fe09d1d7c62a813db922c396c0cbc9c" title="GAP compression is ON.">bm::BM_GAP</a>);  <span class="comment">//  set DGAP compression mode ON</span>
 
104
 
 
105
    <a class="code" href="a00099.html#6c4e3c21afef90ce9111f8f5e60d4c13">fill_bvector</a>(&amp;bv1, &amp;bv2);  <span class="comment">// Fill both bvectors with the same values</span>
 
106
 
 
107
    <span class="comment">// For a given distrubution statistics should demonstrate</span>
 
108
    <span class="comment">// lower memory consumption for the vector with compression</span>
 
109
 
 
110
    <a class="code" href="a00099.html#eb4ca6f0a986ad6ae67d1f7124fdc400">print_statistics</a>(bv1);    
 
111
    <a class="code" href="a00099.html#eb4ca6f0a986ad6ae67d1f7124fdc400">print_statistics</a>(bv2);
 
112
 
 
113
    <span class="comment">// Now run optimization procedure for bv1 and see statistics.</span>
 
114
 
 
115
    bv1.<a name="a10"></a><a class="code" href="a00040.html#bd522c13e26c2b8f84636fe8b6648dcb" title="Optimize memory bitvector&amp;#39;s memory allocation.">optimize</a>();
 
116
 
 
117
    <a class="code" href="a00099.html#eb4ca6f0a986ad6ae67d1f7124fdc400">print_statistics</a>(bv1);    
 
118
 
 
119
    <span class="keywordflow">return</span> 0;
 
120
}
 
121
 
 
122
</pre></div> </div>
 
123
<hr size="1"><address style="text-align: right;"><small>Generated on Mon Oct 12 12:16:38 2009 for BitMagic by&nbsp;
 
124
<a href="http://www.doxygen.org/index.html">
 
125
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.5 </small></address>
 
126
</body>
 
127
</html>