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

« back to all changes in this revision

Viewing changes to doc/html/a00109_source.html

  • Committer: Bazaar Package Importer
  • Author(s): Roberto C. Sanchez
  • Date: 2010-04-08 16:47:58 UTC
  • mfrom: (4.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100408164758-3vu6wmrk1dnzqnnj
Tags: 3.6.4-1
* New upstream release
* Update to Standards-Version 3.8.4 (no changes)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
<html xmlns="http://www.w3.org/1999/xhtml">
3
3
<head>
4
4
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
5
 
<title>BitMagic: sample4.cpp Source File</title>
 
5
<title>BitMagic: sample3.cpp Source File</title>
6
6
<link href="tabs.css" rel="stylesheet" type="text/css"/>
7
7
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
8
8
</head>
25
25
      <li><a href="globals.html"><span>Globals</span></a></li>
26
26
    </ul>
27
27
  </div>
28
 
<h1>sample4.cpp</h1><a href="a00109.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
29
 
<a name="l00002"></a>00002 <span class="comment">Copyright(c) 2002-2009 Anatoliy Kuznetsov(anatoliy_kuznetsov at yahoo.com)</span>
 
28
<h1>sample3.cpp</h1><a href="a00109.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
 
29
<a name="l00002"></a>00002 <span class="comment">Copyright(c) 2002-2005 Anatoliy Kuznetsov(anatoliy_kuznetsov at yahoo.com)</span>
30
30
<a name="l00003"></a>00003 <span class="comment"></span>
31
31
<a name="l00004"></a>00004 <span class="comment">Permission is hereby granted, free of charge, to any person </span>
32
32
<a name="l00005"></a>00005 <span class="comment">obtaining a copy of this software and associated documentation </span>
48
48
<a name="l00021"></a>00021 <span class="comment">OTHER DEALINGS IN THE SOFTWARE.</span>
49
49
<a name="l00022"></a>00022 <span class="comment">*/</span>
50
50
<a name="l00023"></a>00023 <span class="comment"></span>
51
 
<a name="l00024"></a>00024 <span class="comment">/** \example sample4.cpp</span>
52
 
<a name="l00025"></a>00025 <span class="comment"> Exmaple demonstrates bitvector serialization/deserialization.</span>
53
 
<a name="l00026"></a>00026 <span class="comment"> </span>
54
 
<a name="l00027"></a>00027 <span class="comment">For more information please visit:  http://bmagic.sourceforge.net</span>
55
 
<a name="l00028"></a>00028 <span class="comment"></span>
56
 
<a name="l00029"></a>00029 <span class="comment">  \sa bm::serializer</span>
57
 
<a name="l00030"></a>00030 <span class="comment">  \sa bm::deserialize </span>
58
 
<a name="l00031"></a>00031 <span class="comment"></span>
59
 
<a name="l00032"></a>00032 <span class="comment">*/</span>
60
 
<a name="l00033"></a>00033 
61
 
<a name="l00034"></a>00034 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
62
 
<a name="l00035"></a>00035 <span class="preprocessor">#include &lt;iostream&gt;</span>
63
 
<a name="l00036"></a>00036 <span class="preprocessor">#include &quot;<a class="code" href="a00087.html">bm.h</a>&quot;</span>
64
 
<a name="l00037"></a>00037 <span class="preprocessor">#include &quot;<a class="code" href="a00096.html">bmserial.h</a>&quot;</span>
65
 
<a name="l00038"></a>00038 
66
 
<a name="l00039"></a>00039 <span class="keyword">using namespace </span>std;
 
51
<a name="l00024"></a>00024 <span class="comment">/** \example sample3.cpp</span>
 
52
<a name="l00025"></a>00025 <span class="comment"> Exmaple demonstrates using bitvectors with different initial</span>
 
53
<a name="l00026"></a>00026 <span class="comment"> block allocation strategy. </span>
 
54
<a name="l00027"></a>00027 <span class="comment"> Bitvector 1 (bv1) by default working without RLE compression option</span>
 
55
<a name="l00028"></a>00028 <span class="comment"> (best performance, maximum memory consumption). </span>
 
56
<a name="l00029"></a>00029 <span class="comment"> Bitvector 2 (bv2) will be working in compression mode and use less memory.</span>
 
57
<a name="l00030"></a>00030 <span class="comment"> </span>
 
58
<a name="l00031"></a>00031 <span class="comment">  \sa bm::bvector&lt;&gt;::set_new_blocks_strat() </span>
 
59
<a name="l00032"></a>00032 <span class="comment"></span>
 
60
<a name="l00033"></a>00033 <span class="comment">  For more information please visit: http://bmagic.sourceforge.net</span>
 
61
<a name="l00034"></a>00034 <span class="comment"></span>
 
62
<a name="l00035"></a>00035 <span class="comment">*/</span>
 
63
<a name="l00036"></a>00036 
 
64
<a name="l00037"></a>00037 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
 
65
<a name="l00038"></a>00038 <span class="preprocessor">#include &lt;iostream&gt;</span>
 
66
<a name="l00039"></a>00039 <span class="preprocessor">#include &quot;<a class="code" href="a00088.html">bm.h</a>&quot;</span>
67
67
<a name="l00040"></a>00040 
68
 
<a name="l00041"></a>00041 
69
 
<a name="l00042"></a>00042 <span class="comment">// This exmaple demonstrates bitvector serialization/deserialization.</span>
70
 
<a name="l00043"></a>00043 
 
68
<a name="l00041"></a>00041 <span class="keyword">using namespace </span>std;
 
69
<a name="l00042"></a>00042 
 
70
<a name="l00043"></a><a class="code" href="a00109.html#a8652d848be89c1f9b0a77327ee32fc0f">00043</a> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <a class="code" href="a00109.html#a8652d848be89c1f9b0a77327ee32fc0f">MAX_VALUE</a> = 1000000;
71
71
<a name="l00044"></a>00044 
72
 
<a name="l00045"></a>00045 
73
 
<a name="l00046"></a><a class="code" href="a00109.html#a8652d848be89c1f9b0a77327ee32fc0f">00046</a> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <a class="code" href="a00108.html#a8652d848be89c1f9b0a77327ee32fc0f">MAX_VALUE</a> = 1000000;
74
 
<a name="l00047"></a>00047 
75
 
<a name="l00048"></a>00048 <span class="comment">// This procedure creates very dense bitvector.</span>
76
 
<a name="l00049"></a>00049 <span class="comment">// The resulting set will consists mostly from ON (1) bits</span>
77
 
<a name="l00050"></a>00050 <span class="comment">// interrupted with small gaps of 0 bits.</span>
78
 
<a name="l00051"></a>00051 
79
 
<a name="l00052"></a><a class="code" href="a00109.html#a663e1bc930c9ade56c0bc436b8860a1e">00052</a> <span class="keywordtype">void</span> <a class="code" href="a00108.html#a6c4e3c21afef90ce9111f8f5e60d4c13">fill_bvector</a>(<a class="code" href="a00044.html" title="bitvector with runtime compression of bits.">bm::bvector&lt;&gt;</a>* bv)
80
 
<a name="l00053"></a>00053 {
81
 
<a name="l00054"></a>00054     <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)
82
 
<a name="l00055"></a>00055     {
83
 
<a name="l00056"></a>00056         <span class="keywordflow">if</span> (rand() % 2500)
84
 
<a name="l00057"></a>00057         {
85
 
<a name="l00058"></a>00058             bv-&gt;<a class="code" href="a00044.html#a1769d9ed3a4ee41b03fc3ca4a0e5a58e" title="Sets bit n.">set_bit</a>(i);
86
 
<a name="l00059"></a>00059         }
87
 
<a name="l00060"></a>00060     }
88
 
<a name="l00061"></a>00061 }
89
 
<a name="l00062"></a>00062 
90
 
<a name="l00063"></a>00063 
91
 
<a name="l00064"></a><a class="code" href="a00109.html#aeb4ca6f0a986ad6ae67d1f7124fdc400">00064</a> <span class="keywordtype">void</span> <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)
92
 
<a name="l00065"></a>00065 {
93
 
<a name="l00066"></a>00066     <a class="code" href="a00085.html" title="Statistical information about bitset&amp;#39;s memory allocation details.">bm::bvector&lt;&gt;::statistics</a> st;
94
 
<a name="l00067"></a>00067     bv.<a class="code" href="a00044.html#a1eaaac76a97b9eb1d3c11f21cf9385ac" title="Calculates bitvector statistics.">calc_stat</a>(&amp;st);
95
 
<a name="l00068"></a>00068 
96
 
<a name="l00069"></a>00069     cout &lt;&lt; <span class="stringliteral">&quot;Bits count:&quot;</span> &lt;&lt; bv.<a class="code" href="a00044.html#a71077c1315555301532e24d4d2b95ea2" title="Returns count of bits which are 1.">count</a>() &lt;&lt; endl;
97
 
<a name="l00070"></a>00070     cout &lt;&lt; <span class="stringliteral">&quot;Bit blocks:&quot;</span> &lt;&lt; st.<a class="code" href="a00043.html#a4ec8ba190b4ba31c431c008402881c62" title="Number of bit blocks.">bit_blocks</a> &lt;&lt; endl;
98
 
<a name="l00071"></a>00071     cout &lt;&lt; <span class="stringliteral">&quot;GAP blocks:&quot;</span> &lt;&lt; st.<a class="code" href="a00043.html#a4dcfd64e9ab0be5472e3c2b04e551f81" title="Number of GAP blocks.">gap_blocks</a> &lt;&lt; endl;
99
 
<a name="l00072"></a>00072     cout &lt;&lt; <span class="stringliteral">&quot;Memory used:&quot;</span>&lt;&lt; st.<a class="code" href="a00043.html#ad3b2190eb4afe24ecd56323cbc0a7666" title="Memory used by bitvector including temp and service blocks.">memory_used</a> &lt;&lt; endl;
100
 
<a name="l00073"></a>00073     cout &lt;&lt; <span class="stringliteral">&quot;Max.serialize mem.:&quot;</span> &lt;&lt; st.<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;;
101
 
<a name="l00074"></a>00074 }
102
 
<a name="l00075"></a>00075 
103
 
<a name="l00076"></a>00076 
104
 
<a name="l00077"></a><a class="code" href="a00109.html#a2ba5ce11270f84d292466449521b695f">00077</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* <a class="code" href="a00109.html#a2ba5ce11270f84d292466449521b695f">serialize_bvector</a>(<a class="code" href="a00083.html" title="Bit-vector serialization class.">bm::serializer</a>&lt;<a class="code" href="a00044.html" title="bitvector with runtime compression of bits.">bm::bvector&lt;&gt;</a> &gt;&amp; bvs, 
105
 
<a name="l00078"></a>00078                                  <a class="code" href="a00044.html" title="bitvector with runtime compression of bits.">bm::bvector&lt;&gt;</a>&amp; bv)
106
 
<a name="l00079"></a>00079 {
107
 
<a name="l00080"></a>00080     <span class="comment">// It is reccomended to optimize vector before serialization.</span>
108
 
<a name="l00081"></a>00081     bv.<a class="code" href="a00044.html#abd522c13e26c2b8f84636fe8b6648dcb" title="Optimize memory bitvector&amp;#39;s memory allocation.">optimize</a>();  
109
 
<a name="l00082"></a>00082 
110
 
<a name="l00083"></a>00083     <a class="code" href="a00085.html" title="Statistical information about bitset&amp;#39;s memory allocation details.">bm::bvector&lt;&gt;::statistics</a> st;
111
 
<a name="l00084"></a>00084     bv.<a class="code" href="a00044.html#a1eaaac76a97b9eb1d3c11f21cf9385ac" title="Calculates bitvector statistics.">calc_stat</a>(&amp;st);
112
 
<a name="l00085"></a>00085 
113
 
<a name="l00086"></a>00086     cout &lt;&lt; <span class="stringliteral">&quot;Bits count:&quot;</span> &lt;&lt; bv.<a class="code" href="a00044.html#a71077c1315555301532e24d4d2b95ea2" title="Returns count of bits which are 1.">count</a>() &lt;&lt; endl;
114
 
<a name="l00087"></a>00087     cout &lt;&lt; <span class="stringliteral">&quot;Bit blocks:&quot;</span> &lt;&lt; st.<a class="code" href="a00043.html#a4ec8ba190b4ba31c431c008402881c62" title="Number of bit blocks.">bit_blocks</a> &lt;&lt; endl;
115
 
<a name="l00088"></a>00088     cout &lt;&lt; <span class="stringliteral">&quot;GAP blocks:&quot;</span> &lt;&lt; st.<a class="code" href="a00043.html#a4dcfd64e9ab0be5472e3c2b04e551f81" title="Number of GAP blocks.">gap_blocks</a> &lt;&lt; endl;
116
 
<a name="l00089"></a>00089     cout &lt;&lt; <span class="stringliteral">&quot;Memory used:&quot;</span>&lt;&lt; st.<a class="code" href="a00043.html#ad3b2190eb4afe24ecd56323cbc0a7666" title="Memory used by bitvector including temp and service blocks.">memory_used</a> &lt;&lt; endl;
117
 
<a name="l00090"></a>00090     cout &lt;&lt; <span class="stringliteral">&quot;Max.serialize mem.:&quot;</span> &lt;&lt; st.<a class="code" href="a00043.html#a92f800e8649a1455c17019c8ec882b4b" title="Estimated maximum of memory required for serialization.">max_serialize_mem</a> &lt;&lt; endl;
 
72
<a name="l00045"></a>00045 <span class="comment">// This procedure creates very dense bitvectors.</span>
 
73
<a name="l00046"></a>00046 <span class="comment">// The resulting set will consists mostly from ON (1) bits</span>
 
74
<a name="l00047"></a>00047 <span class="comment">// interrupted with small gaps of 0 bits.</span>
 
75
<a name="l00048"></a>00048 
 
76
<a name="l00049"></a><a class="code" href="a00109.html#a6c4e3c21afef90ce9111f8f5e60d4c13">00049</a> <span class="keywordtype">void</span> <a class="code" href="a00109.html#a6c4e3c21afef90ce9111f8f5e60d4c13">fill_bvector</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)
 
77
<a name="l00050"></a>00050 {
 
78
<a name="l00051"></a>00051     <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0; i &lt; <a class="code" href="a00109.html#a8652d848be89c1f9b0a77327ee32fc0f">MAX_VALUE</a>; ++i)
 
79
<a name="l00052"></a>00052     {
 
80
<a name="l00053"></a>00053         <span class="keywordflow">if</span> (rand() % 2500)
 
81
<a name="l00054"></a>00054         {
 
82
<a name="l00055"></a>00055             bv1-&gt;<a class="code" href="a00044.html#a1769d9ed3a4ee41b03fc3ca4a0e5a58e" title="Sets bit n.">set_bit</a>(i);
 
83
<a name="l00056"></a>00056             bv2-&gt;<a class="code" href="a00044.html#a1769d9ed3a4ee41b03fc3ca4a0e5a58e" title="Sets bit n.">set_bit</a>(i);
 
84
<a name="l00057"></a>00057         }
 
85
<a name="l00058"></a>00058     }
 
86
<a name="l00059"></a>00059 }
 
87
<a name="l00060"></a>00060 
 
88
<a name="l00061"></a>00061 
 
89
<a name="l00062"></a><a class="code" href="a00109.html#aeb4ca6f0a986ad6ae67d1f7124fdc400">00062</a> <span class="keywordtype">void</span> <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&lt;&gt;</a>&amp; bv)
 
90
<a name="l00063"></a>00063 {
 
91
<a name="l00064"></a>00064     <a class="code" href="a00086.html" title="Statistical information about bitset&amp;#39;s memory allocation details.">bm::bvector&lt;&gt;::statistics</a> st;
 
92
<a name="l00065"></a>00065     bv.<a class="code" href="a00044.html#a1eaaac76a97b9eb1d3c11f21cf9385ac" title="Calculates bitvector statistics.">calc_stat</a>(&amp;st);
 
93
<a name="l00066"></a>00066 
 
94
<a name="l00067"></a>00067     cout &lt;&lt; <span class="stringliteral">&quot;Bits count:&quot;</span> &lt;&lt; bv.<a class="code" href="a00044.html#a71077c1315555301532e24d4d2b95ea2" title="Returns count of bits which are 1.">count</a>() &lt;&lt; endl;
 
95
<a name="l00068"></a>00068     cout &lt;&lt; <span class="stringliteral">&quot;Bit blocks:&quot;</span> &lt;&lt; st.<a class="code" href="a00043.html#a4ec8ba190b4ba31c431c008402881c62" title="Number of bit blocks.">bit_blocks</a> &lt;&lt; endl;
 
96
<a name="l00069"></a>00069     cout &lt;&lt; <span class="stringliteral">&quot;GAP blocks:&quot;</span> &lt;&lt; st.<a class="code" href="a00043.html#a4dcfd64e9ab0be5472e3c2b04e551f81" title="Number of GAP blocks.">gap_blocks</a> &lt;&lt; endl;
 
97
<a name="l00070"></a>00070     cout &lt;&lt; <span class="stringliteral">&quot;Memory used:&quot;</span>&lt;&lt; st.<a class="code" href="a00043.html#ad3b2190eb4afe24ecd56323cbc0a7666" title="Memory used by bitvector including temp and service blocks.">memory_used</a> &lt;&lt; endl;
 
98
<a name="l00071"></a>00071     cout &lt;&lt; <span class="stringliteral">&quot;Max.serialize mem.:&quot;</span> &lt;&lt; st.<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;;
 
99
<a name="l00072"></a>00072 }
 
100
<a name="l00073"></a>00073 
 
101
<a name="l00074"></a>00074 
 
102
<a name="l00075"></a><a class="code" href="a00109.html#a840291bc02cba5474a4cb46a9b9566fe">00075</a> <span class="keywordtype">int</span> <a class="code" href="a00106.html#a840291bc02cba5474a4cb46a9b9566fe">main</a>(<span class="keywordtype">void</span>)
 
103
<a name="l00076"></a>00076 {
 
104
<a name="l00077"></a>00077     <a class="code" href="a00044.html" title="bitvector with runtime compression of bits.">bm::bvector&lt;&gt;</a>   bv1;    
 
105
<a name="l00078"></a>00078     <a class="code" href="a00044.html" title="bitvector with runtime compression of bits.">bm::bvector&lt;&gt;</a>   bv2;
 
106
<a name="l00079"></a>00079 
 
107
<a name="l00080"></a>00080     bv2.<a class="code" href="a00044.html#ab1094180d03cbc961d62f0f453097452" title="Sets new blocks allocation strategy.">set_new_blocks_strat</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 name="l00081"></a>00081 
 
109
<a name="l00082"></a>00082     <a class="code" href="a00109.html#a6c4e3c21afef90ce9111f8f5e60d4c13">fill_bvector</a>(&amp;bv1, &amp;bv2);  <span class="comment">// Fill both bvectors with the same values</span>
 
110
<a name="l00083"></a>00083 
 
111
<a name="l00084"></a>00084     <span class="comment">// For a given distrubution statistics should demonstrate</span>
 
112
<a name="l00085"></a>00085     <span class="comment">// lower memory consumption for the vector with compression</span>
 
113
<a name="l00086"></a>00086 
 
114
<a name="l00087"></a>00087     <a class="code" href="a00109.html#aeb4ca6f0a986ad6ae67d1f7124fdc400">print_statistics</a>(bv1);    
 
115
<a name="l00088"></a>00088     <a class="code" href="a00109.html#aeb4ca6f0a986ad6ae67d1f7124fdc400">print_statistics</a>(bv2);
 
116
<a name="l00089"></a>00089 
 
117
<a name="l00090"></a>00090     <span class="comment">// Now run optimization procedure for bv1 and see statistics.</span>
118
118
<a name="l00091"></a>00091 
119
 
<a name="l00092"></a>00092     <span class="comment">// Allocate serialization buffer.</span>
 
119
<a name="l00092"></a>00092     bv1.<a class="code" href="a00044.html#abd522c13e26c2b8f84636fe8b6648dcb" title="Optimize memory bitvector&amp;#39;s memory allocation.">optimize</a>();
120
120
<a name="l00093"></a>00093 
121
 
<a name="l00094"></a>00094     <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*  buf = <span class="keyword">new</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>[st.<a class="code" href="a00043.html#a92f800e8649a1455c17019c8ec882b4b" title="Estimated maximum of memory required for serialization.">max_serialize_mem</a>];
 
121
<a name="l00094"></a>00094     <a class="code" href="a00109.html#aeb4ca6f0a986ad6ae67d1f7124fdc400">print_statistics</a>(bv1);    
122
122
<a name="l00095"></a>00095 
123
 
<a name="l00096"></a>00096     <span class="comment">// Serialization to memory.</span>
124
 
<a name="l00097"></a>00097 
125
 
<a name="l00098"></a>00098     <span class="keywordtype">unsigned</span> len = bvs.serialize(bv, buf, 0);
126
 
<a name="l00099"></a>00099     <span class="comment">//unsigned len = bm::serialize(bv, buf);</span>
127
 
<a name="l00100"></a>00100 
128
 
<a name="l00101"></a>00101     cout &lt;&lt; <span class="stringliteral">&quot;Serialized size:&quot;</span> &lt;&lt; len &lt;&lt; endl &lt;&lt; endl;
129
 
<a name="l00102"></a>00102 
130
 
<a name="l00103"></a>00103     <span class="keywordflow">return</span> buf;
131
 
<a name="l00104"></a>00104 }
132
 
<a name="l00105"></a>00105 
133
 
<a name="l00106"></a>00106 
134
 
<a name="l00107"></a><a class="code" href="a00109.html#a840291bc02cba5474a4cb46a9b9566fe">00107</a> <span class="keywordtype">int</span> <a class="code" href="a00105.html#a840291bc02cba5474a4cb46a9b9566fe">main</a>(<span class="keywordtype">void</span>)
135
 
<a name="l00108"></a>00108 {
136
 
<a name="l00109"></a>00109     <a class="code" href="a00044.html" title="bitvector with runtime compression of bits.">bm::bvector&lt;&gt;</a>   bv1;    
137
 
<a name="l00110"></a>00110     <a class="code" href="a00044.html" title="bitvector with runtime compression of bits.">bm::bvector&lt;&gt;</a>   bv2;
138
 
<a name="l00111"></a>00111 
139
 
<a name="l00112"></a>00112     bv2.<a class="code" href="a00044.html#ab1094180d03cbc961d62f0f453097452" title="Sets new blocks allocation strategy.">set_new_blocks_strat</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>
140
 
<a name="l00113"></a>00113 
141
 
<a name="l00114"></a>00114     <a class="code" href="a00108.html#a6c4e3c21afef90ce9111f8f5e60d4c13">fill_bvector</a>(&amp;bv1);
142
 
<a name="l00115"></a>00115     <a class="code" href="a00108.html#a6c4e3c21afef90ce9111f8f5e60d4c13">fill_bvector</a>(&amp;bv2);
143
 
<a name="l00116"></a>00116 
144
 
<a name="l00117"></a>00117     <span class="comment">// Prepare a serializer class </span>
145
 
<a name="l00118"></a>00118     <span class="comment">//  for best performance it is best to create serilizer once and reuse it</span>
146
 
<a name="l00119"></a>00119     <span class="comment">//  (saves a lot of memory allocations)</span>
147
 
<a name="l00120"></a>00120     <span class="comment">//</span>
148
 
<a name="l00121"></a>00121     <a class="code" href="a00083.html" title="Bit-vector serialization class.">bm::serializer&lt;bm::bvector&lt;&gt;</a> &gt; bvs;
149
 
<a name="l00122"></a>00122 
150
 
<a name="l00123"></a>00123     <span class="comment">// next settings provide lowest serilized size </span>
151
 
<a name="l00124"></a>00124     bvs.<a class="code" href="a00083.html#a892b124d42bb939485e47d197b8dc1ac" title="Set byte-order serialization (for cross platform compatibility).">byte_order_serialization</a>(<span class="keyword">false</span>);
152
 
<a name="l00125"></a>00125     bvs.<a class="code" href="a00083.html#a5b19026c2e928c639f09da4a4e1235ab" title="Set GAP length serialization (serializes GAP levels of the original vector).">gap_length_serialization</a>(<span class="keyword">false</span>);
153
 
<a name="l00126"></a>00126     bvs.<a class="code" href="a00083.html#ad433d790f07103d39c5f15a6caaf2823" title="Set compression level.">set_compression_level</a>(4);
154
 
<a name="l00127"></a>00127 
155
 
<a name="l00128"></a>00128 
156
 
<a name="l00129"></a>00129     <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* buf1 = <a class="code" href="a00109.html#a2ba5ce11270f84d292466449521b695f">serialize_bvector</a>(bvs, bv1);
157
 
<a name="l00130"></a>00130     <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* buf2 = <a class="code" href="a00109.html#a2ba5ce11270f84d292466449521b695f">serialize_bvector</a>(bvs, bv2);
158
 
<a name="l00131"></a>00131 
159
 
<a name="l00132"></a>00132     <span class="comment">// Serialized bvectors (buf1 and buf2) now ready to be</span>
160
 
<a name="l00133"></a>00133     <span class="comment">// saved to a database, file or send over a network.</span>
161
 
<a name="l00134"></a>00134 
162
 
<a name="l00135"></a>00135     <span class="comment">// ...</span>
163
 
<a name="l00136"></a>00136 
164
 
<a name="l00137"></a>00137     <span class="comment">// Deserialization.</span>
165
 
<a name="l00138"></a>00138 
166
 
<a name="l00139"></a>00139     <a class="code" href="a00044.html" title="bitvector with runtime compression of bits.">bm::bvector&lt;&gt;</a>  bv3;
167
 
<a name="l00140"></a>00140 
168
 
<a name="l00141"></a>00141     <span class="comment">// As a result of desrialization bv3 will contain all bits from</span>
169
 
<a name="l00142"></a>00142     <span class="comment">// bv1 and bv3:</span>
170
 
<a name="l00143"></a>00143     <span class="comment">//   bv3 = bv1 OR bv2</span>
171
 
<a name="l00144"></a>00144 
172
 
<a name="l00145"></a>00145     <a class="code" href="a00126.html#gafbe633db8da3d867f098468269fd8d3d" title="Bitvector deserialization from memory.">bm::deserialize</a>(bv3, buf1);
173
 
<a name="l00146"></a>00146     <a class="code" href="a00126.html#gafbe633db8da3d867f098468269fd8d3d" title="Bitvector deserialization from memory.">bm::deserialize</a>(bv3, buf2);
174
 
<a name="l00147"></a>00147 
175
 
<a name="l00148"></a>00148     <a class="code" href="a00108.html#aeb4ca6f0a986ad6ae67d1f7124fdc400">print_statistics</a>(bv3);
176
 
<a name="l00149"></a>00149 
177
 
<a name="l00150"></a>00150     <span class="comment">// After a complex operation we can try to optimize bv3.</span>
178
 
<a name="l00151"></a>00151 
179
 
<a name="l00152"></a>00152     bv3.<a class="code" href="a00044.html#abd522c13e26c2b8f84636fe8b6648dcb" title="Optimize memory bitvector&amp;#39;s memory allocation.">optimize</a>();
180
 
<a name="l00153"></a>00153 
181
 
<a name="l00154"></a>00154     <a class="code" href="a00108.html#aeb4ca6f0a986ad6ae67d1f7124fdc400">print_statistics</a>(bv3);
182
 
<a name="l00155"></a>00155 
183
 
<a name="l00156"></a>00156     <span class="keyword">delete</span> [] buf1;
184
 
<a name="l00157"></a>00157     <span class="keyword">delete</span> [] buf2;
185
 
<a name="l00158"></a>00158 
186
 
<a name="l00159"></a>00159     <span class="keywordflow">return</span> 0;
187
 
<a name="l00160"></a>00160 }
188
 
<a name="l00161"></a>00161 
 
123
<a name="l00096"></a>00096     <span class="keywordflow">return</span> 0;
 
124
<a name="l00097"></a>00097 }
 
125
<a name="l00098"></a>00098 
189
126
</pre></div></div>
190
 
<hr size="1"/><address style="text-align: right;"><small>Generated on Fri Jan 8 20:09:19 2010 for BitMagic by&nbsp;
 
127
<hr size="1"/><address style="text-align: right;"><small>Generated on Tue Mar 23 20:47:55 2010 for BitMagic by&nbsp;
191
128
<a href="http://www.doxygen.org/index.html">
192
129
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
193
130
</body>