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

« back to all changes in this revision

Viewing changes to doc/html/a00101_source.html

  • Committer: Bazaar Package Importer
  • Author(s): Roberto C. Sanchez
  • Date: 2009-12-09 16:02:55 UTC
  • mfrom: (4.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20091209160255-hu2bnjrbncl92z5w
Tags: 3.6.1-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
2
<html xmlns="http://www.w3.org/1999/xhtml">
 
3
<head>
 
4
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
 
5
<title>BitMagic: sample1.cpp Source File</title>
 
6
<link href="tabs.css" rel="stylesheet" type="text/css"/>
 
7
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
 
8
</head>
 
9
<body>
 
10
<!-- Generated by Doxygen 1.6.1 -->
 
11
<div class="navigation" id="top">
 
12
  <div class="tabs">
 
13
    <ul>
 
14
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
 
15
      <li><a href="modules.html"><span>Modules</span></a></li>
 
16
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
 
17
      <li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
 
18
      <li class="current"><a href="files.html"><span>Files</span></a></li>
 
19
      <li><a href="examples.html"><span>Examples</span></a></li>
 
20
    </ul>
 
21
  </div>
 
22
  <div class="tabs">
 
23
    <ul>
 
24
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
 
25
      <li><a href="globals.html"><span>Globals</span></a></li>
 
26
    </ul>
 
27
  </div>
 
28
<h1>sample1.cpp</h1><a href="a00101.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
<a name="l00003"></a>00003 <span class="comment"></span>
 
31
<a name="l00004"></a>00004 <span class="comment">Permission is hereby granted, free of charge, to any person </span>
 
32
<a name="l00005"></a>00005 <span class="comment">obtaining a copy of this software and associated documentation </span>
 
33
<a name="l00006"></a>00006 <span class="comment">files (the &quot;Software&quot;), to deal in the Software without restriction, </span>
 
34
<a name="l00007"></a>00007 <span class="comment">including without limitation the rights to use, copy, modify, merge, </span>
 
35
<a name="l00008"></a>00008 <span class="comment">publish, distribute, sublicense, and/or sell copies of the Software, </span>
 
36
<a name="l00009"></a>00009 <span class="comment">and to permit persons to whom the Software is furnished to do so, </span>
 
37
<a name="l00010"></a>00010 <span class="comment">subject to the following conditions:</span>
 
38
<a name="l00011"></a>00011 <span class="comment"></span>
 
39
<a name="l00012"></a>00012 <span class="comment">The above copyright notice and this permission notice shall be included </span>
 
40
<a name="l00013"></a>00013 <span class="comment">in all copies or substantial portions of the Software.</span>
 
41
<a name="l00014"></a>00014 <span class="comment"></span>
 
42
<a name="l00015"></a>00015 <span class="comment">THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, </span>
 
43
<a name="l00016"></a>00016 <span class="comment">EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES </span>
 
44
<a name="l00017"></a>00017 <span class="comment">OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. </span>
 
45
<a name="l00018"></a>00018 <span class="comment">IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, </span>
 
46
<a name="l00019"></a>00019 <span class="comment">DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, </span>
 
47
<a name="l00020"></a>00020 <span class="comment">ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR </span>
 
48
<a name="l00021"></a>00021 <span class="comment">OTHER DEALINGS IN THE SOFTWARE.</span>
 
49
<a name="l00022"></a>00022 <span class="comment">*/</span>
 
50
<a name="l00023"></a>00023 <span class="comment"></span>
 
51
<a name="l00024"></a>00024 <span class="comment">/** \example sample1.cpp</span>
 
52
<a name="l00025"></a>00025 <span class="comment">  Example of how to use bvector template class to set</span>
 
53
<a name="l00026"></a>00026 <span class="comment">  bits and then retrieve indexes of ON bits.</span>
 
54
<a name="l00027"></a>00027 <span class="comment"> </span>
 
55
<a name="l00028"></a>00028 <span class="comment">  For more information please visit:  http://bmagic.sourceforge.net</span>
 
56
<a name="l00029"></a>00029 <span class="comment"></span>
 
57
<a name="l00030"></a>00030 <span class="comment">  \sa bm::bvector&lt;&gt;::get_next() </span>
 
58
<a name="l00031"></a>00031 <span class="comment">  \sa bm::bvector&lt;&gt;::get_first() </span>
 
59
<a name="l00032"></a>00032 <span class="comment">  \sa bm::bvector&lt;&gt;::set()</span>
 
60
<a name="l00033"></a>00033 <span class="comment">  \sa bm::bvector&lt;&gt;::count() </span>
 
61
<a name="l00034"></a>00034 <span class="comment">  \sa bm::bvector&lt;&gt;::clear()</span>
 
62
<a name="l00035"></a>00035 <span class="comment">  </span>
 
63
<a name="l00036"></a>00036 <span class="comment"> */</span>
 
64
<a name="l00037"></a>00037 
 
65
<a name="l00038"></a>00038 
 
66
<a name="l00039"></a>00039 <span class="preprocessor">#include &lt;iostream&gt;</span>
 
67
<a name="l00040"></a>00040 <span class="preprocessor">#include &quot;<a class="code" href="a00084.html">bm.h</a>&quot;</span>
 
68
<a name="l00041"></a>00041 
 
69
<a name="l00042"></a>00042 <span class="keyword">using namespace </span>std;
 
70
<a name="l00043"></a>00043 
 
71
<a name="l00044"></a><a class="code" href="a00101.html#a840291bc02cba5474a4cb46a9b9566fe">00044</a> <span class="keywordtype">int</span> <a class="code" href="a00101.html#a840291bc02cba5474a4cb46a9b9566fe">main</a>(<span class="keywordtype">void</span>)
 
72
<a name="l00045"></a>00045 {
 
73
<a name="l00046"></a>00046     <a class="code" href="a00043.html" title="bitvector with runtime compression of bits.">bm::bvector&lt;&gt;</a>   bv;    <span class="comment">// Bitvector variable declaration.</span>
 
74
<a name="l00047"></a>00047 
 
75
<a name="l00048"></a>00048     cout &lt;&lt; bv.<a class="code" href="a00043.html#a71077c1315555301532e24d4d2b95ea2" title="Returns count of bits which are 1.">count</a>() &lt;&lt; endl;
 
76
<a name="l00049"></a>00049 
 
77
<a name="l00050"></a>00050     <span class="comment">// Set some bits.</span>
 
78
<a name="l00051"></a>00051 
 
79
<a name="l00052"></a>00052     bv.<a class="code" href="a00043.html#abc85ec9da74de03ff7e2a6c836656dd8" title="Sets bit n if val is true, clears bit n if val is false.">set</a>(10);
 
80
<a name="l00053"></a>00053     bv.<a class="code" href="a00043.html#abc85ec9da74de03ff7e2a6c836656dd8" title="Sets bit n if val is true, clears bit n if val is false.">set</a>(100);
 
81
<a name="l00054"></a>00054     bv.<a class="code" href="a00043.html#abc85ec9da74de03ff7e2a6c836656dd8" title="Sets bit n if val is true, clears bit n if val is false.">set</a>(1000000);
 
82
<a name="l00055"></a>00055 
 
83
<a name="l00056"></a>00056     <span class="comment">// New bitvector&apos;s count.</span>
 
84
<a name="l00057"></a>00057 
 
85
<a name="l00058"></a>00058     cout &lt;&lt; bv.<a class="code" href="a00043.html#a71077c1315555301532e24d4d2b95ea2" title="Returns count of bits which are 1.">count</a>() &lt;&lt; endl;
 
86
<a name="l00059"></a>00059 
 
87
<a name="l00060"></a>00060 
 
88
<a name="l00061"></a>00061     <span class="comment">// Print the bitvector.</span>
 
89
<a name="l00062"></a>00062 
 
90
<a name="l00063"></a>00063     <span class="keywordtype">unsigned</span> value = bv.<a class="code" href="a00043.html#af3129b35cabf0554d85711c085a8616d" title="Gets number of first bit which is ON.">get_first</a>();
 
91
<a name="l00064"></a>00064     <span class="keywordflow">do</span>
 
92
<a name="l00065"></a>00065     {
 
93
<a name="l00066"></a>00066         cout &lt;&lt; value;
 
94
<a name="l00067"></a>00067         value = bv.<a class="code" href="a00043.html#adef9c095a682a9857068c280e37c8240" title="Finds the number of the next bit ON.">get_next</a>(value);
 
95
<a name="l00068"></a>00068         <span class="keywordflow">if</span> (value)
 
96
<a name="l00069"></a>00069         {
 
97
<a name="l00070"></a>00070             cout &lt;&lt; <span class="stringliteral">&quot;,&quot;</span>;
 
98
<a name="l00071"></a>00071         }
 
99
<a name="l00072"></a>00072         <span class="keywordflow">else</span>
 
100
<a name="l00073"></a>00073         {
 
101
<a name="l00074"></a>00074             <span class="keywordflow">break</span>;
 
102
<a name="l00075"></a>00075         }
 
103
<a name="l00076"></a>00076     } <span class="keywordflow">while</span>(1);
 
104
<a name="l00077"></a>00077 
 
105
<a name="l00078"></a>00078     cout &lt;&lt; endl;
 
106
<a name="l00079"></a>00079 
 
107
<a name="l00080"></a>00080     bv.<a class="code" href="a00043.html#afe98c658c4ee54155e61f9bdfa7b9019" title="Clears every bit in the bitvector.">clear</a>();   <span class="comment">// Clean up.</span>
 
108
<a name="l00081"></a>00081 
 
109
<a name="l00082"></a>00082     cout &lt;&lt; bv.<a class="code" href="a00043.html#a71077c1315555301532e24d4d2b95ea2" title="Returns count of bits which are 1.">count</a>() &lt;&lt; endl;
 
110
<a name="l00083"></a>00083 
 
111
<a name="l00084"></a>00084     <span class="comment">// We also can use operators to set-clear bits;</span>
 
112
<a name="l00085"></a>00085 
 
113
<a name="l00086"></a>00086     bv[10] = <span class="keyword">true</span>;
 
114
<a name="l00087"></a>00087     bv[100] = <span class="keyword">true</span>;
 
115
<a name="l00088"></a>00088     bv[10000] = <span class="keyword">true</span>;
 
116
<a name="l00089"></a>00089 
 
117
<a name="l00090"></a>00090     cout &lt;&lt; bv.<a class="code" href="a00043.html#a71077c1315555301532e24d4d2b95ea2" title="Returns count of bits which are 1.">count</a>() &lt;&lt; endl;
 
118
<a name="l00091"></a>00091 
 
119
<a name="l00092"></a>00092     <span class="keywordflow">if</span> (bv[10])
 
120
<a name="l00093"></a>00093     {
 
121
<a name="l00094"></a>00094         bv[10] = <span class="keyword">false</span>;
 
122
<a name="l00095"></a>00095     }
 
123
<a name="l00096"></a>00096 
 
124
<a name="l00097"></a>00097     cout &lt;&lt; bv.<a class="code" href="a00043.html#a71077c1315555301532e24d4d2b95ea2" title="Returns count of bits which are 1.">count</a>() &lt;&lt; endl;
 
125
<a name="l00098"></a>00098 
 
126
<a name="l00099"></a>00099     <span class="keywordflow">return</span> 0;
 
127
<a name="l00100"></a>00100 }
 
128
<a name="l00101"></a>00101 
 
129
</pre></div></div>
 
130
<hr size="1"/><address style="text-align: right;"><small>Generated on Sun Nov 22 10:49:36 2009 for BitMagic by&nbsp;
 
131
<a href="http://www.doxygen.org/index.html">
 
132
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
 
133
</body>
 
134
</html>