~ubuntu-branches/ubuntu/vivid/bmagic/vivid

« back to all changes in this revision

Viewing changes to html/a00153.html

  • Committer: Bazaar Package Importer
  • Author(s): Andres Salomon
  • Date: 2008-01-05 23:58:56 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080105235856-2kmxhxkz14qjy9ia
Tags: 3.5.0-1
* New upstream release.
* Add tcpp.dpatch.  This stops tests/stress/t.cpp from including
  ncbi_pch.hpp.  As far as I can tell, NCBI is not used at all, I have
  no idea where that came from..
* Silence some lintian warnings; binary-arch-rules-but-pkg-is-arch-indep
  and ancient-standards-version.

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: sample8.cpp Source File</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
<div class="nav">
 
9
<a class="el" href="dir_000001.html">samples</a>&nbsp;/&nbsp;<a class="el" href="dir_000009.html">sample8</a></div>
 
10
<h1>sample8.cpp</h1><a href="a00127.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 sample8.cpp</span>
 
34
00025 <span class="comment"></span>
 
35
00026 <span class="comment">    Example demonstrates some STL compatability set operations using</span>
 
36
00027 <span class="comment">    set iterators.</span>
 
37
00028 <span class="comment"> </span>
 
38
00029 <span class="comment">  \sa bm::bvector&lt;&gt;::enumerator </span>
 
39
00030 <span class="comment">  \sa bm::bvector&lt;&gt;::insert_iterator</span>
 
40
00031 <span class="comment"></span>
 
41
00032 <span class="comment">   For more information please visit:  http://bmagic.sourceforge.net</span>
 
42
00033 <span class="comment"></span>
 
43
00034 <span class="comment">*/</span>
 
44
00035 
 
45
00036 <span class="preprocessor">#include &lt;iostream&gt;</span>
 
46
00037 <span class="preprocessor">#include &lt;algorithm&gt;</span>
 
47
00038 <span class="preprocessor">#include &lt;vector&gt;</span>
 
48
00039 <span class="preprocessor">#include &lt;list&gt;</span>
 
49
00040 
 
50
00041 <span class="keyword">using</span> std::vector;
 
51
00042 <span class="keyword">using</span> std::list;
 
52
00043 
 
53
00044 <span class="comment">// This example requires STL compatibility</span>
 
54
00045 <span class="preprocessor">#ifdef BM_NO_STL</span>
 
55
00046 <span class="preprocessor"></span><span class="preprocessor"># undef BM_NO_STL</span>
 
56
00047 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
 
57
00048 <span class="preprocessor"></span>
 
58
00049 <span class="preprocessor">#include "<a class="code" href="a00111.html">bm.h</a>"</span>
 
59
00050 
 
60
00051 <span class="keyword">using</span> <span class="keyword">namespace </span>std;
 
61
00052 
 
62
<a name="l00053"></a><a class="code" href="a00127.html#a0">00053</a> <span class="keywordtype">void</span> <a class="code" href="a00124.html#a0">Print</a>(<span class="keywordtype">unsigned</span> n)
 
63
00054 {
 
64
00055     cout &lt;&lt; n &lt;&lt; endl;;
 
65
00056 }
 
66
00057 
 
67
00058 <span class="comment">// Utility template function used to print container</span>
 
68
<a name="l00059"></a><a class="code" href="a00127.html#a1">00059</a> <span class="keyword">template</span>&lt;<span class="keyword">class</span> T&gt; <span class="keywordtype">void</span> <a class="code" href="a00127.html#a1">PrintContainer</a>(T first, T last)
 
69
00060 {
 
70
00061     <span class="keywordflow">if</span> (first == last)
 
71
00062         cout &lt;&lt; <span class="stringliteral">"&lt;EMPTY SET&gt;"</span>;
 
72
00063     <span class="keywordflow">else</span>
 
73
00064         <span class="keywordflow">for</span>(;first != last; ++first)
 
74
00065             cout &lt;&lt; *first &lt;&lt; <span class="stringliteral">";"</span>;
 
75
00066     cout &lt;&lt; endl;
 
76
00067 }
 
77
00068 
 
78
<a name="l00069"></a><a class="code" href="a00127.html#a2">00069</a> <span class="keywordtype">int</span> <a class="code" href="a00120.html#a0">main</a>(<span class="keywordtype">void</span>)
 
79
00070 {
 
80
00071     <a class="code" href="a00084.html">bm::bvector&lt;&gt;</a>   bv;    
 
81
00072 
 
82
00073     bv[10] = <span class="keyword">true</span>;
 
83
00074     bv[100] = <span class="keyword">true</span>;
 
84
00075     bv[10000] = <span class="keyword">true</span>;
 
85
00076     
 
86
00077     cout &lt;&lt; <span class="stringliteral">"Source set:"</span>;
 
87
00078     <a class="code" href="a00127.html#a1">PrintContainer</a>(bv.<a class="code" href="a00084.html#a61">first</a>(), bv.<a class="code" href="a00084.html#a62">end</a>());
 
88
00079     
 
89
00080     <span class="comment">// copy all bitset information into STL vector using copy algorithm</span>
 
90
00081     {
 
91
00082         vector&lt;unsigned&gt; vect;
 
92
00083         vect.<a class="code" href="a00084.html#a31">resize</a>(bv.<a class="code" href="a00084.html#a28">count</a>());
 
93
00084         std::copy(bv.<a class="code" href="a00084.html#a61">first</a>(), bv.<a class="code" href="a00084.html#a62">end</a>(), vect.begin());
 
94
00085         cout &lt;&lt; <span class="stringliteral">"Vector:"</span>;
 
95
00086         <a class="code" href="a00127.html#a1">PrintContainer</a>(vect.begin(), vect.end());
 
96
00087     }
 
97
00088 
 
98
00089     <span class="comment">// doing the same with the help of back_inserter</span>
 
99
00090 
 
100
00091     {
 
101
00092         list&lt;unsigned&gt; lst;
 
102
00093         std::copy(bv.<a class="code" href="a00084.html#a61">first</a>(), bv.<a class="code" href="a00084.html#a62">end</a>(), std::back_inserter(lst));
 
103
00094         cout &lt;&lt; <span class="stringliteral">"List:"</span>;
 
104
00095         <a class="code" href="a00127.html#a1">PrintContainer</a>(lst.begin(), lst.end());
 
105
00096     }
 
106
00097 
 
107
00098     {
 
108
00099         vector&lt;unsigned&gt;   vect;
 
109
00100         vector&lt;unsigned&gt;   res1, res2, res3;
 
110
00101         
 
111
00102         vect.push_back(100);
 
112
00103         vect.push_back(15);
 
113
00104         vect.push_back(150);
 
114
00105         
 
115
00106         cout &lt;&lt; <span class="stringliteral">"Argument vector for set operations:"</span>;
 
116
00107         <a class="code" href="a00127.html#a1">PrintContainer</a>(vect.begin(), vect.end());
 
117
00108         
 
118
00109         <span class="comment">// set should be ordered by &lt; to make set algorithms possible</span>
 
119
00110         std::sort(vect.begin(), vect.end());
 
120
00111         cout &lt;&lt; endl;
 
121
00112         
 
122
00113         std::set_union(bv.<a class="code" href="a00084.html#a61">first</a>(), bv.<a class="code" href="a00084.html#a62">end</a>(),
 
123
00114                        vect.begin(), vect.<a class="code" href="a00084.html#a62">end</a>(),
 
124
00115                        std::back_inserter(res1)); <span class="comment">//10;15;100;150;10000</span>
 
125
00116         cout &lt;&lt; <span class="stringliteral">"Set union:"</span> &lt;&lt; endl;
 
126
00117         <a class="code" href="a00127.html#a1">PrintContainer</a>(res1.begin(), res1.end());
 
127
00118         
 
128
00119         std::set_intersection(bv.<a class="code" href="a00084.html#a61">first</a>(), bv.<a class="code" href="a00084.html#a62">end</a>(),
 
129
00120                               vect.begin(), vect.<a class="code" href="a00084.html#a62">end</a>(),
 
130
00121                               std::back_inserter(res2));  <span class="comment">// 100</span>
 
131
00122         cout &lt;&lt; <span class="stringliteral">"Set intersection:"</span> &lt;&lt; endl;
 
132
00123         <a class="code" href="a00127.html#a1">PrintContainer</a>(res2.begin(), res2.end());
 
133
00124 
 
134
00125         vector&lt;unsigned&gt;::const_iterator it1 = vect.begin();
 
135
00126         vector&lt;unsigned&gt;::const_iterator it2 = vect.<a class="code" href="a00084.html#a62">end</a>();
 
136
00127         <a class="code" href="a00084.html">bm::bvector&lt;&gt;</a>::enumerator en = bv.<a class="code" href="a00084.html#a61">first</a>();
 
137
00128         <a class="code" href="a00084.html">bm::bvector&lt;&gt;</a>::enumerator en2= bv.<a class="code" href="a00084.html#a62">end</a>();
 
138
00129         
 
139
00130         std::set_difference(en, en2,
 
140
00131                             it1, it2,
 
141
00132                             std::back_inserter(res3));  <span class="comment">// 10;10000</span>
 
142
00133 
 
143
00134         cout &lt;&lt; <span class="stringliteral">"Set diff:"</span> &lt;&lt; endl;
 
144
00135         <a class="code" href="a00127.html#a1">PrintContainer</a>(res3.begin(), res3.end());
 
145
00136         
 
146
00137     }
 
147
00138 
 
148
00139     <span class="comment">// Using bvector&lt;&gt;::insert_iterator to set bits</span>
 
149
00140     {
 
150
00141         <a class="code" href="a00084.html">bm::bvector&lt;&gt;</a> bv1;
 
151
00142         std::vector&lt;unsigned&gt; vect;
 
152
00143         
 
153
00144         vect.push_back(300);
 
154
00145         vect.push_back(200);
 
155
00146         vect.push_back(275);
 
156
00147         vect.push_back(200);
 
157
00148         
 
158
00149         cout &lt;&lt; endl &lt;&lt; <span class="stringliteral">"Source vector:"</span>;
 
159
00150         <a class="code" href="a00127.html#a1">PrintContainer</a>(vect.begin(), vect.end()); <span class="comment">// 300;200;275;200;</span>
 
160
00151         
 
161
00152         <span class="comment">// The "side effect" of this operation is that we sorted</span>
 
162
00153         <span class="comment">// the input sequence and eliminated duplicates</span>
 
163
00154         
 
164
00155         std::copy(vect.begin(), vect.end(), bv1.<a class="code" href="a00084.html#a24">inserter</a>());
 
165
00156         cout &lt;&lt; <span class="stringliteral">"Bitset:"</span>;
 
166
00157         
 
167
00158         <a class="code" href="a00127.html#a1">PrintContainer</a>(bv1.<a class="code" href="a00084.html#a61">first</a>(), bv1.<a class="code" href="a00084.html#a62">end</a>());  <span class="comment">// 200;275;300</span>
 
168
00159     }
 
169
00160     
 
170
00161     
 
171
00162     <span class="keywordflow">return</span> 0;
 
172
00163 }
 
173
00164 
 
174
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Aug 5 14:12:26 2007 for BitMagic by&nbsp;
 
175
<a href="http://www.doxygen.org/index.html">
 
176
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.1 </small></address>
 
177
</body>
 
178
</html>