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

« back to all changes in this revision

Viewing changes to doc/html/a00001.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>sample1.cpp</h1><p>Example of how to use bvector template class to set bits and then retrieve indexes of ON bits. For more information please visit: <a href="http://bmagic.sourceforge.net">http://bmagic.sourceforge.net</a></p>
25
 
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="a00043.html#adef9c095a682a9857068c280e37c8240" title="Finds the number of the next bit ON.">bm::bvector&lt;&gt;::get_next()</a> </dd>
26
 
<dd>
27
 
<a class="el" href="a00043.html#af3129b35cabf0554d85711c085a8616d" title="Gets number of first bit which is ON.">bm::bvector&lt;&gt;::get_first()</a> </dd>
28
 
<dd>
29
 
<a class="el" href="a00043.html#aa745480d136c8b0e6bc41afe951577c5" title="Sets every bit in this bitset to 1.">bm::bvector&lt;&gt;::set()</a> </dd>
30
 
<dd>
31
 
<a class="el" href="a00043.html#a71077c1315555301532e24d4d2b95ea2" title="Returns count of bits which are 1.">bm::bvector&lt;&gt;::count()</a> </dd>
32
 
<dd>
33
 
<a class="el" href="a00043.html#afe98c658c4ee54155e61f9bdfa7b9019" title="Clears every bit in the bitvector.">bm::bvector&lt;&gt;::clear()</a></dd></dl>
 
25
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="a00044.html#adef9c095a682a9857068c280e37c8240" title="Finds the number of the next bit ON.">bm::bvector&lt;&gt;::get_next()</a> </dd>
 
26
<dd>
 
27
<a class="el" href="a00044.html#af3129b35cabf0554d85711c085a8616d" title="Gets number of first bit which is ON.">bm::bvector&lt;&gt;::get_first()</a> </dd>
 
28
<dd>
 
29
<a class="el" href="a00044.html#aa745480d136c8b0e6bc41afe951577c5" title="Sets every bit in this bitset to 1.">bm::bvector&lt;&gt;::set()</a> </dd>
 
30
<dd>
 
31
<a class="el" href="a00044.html#a71077c1315555301532e24d4d2b95ea2" title="Returns count of bits which are 1.">bm::bvector&lt;&gt;::count()</a> </dd>
 
32
<dd>
 
33
<a class="el" href="a00044.html#afe98c658c4ee54155e61f9bdfa7b9019" title="Clears every bit in the bitvector.">bm::bvector&lt;&gt;::clear()</a></dd></dl>
34
34
<div class="fragment"><pre class="fragment"><span class="comment">/*</span>
35
35
<span class="comment">Copyright(c) 2002-2005 Anatoliy Kuznetsov(anatoliy_kuznetsov at yahoo.com)</span>
36
36
<span class="comment"></span>
70
70
 
71
71
 
72
72
<span class="preprocessor">#include &lt;iostream&gt;</span>
73
 
<span class="preprocessor">#include &quot;<a class="code" href="a00084.html">bm.h</a>&quot;</span>
 
73
<span class="preprocessor">#include &quot;<a class="code" href="a00087.html">bm.h</a>&quot;</span>
74
74
 
75
75
<span class="keyword">using namespace </span>std;
76
76
 
77
 
<span class="keywordtype">int</span> <a name="a0"></a><a class="code" href="a00101.html#a840291bc02cba5474a4cb46a9b9566fe">main</a>(<span class="keywordtype">void</span>)
 
77
<span class="keywordtype">int</span> <a name="a0"></a><a class="code" href="a00105.html#a840291bc02cba5474a4cb46a9b9566fe">main</a>(<span class="keywordtype">void</span>)
78
78
{
79
 
    <a name="_a1"></a><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>
 
79
    <a name="_a1"></a><a class="code" href="a00044.html" title="bitvector with runtime compression of bits.">bm::bvector&lt;&gt;</a>   bv;    <span class="comment">// Bitvector variable declaration.</span>
80
80
 
81
 
    cout &lt;&lt; bv.<a name="a2"></a><a class="code" href="a00043.html#a71077c1315555301532e24d4d2b95ea2" title="Returns count of bits which are 1.">count</a>() &lt;&lt; endl;
 
81
    cout &lt;&lt; bv.<a name="a2"></a><a class="code" href="a00044.html#a71077c1315555301532e24d4d2b95ea2" title="Returns count of bits which are 1.">count</a>() &lt;&lt; endl;
82
82
 
83
83
    <span class="comment">// Set some bits.</span>
84
84
 
85
 
    bv.<a name="a3"></a><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);
86
 
    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);
87
 
    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);
 
85
    bv.<a name="a3"></a><a class="code" href="a00044.html#abc85ec9da74de03ff7e2a6c836656dd8" title="Sets bit n if val is true, clears bit n if val is false.">set</a>(10);
 
86
    bv.<a class="code" href="a00044.html#abc85ec9da74de03ff7e2a6c836656dd8" title="Sets bit n if val is true, clears bit n if val is false.">set</a>(100);
 
87
    bv.<a class="code" href="a00044.html#abc85ec9da74de03ff7e2a6c836656dd8" title="Sets bit n if val is true, clears bit n if val is false.">set</a>(1000000);
88
88
 
89
89
    <span class="comment">// New bitvector&apos;s count.</span>
90
90
 
91
 
    cout &lt;&lt; bv.<a class="code" href="a00043.html#a71077c1315555301532e24d4d2b95ea2" title="Returns count of bits which are 1.">count</a>() &lt;&lt; endl;
 
91
    cout &lt;&lt; bv.<a class="code" href="a00044.html#a71077c1315555301532e24d4d2b95ea2" title="Returns count of bits which are 1.">count</a>() &lt;&lt; endl;
92
92
 
93
93
 
94
94
    <span class="comment">// Print the bitvector.</span>
95
95
 
96
 
    <span class="keywordtype">unsigned</span> value = bv.<a name="a4"></a><a class="code" href="a00043.html#af3129b35cabf0554d85711c085a8616d" title="Gets number of first bit which is ON.">get_first</a>();
 
96
    <span class="keywordtype">unsigned</span> value = bv.<a name="a4"></a><a class="code" href="a00044.html#af3129b35cabf0554d85711c085a8616d" title="Gets number of first bit which is ON.">get_first</a>();
97
97
    <span class="keywordflow">do</span>
98
98
    {
99
99
        cout &lt;&lt; value;
100
 
        value = bv.<a name="a5"></a><a class="code" href="a00043.html#adef9c095a682a9857068c280e37c8240" title="Finds the number of the next bit ON.">get_next</a>(value);
 
100
        value = bv.<a name="a5"></a><a class="code" href="a00044.html#adef9c095a682a9857068c280e37c8240" title="Finds the number of the next bit ON.">get_next</a>(value);
101
101
        <span class="keywordflow">if</span> (value)
102
102
        {
103
103
            cout &lt;&lt; <span class="stringliteral">&quot;,&quot;</span>;
110
110
 
111
111
    cout &lt;&lt; endl;
112
112
 
113
 
    bv.<a name="a6"></a><a class="code" href="a00043.html#afe98c658c4ee54155e61f9bdfa7b9019" title="Clears every bit in the bitvector.">clear</a>();   <span class="comment">// Clean up.</span>
 
113
    bv.<a name="a6"></a><a class="code" href="a00044.html#afe98c658c4ee54155e61f9bdfa7b9019" title="Clears every bit in the bitvector.">clear</a>();   <span class="comment">// Clean up.</span>
114
114
 
115
 
    cout &lt;&lt; bv.<a class="code" href="a00043.html#a71077c1315555301532e24d4d2b95ea2" title="Returns count of bits which are 1.">count</a>() &lt;&lt; endl;
 
115
    cout &lt;&lt; bv.<a class="code" href="a00044.html#a71077c1315555301532e24d4d2b95ea2" title="Returns count of bits which are 1.">count</a>() &lt;&lt; endl;
116
116
 
117
117
    <span class="comment">// We also can use operators to set-clear bits;</span>
118
118
 
120
120
    bv[100] = <span class="keyword">true</span>;
121
121
    bv[10000] = <span class="keyword">true</span>;
122
122
 
123
 
    cout &lt;&lt; bv.<a class="code" href="a00043.html#a71077c1315555301532e24d4d2b95ea2" title="Returns count of bits which are 1.">count</a>() &lt;&lt; endl;
 
123
    cout &lt;&lt; bv.<a class="code" href="a00044.html#a71077c1315555301532e24d4d2b95ea2" title="Returns count of bits which are 1.">count</a>() &lt;&lt; endl;
124
124
 
125
125
    <span class="keywordflow">if</span> (bv[10])
126
126
    {
127
127
        bv[10] = <span class="keyword">false</span>;
128
128
    }
129
129
 
130
 
    cout &lt;&lt; bv.<a class="code" href="a00043.html#a71077c1315555301532e24d4d2b95ea2" title="Returns count of bits which are 1.">count</a>() &lt;&lt; endl;
 
130
    cout &lt;&lt; bv.<a class="code" href="a00044.html#a71077c1315555301532e24d4d2b95ea2" title="Returns count of bits which are 1.">count</a>() &lt;&lt; endl;
131
131
 
132
132
    <span class="keywordflow">return</span> 0;
133
133
}
134
134
 
135
135
</pre></div> </div>
136
 
<hr size="1"/><address style="text-align: right;"><small>Generated on Sun Nov 22 10:49:33 2009 for BitMagic by&nbsp;
 
136
<hr size="1"/><address style="text-align: right;"><small>Generated on Fri Jan 8 20:09:19 2010 for BitMagic by&nbsp;
137
137
<a href="http://www.doxygen.org/index.html">
138
138
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
139
139
</body>