23
23
<div class="contents">
24
24
<h1>sample10.cpp</h1><p>Example of how to get random subset of a bit-vector For more information please visit: <a href="http://bmagic.sourceforge.net">http://bmagic.sourceforge.net</a></p>
25
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="a00079.html">bm::random_subset</a></dd></dl>
25
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="a00080.html">bm::random_subset</a></dd></dl>
26
26
<div class="fragment"><pre class="fragment"><span class="comment">/*</span>
27
27
<span class="comment">Copyright(c) 2002-2005 Anatoliy Kuznetsov(anatoliy_kuznetsov at yahoo.com)</span>
28
28
<span class="comment"></span>
58
58
<span class="preprocessor">#include <iostream></span>
59
<span class="preprocessor">#include "<a class="code" href="a00087.html">bm.h</a>"</span>
60
<span class="preprocessor">#include "<a class="code" href="a00095.html">bmrandom.h</a>"</span>
59
<span class="preprocessor">#include "<a class="code" href="a00088.html">bm.h</a>"</span>
60
<span class="preprocessor">#include "<a class="code" href="a00096.html">bmrandom.h</a>"</span>
62
62
<span class="keyword">using namespace </span>std;
64
<span class="keyword">template</span><<span class="keyword">class</span> T> <span class="keywordtype">void</span> <a name="a0"></a><a class="code" href="a00113.html#ab7f435443f8dbf9f50e4ad0efea8b1f8">PrintContainer</a>(T first, T last)
64
<span class="keyword">template</span><<span class="keyword">class</span> T> <span class="keywordtype">void</span> <a name="a0"></a><a class="code" href="a00114.html#ab7f435443f8dbf9f50e4ad0efea8b1f8">PrintContainer</a>(T first, T last)
66
66
<span class="keywordflow">if</span> (first == last)
67
67
cout << <span class="stringliteral">"<EMPTY SET>"</span>;
75
<span class="keywordtype">int</span> <a name="a1"></a><a class="code" href="a00105.html#a840291bc02cba5474a4cb46a9b9566fe">main</a>(<span class="keywordtype">void</span>)
75
<span class="keywordtype">int</span> <a name="a1"></a><a class="code" href="a00106.html#a840291bc02cba5474a4cb46a9b9566fe">main</a>(<span class="keywordtype">void</span>)
77
77
<a name="_a2"></a><a class="code" href="a00044.html" title="bitvector with runtime compression of bits.">bm::bvector<></a> bv;
96
96
<span class="comment">// random sampler instance can be shared between calls</span>
97
97
<span class="comment">//</span>
98
<a name="_a4"></a><a class="code" href="a00079.html">bm::random_subset<bm::bvector<></a> > rand_sampler;
99
rand_sampler.<a name="a5"></a><a class="code" href="a00079.html#addbc2e7ae5308fed4c92da441b236ce4" title="Get random subset of input vector.">sample</a>(bvsubset1, bv, 20);
100
rand_sampler.<a class="code" href="a00079.html#addbc2e7ae5308fed4c92da441b236ce4" title="Get random subset of input vector.">sample</a>(bvsubset2, bv, 20);
98
<a name="_a4"></a><a class="code" href="a00080.html">bm::random_subset<bm::bvector<></a> > rand_sampler;
99
rand_sampler.<a name="a5"></a><a class="code" href="a00080.html#addbc2e7ae5308fed4c92da441b236ce4" title="Get random subset of input vector.">sample</a>(bvsubset1, bv, 20);
100
rand_sampler.<a class="code" href="a00080.html#addbc2e7ae5308fed4c92da441b236ce4" title="Get random subset of input vector.">sample</a>(bvsubset2, bv, 20);
102
<a class="code" href="a00113.html#ab7f435443f8dbf9f50e4ad0efea8b1f8">PrintContainer</a>(bvsubset1.<a name="a6"></a><a class="code" href="a00044.html#aad48c661f843e32c9893438a6f27a8f0" title="Returns enumerator pointing on the first non-zero bit.">first</a>(), bvsubset1.<a name="a7"></a><a class="code" href="a00044.html#a2c6e522f858fdc466765d2c0f269f590" title="Returns enumerator pointing on the next bit after the last.">end</a>());
102
<a class="code" href="a00114.html#ab7f435443f8dbf9f50e4ad0efea8b1f8">PrintContainer</a>(bvsubset1.<a name="a6"></a><a class="code" href="a00044.html#aad48c661f843e32c9893438a6f27a8f0" title="Returns enumerator pointing on the first non-zero bit.">first</a>(), bvsubset1.<a name="a7"></a><a class="code" href="a00044.html#a2c6e522f858fdc466765d2c0f269f590" title="Returns enumerator pointing on the next bit after the last.">end</a>());
103
103
cout << endl;
104
<a class="code" href="a00113.html#ab7f435443f8dbf9f50e4ad0efea8b1f8">PrintContainer</a>(bvsubset2.<a class="code" href="a00044.html#aad48c661f843e32c9893438a6f27a8f0" title="Returns enumerator pointing on the first non-zero bit.">first</a>(), bvsubset2.<a class="code" href="a00044.html#a2c6e522f858fdc466765d2c0f269f590" title="Returns enumerator pointing on the next bit after the last.">end</a>());
104
<a class="code" href="a00114.html#ab7f435443f8dbf9f50e4ad0efea8b1f8">PrintContainer</a>(bvsubset2.<a class="code" href="a00044.html#aad48c661f843e32c9893438a6f27a8f0" title="Returns enumerator pointing on the first non-zero bit.">first</a>(), bvsubset2.<a class="code" href="a00044.html#a2c6e522f858fdc466765d2c0f269f590" title="Returns enumerator pointing on the next bit after the last.">end</a>());
106
106
<span class="keywordflow">return</span> 0;
109
109
</pre></div> </div>
110
<hr size="1"/><address style="text-align: right;"><small>Generated on Fri Jan 8 20:09:19 2010 for BitMagic by
110
<hr size="1"/><address style="text-align: right;"><small>Generated on Tue Mar 23 20:47:54 2010 for BitMagic by
111
111
<a href="http://www.doxygen.org/index.html">
112
112
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>