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

« back to all changes in this revision

Viewing changes to html/a00056.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: sample5.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>sample5.cpp</h1>Example demonstrates using enumerators - the fastest way to retrieve indexes of 1 bits from the bitvector. This approach works faster than get_first/get_next functions.<p>
9
 
<dl compact><dt><b>See also:</b></dt><dd><a class="el" href="a00084.html#n1">bm::bvector&lt;&gt;::enumerator</a></dd></dl>
10
 
For more information please visit: <a href="http://bmagic.sourceforge.net">http://bmagic.sourceforge.net</a><p>
11
 
<div class="fragment"><pre class="fragment"><span class="comment">/*</span>
12
 
<span class="comment">Copyright(c) 2002-2005 Anatoliy Kuznetsov(anatoliy_kuznetsov at yahoo.com)</span>
13
 
<span class="comment"></span>
14
 
<span class="comment">Permission is hereby granted, free of charge, to any person </span>
15
 
<span class="comment">obtaining a copy of this software and associated documentation </span>
16
 
<span class="comment">files (the "Software"), to deal in the Software without restriction, </span>
17
 
<span class="comment">including without limitation the rights to use, copy, modify, merge, </span>
18
 
<span class="comment">publish, distribute, sublicense, and/or sell copies of the Software, </span>
19
 
<span class="comment">and to permit persons to whom the Software is furnished to do so, </span>
20
 
<span class="comment">subject to the following conditions:</span>
21
 
<span class="comment"></span>
22
 
<span class="comment">The above copyright notice and this permission notice shall be included </span>
23
 
<span class="comment">in all copies or substantial portions of the Software.</span>
24
 
<span class="comment"></span>
25
 
<span class="comment">THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, </span>
26
 
<span class="comment">EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES </span>
27
 
<span class="comment">OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. </span>
28
 
<span class="comment">IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, </span>
29
 
<span class="comment">DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, </span>
30
 
<span class="comment">ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR </span>
31
 
<span class="comment">OTHER DEALINGS IN THE SOFTWARE.</span>
32
 
<span class="comment">*/</span>
33
 
<span class="comment"></span>
34
 
<span class="comment">/** \example sample5.cpp</span>
35
 
<span class="comment"> Example demonstrates using enumerators - the fastest way to retrieve </span>
36
 
<span class="comment"> indexes of 1 bits from the bitvector. This approach works faster than</span>
37
 
<span class="comment"> get_first/get_next functions.</span>
38
 
<span class="comment"> </span>
39
 
<span class="comment">  \sa bm::bvector&lt;&gt;::enumerator </span>
40
 
<span class="comment"></span>
41
 
<span class="comment">For more information please visit:  http://bmagic.sourceforge.net</span>
42
 
<span class="comment"></span>
43
 
<span class="comment">*/</span>
44
 
 
45
 
<span class="preprocessor">#include &lt;iostream&gt;</span>
46
 
<span class="preprocessor">#include &lt;algorithm&gt;</span>
47
 
<span class="preprocessor">#include "<a class="code" href="a00111.html">bm.h</a>"</span>
48
 
 
49
 
<span class="keyword">using</span> <span class="keyword">namespace </span>std;
50
 
 
51
 
<span class="keywordtype">void</span> <a name="a28"></a><a class="code" href="a00124.html#a0">Print</a>(<span class="keywordtype">unsigned</span> n)
52
 
{
53
 
    cout &lt;&lt; n &lt;&lt; endl;;
54
 
}
55
 
 
56
 
<span class="keywordtype">int</span> <a name="a29"></a><a class="code" href="a00120.html#a0">main</a>(<span class="keywordtype">void</span>)
57
 
{
58
 
    <a name="_a30"></a><a class="code" href="a00084.html">bm::bvector&lt;&gt;</a>   bv;    
59
 
 
60
 
    bv[10] = <span class="keyword">true</span>;
61
 
    bv[100] = <span class="keyword">true</span>;
62
 
    bv[10000] = <span class="keyword">true</span>;
63
 
 
64
 
    <a class="code" href="a00084.html">bm::bvector&lt;&gt;</a>::enumerator en = bv.<a name="a31"></a><a class="code" href="a00084.html#a61">first</a>();
65
 
    <a class="code" href="a00084.html">bm::bvector&lt;&gt;</a>::enumerator en_end = bv.<a name="a32"></a><a class="code" href="a00084.html#a62">end</a>();
66
 
 
67
 
    <span class="keywordflow">while</span> (en &lt; en_end)
68
 
    {
69
 
        cout &lt;&lt; *en &lt;&lt; endl;
70
 
        ++en;  <span class="comment">// Fastest way to increment enumerator</span>
71
 
    }
72
 
 
73
 
    en = bv.<a class="code" href="a00084.html#a61">first</a>();
74
 
 
75
 
    <span class="comment">// This is not the fastest way to do the job, because for_each </span>
76
 
    <span class="comment">// often will try to calculate difference between iterators,</span>
77
 
    <span class="comment">// which is expensive for enumerators.</span>
78
 
    <span class="comment">// But it can be useful for some STL loyal applications. </span>
79
 
 
80
 
    std::for_each(en, en_end, Print);
81
 
 
82
 
    <span class="keywordflow">return</span> 0;
83
 
}
84
 
</pre></div> <hr size="1"><address style="align: right;"><small>Generated on Sun Aug 5 14:12:25 2007 for BitMagic by&nbsp;
85
 
<a href="http://www.doxygen.org/index.html">
86
 
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.1 </small></address>
87
 
</body>
88
 
</html>