File: a00115.html

package info (click to toggle)
bmagic 3.4.0-4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,208 kB
  • ctags: 2,500
  • sloc: cpp: 9,399; ansic: 3,142; sh: 2,430; makefile: 340
file content (87 lines) | stat: -rw-r--r-- 6,377 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>BitMagic: sample5.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.1 -->
<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>
<div class="nav">
<a class="el" href="dir_000001.html">samples</a>&nbsp;/&nbsp;<a class="el" href="dir_000006.html">sample5</a></div>
<h1>sample5.cpp</h1><a href="a00087.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*</span>
00002 <span class="comment">Copyright(c) 2002-2005 Anatoliy Kuznetsov(anatoliy_kuznetsov at yahoo.com)</span>
00003 <span class="comment"></span>
00004 <span class="comment">Permission is hereby granted, free of charge, to any person </span>
00005 <span class="comment">obtaining a copy of this software and associated documentation </span>
00006 <span class="comment">files (the "Software"), to deal in the Software without restriction, </span>
00007 <span class="comment">including without limitation the rights to use, copy, modify, merge, </span>
00008 <span class="comment">publish, distribute, sublicense, and/or sell copies of the Software, </span>
00009 <span class="comment">and to permit persons to whom the Software is furnished to do so, </span>
00010 <span class="comment">subject to the following conditions:</span>
00011 <span class="comment"></span>
00012 <span class="comment">The above copyright notice and this permission notice shall be included </span>
00013 <span class="comment">in all copies or substantial portions of the Software.</span>
00014 <span class="comment"></span>
00015 <span class="comment">THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, </span>
00016 <span class="comment">EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES </span>
00017 <span class="comment">OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. </span>
00018 <span class="comment">IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, </span>
00019 <span class="comment">DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, </span>
00020 <span class="comment">ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR </span>
00021 <span class="comment">OTHER DEALINGS IN THE SOFTWARE.</span>
00022 <span class="comment">*/</span>
00023 <span class="comment"></span>
00024 <span class="comment">/** \example sample5.cpp</span>
00025 <span class="comment"> Example demonstrates using enumerators - the fastest way to retrieve </span>
00026 <span class="comment"> indexes of 1 bits from the bitvector. This approach works faster than</span>
00027 <span class="comment"> get_first/get_next functions.</span>
00028 <span class="comment"> </span>
00029 <span class="comment">  \sa bm::bvector&lt;&gt;::enumerator </span>
00030 <span class="comment"></span>
00031 <span class="comment">For more information please visit:  http://bmagic.sourceforge.net</span>
00032 <span class="comment"></span>
00033 <span class="comment">*/</span>
00034 
00035 <span class="preprocessor">#include &lt;iostream&gt;</span>
00036 <span class="preprocessor">#include &lt;algorithm&gt;</span>
00037 <span class="preprocessor">#include "<a class="code" href="a00074.html">bm.h</a>"</span>
00038 
00039 <span class="keyword">using</span> <span class="keyword">namespace </span>std;
00040 
<a name="l00041"></a><a class="code" href="a00087.html#a0">00041</a> <span class="keywordtype">void</span> <a class="code" href="a00087.html#a0">Print</a>(<span class="keywordtype">unsigned</span> n)
00042 {
00043     cout &lt;&lt; n &lt;&lt; endl;;
00044 }
00045 
<a name="l00046"></a><a class="code" href="a00087.html#a1">00046</a> <span class="keywordtype">int</span> <a class="code" href="a00083.html#a0">main</a>(<span class="keywordtype">void</span>)
00047 {
00048     <a class="code" href="a00048.html">bm::bvector&lt;&gt;</a>   bv;    
00049 
00050     bv[10] = <span class="keyword">true</span>;
00051     bv[100] = <span class="keyword">true</span>;
00052     bv[10000] = <span class="keyword">true</span>;
00053 
00054     <a class="code" href="a00048.html">bm::bvector&lt;&gt;</a>::enumerator en = bv.<a class="code" href="a00048.html#a59">first</a>();
00055     <a class="code" href="a00048.html">bm::bvector&lt;&gt;</a>::enumerator en_end = bv.<a class="code" href="a00048.html#a60">end</a>();
00056 
00057     <span class="keywordflow">while</span> (en &lt; en_end)
00058     {
00059         cout &lt;&lt; *en &lt;&lt; endl;
00060         ++en;  <span class="comment">// Fastest way to increment enumerator</span>
00061     }
00062 
00063     en = bv.<a class="code" href="a00048.html#a59">first</a>();
00064 
00065     <span class="comment">// This is not the fastest way to do the job, because for_each </span>
00066     <span class="comment">// often will try to calculate difference between iterators,</span>
00067     <span class="comment">// which is expensive for enumerators.</span>
00068     <span class="comment">// But it can be useful for some STL loyal applications. </span>
00069 
00070     std::for_each(en, en_end, <a class="code" href="a00087.html#a0">Print</a>);
00071 
00072     <span class="keywordflow">return</span> 0;
00073 }
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Thu Apr 20 13:28:46 2006 for BitMagic by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.1 </small></address>
</body>
</html>