1
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2
2
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
3
<title>BitMagic: sample2.cpp Source File</title>
3
<title>BitMagic: bmalgo.h File Reference</title>
4
4
<link href="doxygen.css" rel="stylesheet" type="text/css">
6
6
<!-- Generated by Doxygen 1.4.1 -->
7
7
<div class="qindex"><a class="qindex" href="index.html">Main 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 Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="namespacemembers.html">Namespace Members</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="examples.html">Examples</a></div>
9
<a class="el" href="dir_000001.html">samples</a> / <a class="el" href="dir_000003.html">sample2</a></div>
10
<h1>sample2.cpp</h1><a href="a00084.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 sample2.cpp</span>
34
00025 <span class="comment"> Example demonstrates using set operations AND, OR, XOR, etc.</span>
35
00026 <span class="comment"> For more information please visit: http://bmagic.sourceforge.net</span>
36
00027 <span class="comment"> </span>
37
00028 <span class="comment">*/</span>
40
00031 <span class="preprocessor">#include <iostream></span>
41
00032 <span class="preprocessor">#include "<a class="code" href="a00074.html">bm.h</a>"</span>
43
00034 <span class="keyword">using</span> <span class="keyword">namespace </span>std;
45
<a name="l00036"></a><a class="code" href="a00084.html#a0">00036</a> <span class="keywordtype">void</span> <a class="code" href="a00084.html#a0">print_bvector</a>(<span class="keyword">const</span> <a class="code" href="a00048.html">bm::bvector<></a>& bv)
47
00038 <span class="keywordtype">unsigned</span> value = bv.get_first();
48
00039 <span class="keywordflow">do</span>
50
00041 cout << value;
51
00042 value = bv.get_next(value);
52
00043 <span class="keywordflow">if</span> (value)
54
00045 cout << <span class="stringliteral">","</span>;
56
00047 <span class="keywordflow">else</span>
58
00049 <span class="keywordflow">break</span>;
60
00051 } <span class="keywordflow">while</span>(1);
61
00052 cout << endl;
64
<a name="l00055"></a><a class="code" href="a00084.html#a1">00055</a> <span class="keywordtype">int</span> <a class="code" href="a00083.html#a0">main</a>(<span class="keywordtype">void</span>)
66
00057 <a class="code" href="a00048.html">bm::bvector<></a> bv1;
67
00058 <a class="code" href="a00048.html">bm::bvector<></a> bv2;
68
00059 <a class="code" href="a00048.html">bm::bvector<></a> bv3;
70
00061 bv1.<a class="code" href="a00048.html#a19">set</a>(10);
71
00062 bv1.<a class="code" href="a00048.html#a19">set</a>(100);
72
00063 bv1.<a class="code" href="a00048.html#a19">set</a>(1000000);
75
00066 bv2.<a class="code" href="a00048.html#a19">set</a>(10);
76
00067 bv2.<a class="code" href="a00048.html#a19">set</a>(100);
78
00069 <span class="comment">// Logical AND operation on bv2 (bv1 is the argument)</span>
79
00070 <span class="comment">// bv2 = bv2 AND bv1</span>
81
00072 bv3 = bv1 & bv2;
82
00073 <a class="code" href="a00084.html#a0">print_bvector</a>(bv3);
84
00075 bv2 &= bv1; <span class="comment">// You also can use: bv2.bit_and(bv1);</span>
85
00076 <a class="code" href="a00084.html#a0">print_bvector</a>(bv2);
87
00078 <span class="comment">// bv2 = bv2 OR bv1</span>
89
00080 bv3 = bv1 | bv2;
90
00081 <a class="code" href="a00084.html#a0">print_bvector</a>(bv3);
92
00083 bv2 |= bv1; <span class="comment">// You can also use: bv2.bit_or(bv1);</span>
93
00084 <a class="code" href="a00084.html#a0">print_bvector</a>(bv2);
96
00087 bv1.<a class="code" href="a00048.html#a19">set</a>(1000000, <span class="keyword">false</span>);
98
00089 <span class="comment">// bv2 = bv2 SUB bv1</span>
100
00091 bv3 = bv2 - bv1;
101
00092 <a class="code" href="a00084.html#a0">print_bvector</a>(bv3);
103
00094 bv2 -= bv1; <span class="comment">// You can also use: bv2.bit_sub(bv1);</span>
104
00095 <a class="code" href="a00084.html#a0">print_bvector</a>(bv2);
106
00097 <span class="comment">// bv2 XOR bv1</span>
108
00099 bv3 = bv2 ^ bv1;
109
00100 <a class="code" href="a00084.html#a0">print_bvector</a>(bv3);
111
00102 bv2 ^= bv1; <span class="comment">// You can also use: bv2.bit_xor(bv1);</span>
112
00103 <a class="code" href="a00084.html#a0">print_bvector</a>(bv2);
114
00105 <span class="comment">// For lexicographical comparison there is set of overloaded</span>
115
00106 <span class="comment">// operators and function compare.</span>
117
00108 <span class="keywordflow">if</span> (bv2 == bv3)
119
00110 cerr << <span class="stringliteral">"Equivalent. Comparison result = "</span>
120
00111 << bv2.<a class="code" href="a00048.html#a56">compare</a>(bv3) << endl;
122
00113 <span class="keywordflow">else</span>
124
00115 cout << <span class="stringliteral">"Error."</span> << endl;
125
00116 <span class="keywordflow">return</span> 1;
129
00120 <span class="keywordflow">return</span> 0;
131
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Thu Apr 20 13:28:46 2006 for BitMagic by
9
<a class="el" href="dir_000000.html">src</a></div>
10
<h1>bmalgo.h File Reference</h1><code>#include "<a class="el" href="a00137.html">bm.h</a>"</code><br>
11
<code>#include "<a class="el" href="a00141.html">bmfunc.h</a>"</code><br>
12
<code>#include "<a class="el" href="a00140.html">bmdef.h</a>"</code><br>
13
<code>#include "bmalgo_impl.h"</code><br>
14
<code>#include "<a class="el" href="a00143.html">bmundef.h</a>"</code><br>
17
Include dependency graph for bmalgo.h:<p><center><img src="a00167.png" border="0" usemap="#bmalgo.h_map" alt=""></center>
18
<map name="bmalgo.h_map">
19
<area href="a00111.html" shape="rect" coords="157,328,197,349" alt="">
20
<area href="a00114.html" shape="rect" coords="284,5,340,27" alt="">
21
<area href="a00115.html" shape="rect" coords="280,555,344,576" alt="">
22
<area href="a00117.html" shape="rect" coords="276,600,348,621" alt="">
23
<area href="a00113.html" shape="rect" coords="277,96,347,117" alt="">
24
<area href="a00116.html" shape="rect" coords="280,192,344,213" alt="">
25
<area href="a00118.html" shape="rect" coords="279,328,345,349" alt="">
26
<area href="a00119.html" shape="rect" coords="276,237,348,259" alt="">
30
This graph shows which files directly or indirectly include this file:<p><center><img src="a00168.png" border="0" usemap="#bmalgo.hdep_map" alt=""></center>
31
<map name="bmalgo.hdep_map">
32
<area href="a00128.html" shape="rect" coords="129,5,217,26" alt="">
36
<a href="a00138.html">Go to the source code of this file.</a><table border="0" cellpadding="0" cellspacing="0">
39
<hr size="1"><address style="align: right;"><small>Generated on Sun Aug 5 14:12:28 2007 for BitMagic by
132
40
<a href="http://www.doxygen.org/index.html">
133
41
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.1 </small></address>