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

« back to all changes in this revision

Viewing changes to html/a00053.html

  • Committer: Bazaar Package Importer
  • Author(s): Roberto C. Sanchez
  • Date: 2009-10-30 18:48:35 UTC
  • mfrom: (4.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20091030184835-2tqroygiq2pevwij
Tags: 3.6.0-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
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">
5
 
</head><body>
6
 
<!-- Generated by Doxygen 1.4.1 -->
7
 
<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;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&nbsp;Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="namespacemembers.html">Namespace&nbsp;Members</a> | <a class="qindex" href="functions.html">Data&nbsp;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>
37
 
 
38
 
 
39
 
<span class="preprocessor">#include &lt;iostream&gt;</span>
40
 
<span class="preprocessor">#include "<a class="code" href="a00111.html">bm.h</a>"</span>
41
 
 
42
 
<span class="keyword">using</span> <span class="keyword">namespace </span>std;
43
 
 
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&lt;&gt;</a>&amp; bv)
45
 
{
46
 
    <span class="keywordtype">unsigned</span> value = bv.get_first();
47
 
    <span class="keywordflow">do</span>
48
 
    {
49
 
        cout &lt;&lt; value;
50
 
        value = bv.get_next(value);
51
 
        <span class="keywordflow">if</span> (value)
52
 
        {
53
 
            cout &lt;&lt; <span class="stringliteral">","</span>;
54
 
        }
55
 
        <span class="keywordflow">else</span>
56
 
        {
57
 
            <span class="keywordflow">break</span>;
58
 
        }
59
 
    } <span class="keywordflow">while</span>(1);
60
 
    cout &lt;&lt; endl;
61
 
}
62
 
 
63
 
<span class="keywordtype">int</span> <a name="a9"></a><a class="code" href="a00120.html#a0">main</a>(<span class="keywordtype">void</span>)
64
 
{
65
 
    <a class="code" href="a00084.html">bm::bvector&lt;&gt;</a>   bv1;    
66
 
    <a class="code" href="a00084.html">bm::bvector&lt;&gt;</a>   bv2;
67
 
    <a class="code" href="a00084.html">bm::bvector&lt;&gt;</a>   bv3;
68
 
 
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);
72
 
 
73
 
 
74
 
    bv2.<a class="code" href="a00084.html#a21">set</a>(10);
75
 
    bv2.<a class="code" href="a00084.html#a21">set</a>(100);
76
 
 
77
 
    <span class="comment">// Logical AND operation on bv2 (bv1 is the argument)</span>
78
 
    <span class="comment">// bv2 = bv2 AND bv1</span>
79
 
 
80
 
    bv3 = bv1 &amp; bv2;
81
 
    <a class="code" href="a00121.html#a0">print_bvector</a>(bv3);
82
 
 
83
 
    bv2 &amp;= 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);
85
 
    
86
 
    <span class="comment">// bv2 = bv2 OR bv1</span>
87
 
 
88
 
    bv3 = bv1 | bv2;
89
 
    <a class="code" href="a00121.html#a0">print_bvector</a>(bv3);
90
 
 
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);
93
 
 
94
 
    
95
 
    bv1.<a class="code" href="a00084.html#a21">set</a>(1000000, <span class="keyword">false</span>);
96
 
    
97
 
    <span class="comment">// bv2 = bv2 SUB bv1</span>
98
 
 
99
 
    bv3 = bv2 - bv1;
100
 
    <a class="code" href="a00121.html#a0">print_bvector</a>(bv3);
101
 
 
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);
104
 
 
105
 
    <span class="comment">// bv2 XOR bv1</span>
106
 
 
107
 
    bv3 = bv2 ^ bv1;
108
 
    <a class="code" href="a00121.html#a0">print_bvector</a>(bv3);
109
 
 
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);
112
 
 
113
 
    <span class="comment">// For lexicographical comparison there is set of overloaded</span>
114
 
    <span class="comment">// operators and function compare.</span>
115
 
 
116
 
    <span class="keywordflow">if</span> (bv2 == bv3)
117
 
    {
118
 
        cerr &lt;&lt; <span class="stringliteral">"Equivalent. Comparison result = "</span> 
119
 
             &lt;&lt; bv2.<a name="a11"></a><a class="code" href="a00084.html#a58">compare</a>(bv3) &lt;&lt; endl;
120
 
    }
121
 
    <span class="keywordflow">else</span>
122
 
    {
123
 
        cout &lt;&lt; <span class="stringliteral">"Error."</span> &lt;&lt; endl;
124
 
        <span class="keywordflow">return</span> 1;
125
 
    }
126
 
 
127
 
 
128
 
    <span class="keywordflow">return</span> 0;
129
 
}
130
 
</pre></div> <hr size="1"><address style="align: right;"><small>Generated on Sun Aug 5 14:12:25 2007 for BitMagic by&nbsp;
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>
133
 
</body>
134
 
</html>