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

« back to all changes in this revision

Viewing changes to html/a00148.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=iso-8859-1">
3
 
<title>BitMagic: sample3.cpp Source File</title>
4
 
<link href="doxygen.css" rel="stylesheet" type="text/css">
5
 
</head><body>
6
 
<!-- Generated by Doxygen 1.4.1 -->
7
 
<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="namespacemembers.html">Namespace&nbsp;Members</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="examples.html">Examples</a></div>
8
 
<div class="nav">
9
 
<a class="el" href="dir_000001.html">samples</a>&nbsp;/&nbsp;<a class="el" href="dir_000004.html">sample3</a></div>
10
 
<h1>sample3.cpp</h1><a href="a00122.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*</span>
11
 
00002 <span class="comment">Copyright(c) 2002-2005 Anatoliy Kuznetsov(anatoliy_kuznetsov at yahoo.com)</span>
12
 
00003 <span class="comment"></span>
13
 
00004 <span class="comment">Permission is hereby granted, free of charge, to any person </span>
14
 
00005 <span class="comment">obtaining a copy of this software and associated documentation </span>
15
 
00006 <span class="comment">files (the "Software"), to deal in the Software without restriction, </span>
16
 
00007 <span class="comment">including without limitation the rights to use, copy, modify, merge, </span>
17
 
00008 <span class="comment">publish, distribute, sublicense, and/or sell copies of the Software, </span>
18
 
00009 <span class="comment">and to permit persons to whom the Software is furnished to do so, </span>
19
 
00010 <span class="comment">subject to the following conditions:</span>
20
 
00011 <span class="comment"></span>
21
 
00012 <span class="comment">The above copyright notice and this permission notice shall be included </span>
22
 
00013 <span class="comment">in all copies or substantial portions of the Software.</span>
23
 
00014 <span class="comment"></span>
24
 
00015 <span class="comment">THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, </span>
25
 
00016 <span class="comment">EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES </span>
26
 
00017 <span class="comment">OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. </span>
27
 
00018 <span class="comment">IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, </span>
28
 
00019 <span class="comment">DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, </span>
29
 
00020 <span class="comment">ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR </span>
30
 
00021 <span class="comment">OTHER DEALINGS IN THE SOFTWARE.</span>
31
 
00022 <span class="comment">*/</span>
32
 
00023 <span class="comment"></span>
33
 
00024 <span class="comment">/** \example sample3.cpp</span>
34
 
00025 <span class="comment"> Exmaple demonstrates using bitvectors with different initial</span>
35
 
00026 <span class="comment"> block allocation strategy. </span>
36
 
00027 <span class="comment"> Bitvector 1 (bv1) by default working without RLE compression option</span>
37
 
00028 <span class="comment"> (best performance, maximum memory consumption). </span>
38
 
00029 <span class="comment"> Bitvector 2 (bv2) will be working in compression mode and use less memory.</span>
39
 
00030 <span class="comment"> </span>
40
 
00031 <span class="comment">  \sa bm::bvector&lt;&gt;::set_new_blocks_strat() </span>
41
 
00032 <span class="comment"></span>
42
 
00033 <span class="comment">  For more information please visit: http://bmagic.sourceforge.net</span>
43
 
00034 <span class="comment"></span>
44
 
00035 <span class="comment">*/</span>
45
 
00036 
46
 
00037 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
47
 
00038 <span class="preprocessor">#include &lt;iostream&gt;</span>
48
 
00039 <span class="preprocessor">#include "<a class="code" href="a00111.html">bm.h</a>"</span>
49
 
00040 
50
 
00041 <span class="keyword">using</span> <span class="keyword">namespace </span>std;
51
 
00042 
52
 
<a name="l00043"></a><a class="code" href="a00122.html#a0">00043</a> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <a class="code" href="a00122.html#a0">MAX_VALUE</a> = 1000000;
53
 
00044 
54
 
00045 <span class="comment">// This procedure creates very dense bitvectors.</span>
55
 
00046 <span class="comment">// The resulting set will consists mostly from ON (1) bits</span>
56
 
00047 <span class="comment">// interrupted with small gaps of 0 bits.</span>
57
 
00048 
58
 
<a name="l00049"></a><a class="code" href="a00122.html#a1">00049</a> <span class="keywordtype">void</span> <a class="code" href="a00122.html#a1">fill_bvector</a>(<a class="code" href="a00084.html">bm::bvector&lt;&gt;</a>* bv1, <a class="code" href="a00084.html">bm::bvector&lt;&gt;</a>* bv2)
59
 
00050 {
60
 
00051     <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0; i &lt; <a class="code" href="a00122.html#a0">MAX_VALUE</a>; ++i)
61
 
00052     {
62
 
00053         <span class="keywordflow">if</span> (rand() % 2500)
63
 
00054         {
64
 
00055             bv1-&gt;set_bit(i);
65
 
00056             bv2-&gt;set_bit(i);
66
 
00057         }
67
 
00058     }
68
 
00059 }
69
 
00060 
70
 
00061 
71
 
<a name="l00062"></a><a class="code" href="a00122.html#a2">00062</a> <span class="keywordtype">void</span> <a class="code" href="a00122.html#a2">print_statistics</a>(<span class="keyword">const</span> <a class="code" href="a00084.html">bm::bvector&lt;&gt;</a>&amp; bv)
72
 
00063 {
73
 
00064     <a class="code" href="a00084.html">bm::bvector&lt;&gt;</a>::statistics st;
74
 
00065     bv.calc_stat(&amp;st);
75
 
00066 
76
 
00067     cout &lt;&lt; <span class="stringliteral">"Bits count:"</span> &lt;&lt; bv.count() &lt;&lt; endl;
77
 
00068     cout &lt;&lt; <span class="stringliteral">"Bit blocks:"</span> &lt;&lt; st.bit_blocks &lt;&lt; endl;
78
 
00069     cout &lt;&lt; <span class="stringliteral">"GAP blocks:"</span> &lt;&lt; st.gap_blocks &lt;&lt; endl;
79
 
00070     cout &lt;&lt; <span class="stringliteral">"Memory used:"</span>&lt;&lt; st.memory_used &lt;&lt; endl;
80
 
00071     cout &lt;&lt; <span class="stringliteral">"Max.serialize mem.:"</span> &lt;&lt; st.max_serialize_mem &lt;&lt; endl &lt;&lt; endl;;
81
 
00072 }
82
 
00073 
83
 
00074 
84
 
<a name="l00075"></a><a class="code" href="a00122.html#a3">00075</a> <span class="keywordtype">int</span> <a class="code" href="a00120.html#a0">main</a>(<span class="keywordtype">void</span>)
85
 
00076 {
86
 
00077     <a class="code" href="a00084.html">bm::bvector&lt;&gt;</a>   bv1;    
87
 
00078     <a class="code" href="a00084.html">bm::bvector&lt;&gt;</a>   bv2;
88
 
00079 
89
 
00080     bv2.<a class="code" href="a00084.html#a52">set_new_blocks_strat</a>(bm::BM_GAP);  <span class="comment">//  set DGAP compression mode ON</span>
90
 
00081 
91
 
00082     <a class="code" href="a00122.html#a1">fill_bvector</a>(&amp;bv1, &amp;bv2);  <span class="comment">// Fill both bvectors with the same values</span>
92
 
00083 
93
 
00084     <span class="comment">// For a given distrubution statistics should demonstrate</span>
94
 
00085     <span class="comment">// lower memory consumption for the vector with compression</span>
95
 
00086 
96
 
00087     <a class="code" href="a00122.html#a2">print_statistics</a>(bv1);    
97
 
00088     <a class="code" href="a00122.html#a2">print_statistics</a>(bv2);
98
 
00089 
99
 
00090     <span class="comment">// Now run optimization procedure for bv1 and see statistics.</span>
100
 
00091 
101
 
00092     bv1.<a class="code" href="a00084.html#a55">optimize</a>();
102
 
00093 
103
 
00094     <a class="code" href="a00122.html#a2">print_statistics</a>(bv1);    
104
 
00095 
105
 
00096     <span class="keywordflow">return</span> 0;
106
 
00097 }
107
 
00098 
108
 
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Aug 5 14:12:26 2007 for BitMagic by&nbsp;
109
 
<a href="http://www.doxygen.org/index.html">
110
 
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.1 </small></address>
111
 
</body>
112
 
</html>