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: sample2.cpp</title>
4
<link href="doxygen.css" rel="stylesheet" type="text/css">
6
<!-- Generated by Doxygen 1.4.1 -->
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>
8
<h1>sample2.cpp</h1>Example demonstrates using set operations AND, OR, XOR, etc. For more information please visit: <a href="http://bmagic.sourceforge.net">http://bmagic.sourceforge.net</a><p>
9
<div class="fragment"><pre class="fragment"><span class="comment">/*</span>
10
<span class="comment">Copyright(c) 2002-2005 Anatoliy Kuznetsov(anatoliy_kuznetsov at yahoo.com)</span>
11
<span class="comment"></span>
12
<span class="comment">Permission is hereby granted, free of charge, to any person </span>
13
<span class="comment">obtaining a copy of this software and associated documentation </span>
14
<span class="comment">files (the "Software"), to deal in the Software without restriction, </span>
15
<span class="comment">including without limitation the rights to use, copy, modify, merge, </span>
16
<span class="comment">publish, distribute, sublicense, and/or sell copies of the Software, </span>
17
<span class="comment">and to permit persons to whom the Software is furnished to do so, </span>
18
<span class="comment">subject to the following conditions:</span>
19
<span class="comment"></span>
20
<span class="comment">The above copyright notice and this permission notice shall be included </span>
21
<span class="comment">in all copies or substantial portions of the Software.</span>
22
<span class="comment"></span>
23
<span class="comment">THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, </span>
24
<span class="comment">EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES </span>
25
<span class="comment">OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. </span>
26
<span class="comment">IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, </span>
27
<span class="comment">DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, </span>
28
<span class="comment">ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR </span>
29
<span class="comment">OTHER DEALINGS IN THE SOFTWARE.</span>
30
<span class="comment">*/</span>
31
<span class="comment"></span>
32
<span class="comment">/** \example sample2.cpp</span>
33
<span class="comment"> Example demonstrates using set operations AND, OR, XOR, etc.</span>
34
<span class="comment"> For more information please visit: http://bmagic.sourceforge.net</span>
35
<span class="comment"> </span>
36
<span class="comment">*/</span>
39
<span class="preprocessor">#include <iostream></span>
40
<span class="preprocessor">#include "<a class="code" href="a00111.html">bm.h</a>"</span>
42
<span class="keyword">using</span> <span class="keyword">namespace </span>std;
44
<span class="keywordtype">void</span> <a name="a7"></a><a class="code" href="a00121.html#a0">print_bvector</a>(<span class="keyword">const</span> <a name="_a8"></a><a class="code" href="a00084.html">bm::bvector<></a>& bv)
46
<span class="keywordtype">unsigned</span> value = bv.get_first();
47
<span class="keywordflow">do</span>
50
value = bv.get_next(value);
51
<span class="keywordflow">if</span> (value)
53
cout << <span class="stringliteral">","</span>;
55
<span class="keywordflow">else</span>
57
<span class="keywordflow">break</span>;
59
} <span class="keywordflow">while</span>(1);
63
<span class="keywordtype">int</span> <a name="a9"></a><a class="code" href="a00120.html#a0">main</a>(<span class="keywordtype">void</span>)
65
<a class="code" href="a00084.html">bm::bvector<></a> bv1;
66
<a class="code" href="a00084.html">bm::bvector<></a> bv2;
67
<a class="code" href="a00084.html">bm::bvector<></a> bv3;
69
bv1.<a name="a10"></a><a class="code" href="a00084.html#a21">set</a>(10);
70
bv1.<a class="code" href="a00084.html#a21">set</a>(100);
71
bv1.<a class="code" href="a00084.html#a21">set</a>(1000000);
74
bv2.<a class="code" href="a00084.html#a21">set</a>(10);
75
bv2.<a class="code" href="a00084.html#a21">set</a>(100);
77
<span class="comment">// Logical AND operation on bv2 (bv1 is the argument)</span>
78
<span class="comment">// bv2 = bv2 AND bv1</span>
81
<a class="code" href="a00121.html#a0">print_bvector</a>(bv3);
83
bv2 &= bv1; <span class="comment">// You also can use: bv2.bit_and(bv1);</span>
84
<a class="code" href="a00121.html#a0">print_bvector</a>(bv2);
86
<span class="comment">// bv2 = bv2 OR bv1</span>
89
<a class="code" href="a00121.html#a0">print_bvector</a>(bv3);
91
bv2 |= bv1; <span class="comment">// You can also use: bv2.bit_or(bv1);</span>
92
<a class="code" href="a00121.html#a0">print_bvector</a>(bv2);
95
bv1.<a class="code" href="a00084.html#a21">set</a>(1000000, <span class="keyword">false</span>);
97
<span class="comment">// bv2 = bv2 SUB bv1</span>
100
<a class="code" href="a00121.html#a0">print_bvector</a>(bv3);
102
bv2 -= bv1; <span class="comment">// You can also use: bv2.bit_sub(bv1);</span>
103
<a class="code" href="a00121.html#a0">print_bvector</a>(bv2);
105
<span class="comment">// bv2 XOR bv1</span>
108
<a class="code" href="a00121.html#a0">print_bvector</a>(bv3);
110
bv2 ^= bv1; <span class="comment">// You can also use: bv2.bit_xor(bv1);</span>
111
<a class="code" href="a00121.html#a0">print_bvector</a>(bv2);
113
<span class="comment">// For lexicographical comparison there is set of overloaded</span>
114
<span class="comment">// operators and function compare.</span>
116
<span class="keywordflow">if</span> (bv2 == bv3)
118
cerr << <span class="stringliteral">"Equivalent. Comparison result = "</span>
119
<< bv2.<a name="a11"></a><a class="code" href="a00084.html#a58">compare</a>(bv3) << endl;
121
<span class="keywordflow">else</span>
123
cout << <span class="stringliteral">"Error."</span> << endl;
124
<span class="keywordflow">return</span> 1;
128
<span class="keywordflow">return</span> 0;
130
</pre></div> <hr size="1"><address style="align: right;"><small>Generated on Sun Aug 5 14:12:25 2007 for BitMagic by
131
<a href="http://www.doxygen.org/index.html">
132
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.1 </small></address>