File: sample11_8cpp-example.html

package info (click to toggle)
bmagic 6.3.0-1
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 49,956 kB
  • sloc: cpp: 84,298; ansic: 9,703; sh: 1,664; makefile: 742
file content (474 lines) | stat: -rwxr-xr-x 60,769 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.17"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>BitMagic-C++: sample11.cpp</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">BitMagic-C++
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.17 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',false,false,'search.php','Search');
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">sample11.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<p>Example of how to use various bit counting techniques</p><dl class="section see"><dt>See also</dt><dd><a class="el" href="classbm_1_1bvector.html#a3009ba9b116f13f4933a48641f3a695d" title="population cout (count of ON bits)">bm::bvector&lt;&gt;::count()</a> </dd>
<dd>
<a class="el" href="classbm_1_1bvector.html#a99395aaa8ab689455054bda9b261de60" title="Returns count of 1 bits in the given range [left..right] Uses rank-select index to accelerate the sea...">bm::bvector&lt;&gt;::count_range()</a> </dd>
<dd>
<a class="el" href="classbm_1_1bvector.html#ad3e0e88f17cc86b58e006186955c461b" title="Returns count of 1 bits (population) in [0..right] range.">bm::bvector&lt;&gt;::count_to()</a> </dd>
<dd>
<a class="el" href="group__setalgo.html#ga5fb1131811b7b834dfc56a3874667a65" title="Computes bitcount of AND operation of two bitsets.">bm::count_and()</a> </dd>
<dd>
bm::bvector&lt;&gt;::counted_enumerator</dd></dl>
<div class="fragment"><div class="line"><span class="comment">/*</span></div>
<div class="line"><span class="comment">Copyright(c) 2002-2017 Anatoliy Kuznetsov(anatoliy_kuznetsov at yahoo.com)</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span></div>
<div class="line"><span class="comment">you may not use this file except in compliance with the License.</span></div>
<div class="line"><span class="comment">You may obtain a copy of the License at</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">    http://www.apache.org/licenses/LICENSE-2.0</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">Unless required by applicable law or agreed to in writing, software</span></div>
<div class="line"><span class="comment">distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span></div>
<div class="line"><span class="comment">WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span></div>
<div class="line"><span class="comment">See the License for the specific language governing permissions and</span></div>
<div class="line"><span class="comment">limitations under the License.</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">For more information please visit:  http://bitmagic.io</span></div>
<div class="line"><span class="comment">*/</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">/** \example sample11.cpp</span></div>
<div class="line"><span class="comment">  Example of how to use various bit counting techniques</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">  \sa bm::bvector&lt;&gt;::count() </span></div>
<div class="line"><span class="comment">  \sa bm::bvector&lt;&gt;::count_range()</span></div>
<div class="line"><span class="comment">  \sa bm::bvector&lt;&gt;::count_to() </span></div>
<div class="line"><span class="comment">  \sa bm::count_and() </span></div>
<div class="line"><span class="comment">  \sa bm::bvector&lt;&gt;::counted_enumerator</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">/*! \file sample11.cpp</span></div>
<div class="line"><span class="comment">    \brief Example: bvector&lt;&gt; bit-counting techniques analysis</span></div>
<div class="line"><span class="comment">*/</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;random&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;memory&gt;</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#include &quot;<a class="code" href="bm_8h.html">bm.h</a>&quot;</span></div>
<div class="line"><span class="preprocessor">#include &quot;<a class="code" href="bmalgo_8h.html">bmalgo.h</a>&quot;</span></div>
<div class="line"><span class="preprocessor">#include &quot;<a class="code" href="bmtimer_8h.html">bmtimer.h</a>&quot;</span></div>
<div class="line"> </div>
<div class="line"><span class="keyword">using namespace </span>std;</div>
<div class="line"> </div>
<div class="line"><span class="comment">// timing storage for benchmarking</span></div>
<div class="line"><a class="code" href="classbm_1_1chrono__taker.html#add1676592117ed0eaa2fa6279a71b46a">bm::chrono_taker::duration_map_type</a>  <a name="a0"></a><a class="code" href="sample11_8cpp.html#a6cb51d150528a5d2d87acb3e88f450bc">timing_map</a>;</div>
<div class="line"> </div>
<div class="line"><span class="keyword">const</span> <span class="keywordtype">unsigned</span> <a name="a1"></a><a class="code" href="sample11_8cpp.html#a12d500a3c5d539076999df209ab93064">benchmark_count</a> = 10000;</div>
<div class="line"><span class="keywordtype">unsigned</span>            <a name="a2"></a><a class="code" href="sample11_8cpp.html#a0bda51ccc776fd4e0af7cf8bec7aeb63">vector_max</a> = 400000000;</div>
<div class="line"> </div>
<div class="line">std::random_device <a name="a3"></a><a class="code" href="sample11_8cpp.html#a4d7cf7e96896f9aebdd79fed7c8bab7b">rand_dev</a>;  </div>
<div class="line">std::mt19937 <a name="a4"></a><a class="code" href="sample11_8cpp.html#a9b287f91e2adf83c3131895cd6e07195">gen</a>(<a class="code" href="sample11_8cpp.html#a4d7cf7e96896f9aebdd79fed7c8bab7b">rand_dev</a>()); <span class="comment">// mersenne_twister_engine </span></div>
<div class="line">std::uniform_int_distribution&lt;&gt; <a name="a5"></a><a class="code" href="sample11_8cpp.html#a8ae0e64af654605402aa541a12f3cb88">rand_dis</a>(1, <span class="keywordtype">int</span>(<a class="code" href="sample11_8cpp.html#a0bda51ccc776fd4e0af7cf8bec7aeb63">vector_max</a>)); <span class="comment">// generate uniform numebrs for [1, vector_max]</span></div>
<div class="line"> </div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">/// generate pseudo-random bit-vector, mix of blocks</span></div>
<div class="line"><span class="comment">/// </span></div>
<div class="line"><span class="comment"></span><span class="keyword">static</span></div>
<div class="line"><span class="keywordtype">void</span> <a name="a6"></a><a class="code" href="sample11_8cpp.html#ab7285eede6cb5443b9f6544fc25dc4b0">generate_bvector</a>(<a name="_a7"></a><a class="code" href="classbm_1_1bvector.html">bm::bvector&lt;&gt;</a>&amp; bv)</div>
<div class="line">{</div>
<div class="line">    <a class="code" href="classbm_1_1bvector.html#a405dd9ed048c935c84a5086ec8ba3649">bm::bvector&lt;&gt;::size_type</a> i, j;</div>
<div class="line">    <span class="keywordflow">for</span> (i = 0; i &lt; <a class="code" href="sample11_8cpp.html#a0bda51ccc776fd4e0af7cf8bec7aeb63">vector_max</a>;)</div>
<div class="line">    {</div>
<div class="line">        <span class="comment">// generate bit-blocks</span></div>
<div class="line">        <span class="keywordflow">for</span> (j = 0; j &lt; 65535*8; i += 10, j++)</div>
<div class="line">        {</div>
<div class="line">            bv.<a name="a8"></a><a class="code" href="classbm_1_1bvector.html#a52b4259a5cc4ebd8953832c696e24f02">set</a>(i);</div>
<div class="line">        }</div>
<div class="line">        <span class="keywordflow">if</span> (i &gt; <a class="code" href="sample11_8cpp.html#a0bda51ccc776fd4e0af7cf8bec7aeb63">vector_max</a>)</div>
<div class="line">            <span class="keywordflow">break</span>;</div>
<div class="line">        <span class="comment">// generate GAP (compressed) blocks</span></div>
<div class="line">        <span class="keywordflow">for</span> (j = 0; j &lt; 65535; i += 120, j++)</div>
<div class="line">        {</div>
<div class="line">            <span class="keywordtype">unsigned</span> len = rand() % 64;</div>
<div class="line">            bv.<a name="a9"></a><a class="code" href="classbm_1_1bvector.html#aafb2ecaa1a55856533e6b4afbf788eae">set_range</a>(i, i + len);</div>
<div class="line">            i += len;</div>
<div class="line">            <span class="keywordflow">if</span> (i &gt; <a class="code" href="sample11_8cpp.html#a0bda51ccc776fd4e0af7cf8bec7aeb63">vector_max</a>)</div>
<div class="line">                <span class="keywordflow">break</span>;</div>
<div class="line">        }</div>
<div class="line">    }</div>
<div class="line"> </div>
<div class="line">    <span class="comment">// compress vector</span></div>
<div class="line">    <a name="a10"></a><a class="code" href="bm_8h.html#ad9736d9521d713fa5d48859aa720bfdd">BM_DECLARE_TEMP_BLOCK</a>(tb)</div>
<div class="line">    bv.<a name="a11"></a><a class="code" href="classbm_1_1bvector.html#a622e6827d799a561e2f0db28f7ac19d2">optimize</a>(tb);</div>
<div class="line"> </div>
<div class="line">    <span class="comment">// compute bit-vector statistics</span></div>
<div class="line">    <a name="_a12"></a><a class="code" href="structbm_1_1bvector_1_1statistics.html">bm::bvector&lt;&gt;::statistics</a> st;</div>
<div class="line">    bv.<a name="a13"></a><a class="code" href="classbm_1_1bvector.html#af30532c371bfdc8e2ba02bc2115b004d">calc_stat</a>(&amp;st);</div>
<div class="line"> </div>
<div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;Bit-vector statistics: GAP (compressed blocks)=&quot;</span> &lt;&lt; st.<a name="a14"></a><a class="code" href="structbm_1_1bv__statistics.html#a68582594950732906ddea7a99f8cd0b7">gap_blocks</a></div>
<div class="line">              &lt;&lt; <span class="stringliteral">&quot;, BIT (uncompressed blocks)=&quot;</span> &lt;&lt; st.<a name="a15"></a><a class="code" href="structbm_1_1bv__statistics.html#a7be7eba0cd58b422085b2c8c75c7e188">bit_blocks</a></div>
<div class="line">              &lt;&lt; std::endl &lt;&lt; std::endl;</div>
<div class="line">}</div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">/// &quot;pre-heat&quot; CPU to minimize dynamic overclocking effects</span></div>
<div class="line"><span class="comment">///</span></div>
<div class="line"><span class="comment"></span><span class="keyword">static</span></div>
<div class="line"><a class="code" href="classbm_1_1bvector.html#a405dd9ed048c935c84a5086ec8ba3649">bm::bvector&lt;&gt;::size_type</a> <a name="a16"></a><a class="code" href="sample11_8cpp.html#a48ceb6492f4796160706cf8565472ff3">pre_heat</a>(<span class="keyword">const</span> <a class="code" href="classbm_1_1bvector.html">bm::bvector&lt;&gt;</a>&amp; bv)</div>
<div class="line">{</div>
<div class="line">    <a class="code" href="classbm_1_1bvector.html#a405dd9ed048c935c84a5086ec8ba3649">bm::bvector&lt;&gt;::size_type</a> cnt = 0;</div>
<div class="line">    <a class="code" href="classbm_1_1bvector.html#a405dd9ed048c935c84a5086ec8ba3649">bm::bvector&lt;&gt;::size_type</a> m = 1;</div>
<div class="line">    <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0; i &lt; <a class="code" href="sample11_8cpp.html#a12d500a3c5d539076999df209ab93064">benchmark_count</a>; ++i)</div>
<div class="line">    {</div>
<div class="line">        cnt += bv.<a name="a17"></a><a class="code" href="classbm_1_1bvector.html#a3009ba9b116f13f4933a48641f3a695d">count</a>();</div>
<div class="line">        m+=cnt*cnt;</div>
<div class="line">    }</div>
<div class="line">    <span class="keywordflow">return</span> m;</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">/// simple population count for the whole vector</span></div>
<div class="line"><span class="comment">///</span></div>
<div class="line"><span class="comment"></span><span class="keyword">static</span></div>
<div class="line"><span class="keywordtype">void</span> <a name="a18"></a><a class="code" href="sample11_8cpp.html#ab25c9ea3f03a5bdc900317e043b8bdaa">bv_count_test</a>(<span class="keyword">const</span> <a class="code" href="classbm_1_1bvector.html">bm::bvector&lt;&gt;</a>&amp; bv)</div>
<div class="line">{</div>
<div class="line">    <a class="code" href="classbm_1_1bvector.html#a405dd9ed048c935c84a5086ec8ba3649">bm::bvector&lt;&gt;::size_type</a> cnt = 0;</div>
<div class="line"> </div>
<div class="line">    {</div>
<div class="line">        <a name="_a19"></a><a class="code" href="classbm_1_1chrono__taker.html">bm::chrono_taker</a> tt1(<span class="stringliteral">&quot;1. bvector&lt;&gt;::count()&quot;</span>, <a class="code" href="sample11_8cpp.html#a12d500a3c5d539076999df209ab93064">benchmark_count</a> / 2, &amp;<a class="code" href="sample11_8cpp.html#a6cb51d150528a5d2d87acb3e88f450bc">timing_map</a>);</div>
<div class="line">        <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0; i &lt; <a class="code" href="sample11_8cpp.html#a12d500a3c5d539076999df209ab93064">benchmark_count</a> / 2; ++i)</div>
<div class="line">        {</div>
<div class="line">            cnt += bv.<a class="code" href="classbm_1_1bvector.html#a3009ba9b116f13f4933a48641f3a695d">count</a>();</div>
<div class="line">        }</div>
<div class="line">    }</div>
<div class="line">    <span class="comment">// this is mostly to prevent compiler to optimize loop away</span></div>
<div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;Count test finished.&quot;</span> &lt;&lt; cnt &lt;&lt; <span class="stringliteral">&quot;\r&quot;</span>;</div>
<div class="line">}</div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">/// count_range() test</span></div>
<div class="line"><span class="comment">///</span></div>
<div class="line"><span class="comment"></span><span class="keyword">static</span></div>
<div class="line"><span class="keywordtype">void</span> <a name="a20"></a><a class="code" href="sample11_8cpp.html#a35469dd094dc5eaf7328f2b36d7c04bd">bv_count_range</a>(<span class="keyword">const</span> <a class="code" href="classbm_1_1bvector.html">bm::bvector&lt;&gt;</a>&amp; bv)</div>
<div class="line">{</div>
<div class="line">    <a class="code" href="classbm_1_1bvector.html#a405dd9ed048c935c84a5086ec8ba3649">bm::bvector&lt;&gt;::size_type</a> cnt = 0;</div>
<div class="line">    {</div>
<div class="line">        <a class="code" href="classbm_1_1chrono__taker.html">bm::chrono_taker</a> tt1(<span class="stringliteral">&quot;2. bvector&lt;&gt;::count_range()&quot;</span>, <a class="code" href="sample11_8cpp.html#a12d500a3c5d539076999df209ab93064">benchmark_count</a>, &amp;<a class="code" href="sample11_8cpp.html#a6cb51d150528a5d2d87acb3e88f450bc">timing_map</a>);</div>
<div class="line">        <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0; i &lt; <a class="code" href="sample11_8cpp.html#a12d500a3c5d539076999df209ab93064">benchmark_count</a>; ++i)</div>
<div class="line">        {</div>
<div class="line">            <span class="keywordtype">unsigned</span> from = unsigned(<a class="code" href="sample11_8cpp.html#a8ae0e64af654605402aa541a12f3cb88">rand_dis</a>(<a class="code" href="sample11_8cpp.html#a9b287f91e2adf83c3131895cd6e07195">gen</a>));</div>
<div class="line">            <span class="keywordtype">unsigned</span> to = unsigned(<a class="code" href="sample11_8cpp.html#a8ae0e64af654605402aa541a12f3cb88">rand_dis</a>(<a class="code" href="sample11_8cpp.html#a9b287f91e2adf83c3131895cd6e07195">gen</a>));</div>
<div class="line">            <span class="keywordflow">if</span> (from &gt; to)</div>
<div class="line">                swap(from, to);</div>
<div class="line">            cnt += bv.<a name="a21"></a><a class="code" href="classbm_1_1bvector.html#a99395aaa8ab689455054bda9b261de60">count_range</a>(from, to);</div>
<div class="line">        }</div>
<div class="line">    }</div>
<div class="line">    <span class="comment">// this is mostly to prevent compiler to optimize loop away</span></div>
<div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;Count range test finished.&quot;</span> &lt;&lt; cnt &lt;&lt; <span class="stringliteral">&quot;\r&quot;</span>;</div>
<div class="line">}</div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">/// count_range() test using pre-calculated blocks bit count</span></div>
<div class="line"><span class="comment">///</span></div>
<div class="line"><span class="comment"></span><span class="keyword">static</span></div>
<div class="line"><span class="keywordtype">void</span> <a name="a22"></a><a class="code" href="sample11_8cpp.html#a4d9edd508c01ff7825dd1dd6c5cb159d">bv_count_range_acc</a>(<span class="keyword">const</span> <a class="code" href="classbm_1_1bvector.html">bm::bvector&lt;&gt;</a>&amp; bv)</div>
<div class="line">{</div>
<div class="line">    <a class="code" href="classbm_1_1bvector.html#a405dd9ed048c935c84a5086ec8ba3649">bm::bvector&lt;&gt;::size_type</a> cnt = 0;</div>
<div class="line">    </div>
<div class="line">    std::unique_ptr&lt;bm::bvector&lt;&gt;::rs_index_type&gt; rs(<span class="keyword">new</span> <a class="code" href="classbm_1_1bvector.html#ac9ed62250af37ade811aaf20b7a8d9a2">bm::bvector&lt;&gt;::rs_index_type</a>());</div>
<div class="line">    bv.<a name="a23"></a><a class="code" href="classbm_1_1bvector.html#adfb63744a9d6039d9e8daa38cf21e3c6">build_rs_index</a>(rs.get());</div>
<div class="line"> </div>
<div class="line">    {</div>
<div class="line">        <a class="code" href="classbm_1_1chrono__taker.html">bm::chrono_taker</a> tt1(<span class="stringliteral">&quot;3. bvector&lt;&gt;::count_range() with rs_index&quot;</span>, <a class="code" href="sample11_8cpp.html#a12d500a3c5d539076999df209ab93064">benchmark_count</a>, &amp;<a class="code" href="sample11_8cpp.html#a6cb51d150528a5d2d87acb3e88f450bc">timing_map</a>);</div>
<div class="line">        cnt = 0;</div>
<div class="line">        <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0; i &lt; <a class="code" href="sample11_8cpp.html#a12d500a3c5d539076999df209ab93064">benchmark_count</a>; ++i)</div>
<div class="line">        {</div>
<div class="line">            <span class="keywordtype">unsigned</span> from = unsigned(<a class="code" href="sample11_8cpp.html#a8ae0e64af654605402aa541a12f3cb88">rand_dis</a>(<a class="code" href="sample11_8cpp.html#a9b287f91e2adf83c3131895cd6e07195">gen</a>));</div>
<div class="line">            <span class="keywordtype">unsigned</span> to = unsigned(<a class="code" href="sample11_8cpp.html#a8ae0e64af654605402aa541a12f3cb88">rand_dis</a>(<a class="code" href="sample11_8cpp.html#a9b287f91e2adf83c3131895cd6e07195">gen</a>));</div>
<div class="line">            <span class="keywordflow">if</span> (from &gt; to)</div>
<div class="line">                swap(from, to);</div>
<div class="line">            cnt += bv.<a class="code" href="classbm_1_1bvector.html#a99395aaa8ab689455054bda9b261de60">count_range</a>(from, to, *rs); <span class="comment">// use rs index for acceleration</span></div>
<div class="line">        } <span class="comment">// for i</span></div>
<div class="line">    }</div>
<div class="line">    <span class="comment">// this is mostly to prevent compiler to optimize loop away</span></div>
<div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;Count range with blocks test finished.&quot;</span> &lt;&lt; cnt &lt;&lt; <span class="stringliteral">&quot;\r&quot;</span>;</div>
<div class="line">}</div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">/// count_to() test using pre-calculated rank-select index</span></div>
<div class="line"><span class="comment">///</span></div>
<div class="line"><span class="comment"></span><span class="keyword">static</span></div>
<div class="line"><span class="keywordtype">void</span> <a name="a24"></a><a class="code" href="sample11_8cpp.html#aee1d3b9b188e54f8b1fd35e8362f3b7c">bv_count_to_acc</a>(<span class="keyword">const</span> <a class="code" href="classbm_1_1bvector.html">bm::bvector&lt;&gt;</a>&amp; bv)</div>
<div class="line">{</div>
<div class="line">    <a class="code" href="classbm_1_1bvector.html#a405dd9ed048c935c84a5086ec8ba3649">bm::bvector&lt;&gt;::size_type</a> cnt = 0;</div>
<div class="line">    </div>
<div class="line">    <span class="comment">// build a block population count list, used for count_to() acceleration</span></div>
<div class="line">    std::unique_ptr&lt;bm::bvector&lt;&gt;::rs_index_type&gt; rs(<span class="keyword">new</span> <a class="code" href="classbm_1_1bvector.html#ac9ed62250af37ade811aaf20b7a8d9a2">bm::bvector&lt;&gt;::rs_index_type</a>());</div>
<div class="line">    bv.<a class="code" href="classbm_1_1bvector.html#adfb63744a9d6039d9e8daa38cf21e3c6">build_rs_index</a>(rs.get());</div>
<div class="line"> </div>
<div class="line">    {</div>
<div class="line">        <a class="code" href="classbm_1_1chrono__taker.html">bm::chrono_taker</a> tt1(<span class="stringliteral">&quot;4. bvector&lt;&gt;::count_to() with rs_index&quot;</span>, <a class="code" href="sample11_8cpp.html#a12d500a3c5d539076999df209ab93064">benchmark_count</a>, &amp;<a class="code" href="sample11_8cpp.html#a6cb51d150528a5d2d87acb3e88f450bc">timing_map</a>);</div>
<div class="line"> </div>
<div class="line">        <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0; i &lt; <a class="code" href="sample11_8cpp.html#a12d500a3c5d539076999df209ab93064">benchmark_count</a>; ++i)</div>
<div class="line">        {</div>
<div class="line">            <span class="keywordtype">unsigned</span> to = unsigned(<a class="code" href="sample11_8cpp.html#a8ae0e64af654605402aa541a12f3cb88">rand_dis</a>(<a class="code" href="sample11_8cpp.html#a9b287f91e2adf83c3131895cd6e07195">gen</a>));</div>
<div class="line">            cnt += bv.<a name="a25"></a><a class="code" href="classbm_1_1bvector.html#ad3e0e88f17cc86b58e006186955c461b">count_to</a>(to, *rs); <span class="comment">// use rank-select index for acceleration</span></div>
<div class="line">        }</div>
<div class="line">    }</div>
<div class="line">    <span class="comment">// this is mostly to prevent compiler to optimize loop away</span></div>
<div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;Count to with blocks test finished.&quot;</span> &lt;&lt; cnt &lt;&lt; <span class="stringliteral">&quot;\r&quot;</span>;</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">/// count_range implemented via two count_to() calls using pre-calculated</span></div>
<div class="line"><span class="comment">/// rank-select index</span></div>
<div class="line"><span class="comment">///</span></div>
<div class="line"><span class="comment"></span><span class="keyword">static</span></div>
<div class="line"><span class="keywordtype">void</span> <a name="a26"></a><a class="code" href="sample11_8cpp.html#a4c3aa36d9bdcf58161571ffb69f5211a">bv_count_to_range_acc</a>(<span class="keyword">const</span> <a class="code" href="classbm_1_1bvector.html">bm::bvector&lt;&gt;</a>&amp; bv)</div>
<div class="line">{</div>
<div class="line">    <a class="code" href="classbm_1_1bvector.html#a405dd9ed048c935c84a5086ec8ba3649">bm::bvector&lt;&gt;::size_type</a> cnt = 0;</div>
<div class="line">    </div>
<div class="line">    <span class="comment">// build a block population count list, used for count_to() acceleration</span></div>
<div class="line">    std::unique_ptr&lt;bm::bvector&lt;&gt;::rs_index_type&gt; rs(<span class="keyword">new</span> <a class="code" href="classbm_1_1bvector.html#ac9ed62250af37ade811aaf20b7a8d9a2">bm::bvector&lt;&gt;::rs_index_type</a>());</div>
<div class="line">    bv.<a class="code" href="classbm_1_1bvector.html#adfb63744a9d6039d9e8daa38cf21e3c6">build_rs_index</a>(rs.get());</div>
<div class="line"> </div>
<div class="line">    {</div>
<div class="line">        <a class="code" href="classbm_1_1chrono__taker.html">bm::chrono_taker</a> tt1(<span class="stringliteral">&quot;5. bvector&lt;&gt;::count_to to simulate count_range()&quot;</span>, <a class="code" href="sample11_8cpp.html#a12d500a3c5d539076999df209ab93064">benchmark_count</a>, &amp;<a class="code" href="sample11_8cpp.html#a6cb51d150528a5d2d87acb3e88f450bc">timing_map</a>);</div>
<div class="line"> </div>
<div class="line">        <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0; i &lt; <a class="code" href="sample11_8cpp.html#a12d500a3c5d539076999df209ab93064">benchmark_count</a>; ++i)</div>
<div class="line">        {</div>
<div class="line">            <span class="keywordtype">unsigned</span> from = unsigned(<a class="code" href="sample11_8cpp.html#a8ae0e64af654605402aa541a12f3cb88">rand_dis</a>(<a class="code" href="sample11_8cpp.html#a9b287f91e2adf83c3131895cd6e07195">gen</a>));</div>
<div class="line">            <span class="keywordtype">unsigned</span> to = unsigned(<a class="code" href="sample11_8cpp.html#a8ae0e64af654605402aa541a12f3cb88">rand_dis</a>(<a class="code" href="sample11_8cpp.html#a9b287f91e2adf83c3131895cd6e07195">gen</a>));</div>
<div class="line">            <span class="keywordflow">if</span> (from &gt; to)</div>
<div class="line">                swap(from, to);</div>
<div class="line">            </div>
<div class="line">            <a class="code" href="classbm_1_1bvector.html#a405dd9ed048c935c84a5086ec8ba3649">bm::bvector&lt;&gt;::size_type</a> cnt_to = bv.<a class="code" href="classbm_1_1bvector.html#ad3e0e88f17cc86b58e006186955c461b">count_to</a>(to, *rs);</div>
<div class="line">            <a class="code" href="classbm_1_1bvector.html#a405dd9ed048c935c84a5086ec8ba3649">bm::bvector&lt;&gt;::size_type</a> cnt_from = bv.<a class="code" href="classbm_1_1bvector.html#ad3e0e88f17cc86b58e006186955c461b">count_to</a>(from - 1, *rs);</div>
<div class="line">            <a class="code" href="classbm_1_1bvector.html#a405dd9ed048c935c84a5086ec8ba3649">bm::bvector&lt;&gt;::size_type</a> cnt_r = cnt_to - cnt_from;</div>
<div class="line">            cnt += cnt_r;</div>
<div class="line">        }</div>
<div class="line">    }</div>
<div class="line">    <span class="comment">// this is mostly to prevent compiler to optimize loop away</span></div>
<div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;Count range via count_to test finished.&quot;</span> &lt;&lt; cnt &lt;&lt; <span class="stringliteral">&quot;\r&quot;</span>;</div>
<div class="line">}</div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">/// count_range implemented via bm::count_and</span></div>
<div class="line"><span class="comment">///</span></div>
<div class="line"><span class="comment">/// this method can be used, when we need co compute multiple ranges in one call</span></div>
<div class="line"><span class="comment">///</span></div>
<div class="line"><span class="comment"></span><span class="keyword">static</span></div>
<div class="line"><span class="keywordtype">void</span> <a name="a27"></a><a class="code" href="sample11_8cpp.html#aed38ada83d28bf639a9c13a307626b8b">bv_count_and</a>(<span class="keyword">const</span> <a class="code" href="classbm_1_1bvector.html">bm::bvector&lt;&gt;</a>&amp; bv)</div>
<div class="line">{</div>
<div class="line">    <a class="code" href="classbm_1_1bvector.html#a405dd9ed048c935c84a5086ec8ba3649">bm::bvector&lt;&gt;::size_type</a> cnt = 0;</div>
<div class="line">    {</div>
<div class="line">        <a class="code" href="classbm_1_1chrono__taker.html">bm::chrono_taker</a> tt1(<span class="stringliteral">&quot;6. bm::count_and with mask vector&quot;</span>, <a class="code" href="sample11_8cpp.html#a12d500a3c5d539076999df209ab93064">benchmark_count</a>, &amp;<a class="code" href="sample11_8cpp.html#a6cb51d150528a5d2d87acb3e88f450bc">timing_map</a>);</div>
<div class="line"> </div>
<div class="line">        <a class="code" href="classbm_1_1bvector.html">bm::bvector&lt;&gt;</a> mask_bv(<a name="a28"></a><a class="code" href="group__bvector.html#ggad0b87b3b7292383a864d27feaf1c9effa7fe09d1d7c62a813db922c396c0cbc9c">bm::BM_GAP</a>); <span class="comment">// use compressed mask, better seluts on long ranges</span></div>
<div class="line">        <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0; i &lt; <a class="code" href="sample11_8cpp.html#a12d500a3c5d539076999df209ab93064">benchmark_count</a>; ++i)</div>
<div class="line">        {</div>
<div class="line">            <span class="keywordtype">unsigned</span> from = unsigned(<a class="code" href="sample11_8cpp.html#a8ae0e64af654605402aa541a12f3cb88">rand_dis</a>(<a class="code" href="sample11_8cpp.html#a9b287f91e2adf83c3131895cd6e07195">gen</a>));</div>
<div class="line">            <span class="keywordtype">unsigned</span> to = unsigned(<a class="code" href="sample11_8cpp.html#a8ae0e64af654605402aa541a12f3cb88">rand_dis</a>(<a class="code" href="sample11_8cpp.html#a9b287f91e2adf83c3131895cd6e07195">gen</a>));</div>
<div class="line">            <span class="keywordflow">if</span> (from &gt; to)</div>
<div class="line">                swap(from, to);</div>
<div class="line"> </div>
<div class="line">            mask_bv.set_range(from, to, <span class="keyword">true</span>); <span class="comment">// set mask vector</span></div>
<div class="line"> </div>
<div class="line">            cnt += <a name="a29"></a><a class="code" href="group__setalgo.html#ga5fb1131811b7b834dfc56a3874667a65">bm::count_and</a>(bv, mask_bv);</div>
<div class="line">            mask_bv.clear(<span class="keyword">true</span>); <span class="comment">// clear and free memory (faster)</span></div>
<div class="line">        }</div>
<div class="line">    }</div>
<div class="line">    <span class="comment">// this is mostly to prevent compiler to optimize loop away</span></div>
<div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;count AND finished.&quot;</span> &lt;&lt; cnt &lt;&lt; <span class="stringliteral">&quot;\r&quot;</span>;</div>
<div class="line">}</div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">/// count_to implemented via bm::bvector&lt;&gt;::counted_enumerator</span></div>
<div class="line"><span class="comment">///</span></div>
<div class="line"><span class="comment">/// Counted enumerator is an iterator automata, which counts the running population count </span></div>
<div class="line"><span class="comment">/// along the iteration sequence</span></div>
<div class="line"><span class="comment">///</span></div>
<div class="line"><span class="comment"></span><span class="keyword">static</span></div>
<div class="line"><span class="keywordtype">void</span> <a name="a30"></a><a class="code" href="sample11_8cpp.html#af4945f066e89c9bc289f6ce7dc60da4d">bv_counted_enumerator</a>(<span class="keyword">const</span> <a class="code" href="classbm_1_1bvector.html">bm::bvector&lt;&gt;</a>&amp; bv)</div>
<div class="line">{</div>
<div class="line">    <a class="code" href="classbm_1_1bvector.html#a405dd9ed048c935c84a5086ec8ba3649">bm::bvector&lt;&gt;::size_type</a> cnt = 0;</div>
<div class="line">    {</div>
<div class="line">        <span class="comment">// This is a slow method so we use less iterators</span></div>
<div class="line">        <a class="code" href="classbm_1_1chrono__taker.html">bm::chrono_taker</a> tt1(<span class="stringliteral">&quot;7. bm::bvector&lt;&gt;::counted_enumerator&quot;</span>, <a class="code" href="sample11_8cpp.html#a12d500a3c5d539076999df209ab93064">benchmark_count</a>/20, &amp;<a class="code" href="sample11_8cpp.html#a6cb51d150528a5d2d87acb3e88f450bc">timing_map</a>);</div>
<div class="line"> </div>
<div class="line">        <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0; i &lt; <a class="code" href="sample11_8cpp.html#a12d500a3c5d539076999df209ab93064">benchmark_count</a>/20; ++i)</div>
<div class="line">        {</div>
<div class="line">            <span class="keywordtype">unsigned</span> to = unsigned(<a class="code" href="sample11_8cpp.html#a8ae0e64af654605402aa541a12f3cb88">rand_dis</a>(<a class="code" href="sample11_8cpp.html#a9b287f91e2adf83c3131895cd6e07195">gen</a>));</div>
<div class="line">            <a name="_a31"></a><a class="code" href="classbm_1_1bvector_1_1counted__enumerator.html">bm::bvector&lt;&gt;::counted_enumerator</a> en = bv.<a name="a32"></a><a class="code" href="classbm_1_1bvector.html#a86b939f3aed555dc073e8c26e9efea71">first</a>();</div>
<div class="line">            <span class="keywordflow">for</span> (; en.<a name="a33"></a><a class="code" href="classbm_1_1bvector_1_1iterator__base.html#a3f6af7f5b46c0219b28916187d302c43">valid</a>(); ++en)</div>
<div class="line">            {</div>
<div class="line">                <span class="keywordflow">if</span> (*en &gt; to)</div>
<div class="line">                    <span class="keywordflow">break</span>;</div>
<div class="line">            }</div>
<div class="line">            cnt += en.<a name="a34"></a><a class="code" href="classbm_1_1bvector_1_1counted__enumerator.html#a30a400c9f580df410961d3818fcbb66f">count</a>();</div>
<div class="line">        }</div>
<div class="line">    }</div>
<div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;counted_enumerator finished.&quot;</span> &lt;&lt; cnt &lt;&lt; <span class="stringliteral">&quot;\r&quot;</span>;</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> <a name="a35"></a><a class="code" href="sample11_8cpp.html#a840291bc02cba5474a4cb46a9b9566fe">main</a>(<span class="keywordtype">void</span>)</div>
<div class="line">{</div>
<div class="line">    <span class="keywordflow">try</span></div>
<div class="line">    {</div>
<div class="line">        <a class="code" href="classbm_1_1bvector.html">bm::bvector&lt;&gt;</a>   bv;</div>
<div class="line">        <a class="code" href="sample11_8cpp.html#ab7285eede6cb5443b9f6544fc25dc4b0">generate_bvector</a>(bv);</div>
<div class="line">        <span class="comment"></span></div>
<div class="line"><span class="comment">        /// pre-heat CPU to minimize dynamic overclocking</span></div>
<div class="line"><span class="comment"></span>        <span class="keywordtype">unsigned</span> s = <a class="code" href="sample11_8cpp.html#a48ceb6492f4796160706cf8565472ff3">pre_heat</a>(bv);</div>
<div class="line">        std::cout &lt;&lt; s &lt;&lt; <span class="stringliteral">&quot;\r&quot;</span>;</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line">        <span class="comment">// Test 1.</span></div>
<div class="line">        <span class="comment">// Uses plain bvector&lt;&gt;::count() to compute global population count</span></div>
<div class="line">        <span class="comment">// This function would benefit from SIMD (SSE42 / AVX2) acceleration</span></div>
<div class="line">        <span class="comment">//</span></div>
<div class="line">        <a class="code" href="sample11_8cpp.html#ab25c9ea3f03a5bdc900317e043b8bdaa">bv_count_test</a>(bv);</div>
<div class="line"> </div>
<div class="line">        <span class="comment">// Test 2.</span></div>
<div class="line">        <span class="comment">// Uses bvector&lt;&gt;::count_range() to compute population count in a randomly generated</span></div>
<div class="line">        <span class="comment">// region of a bit-vector.</span></div>
<div class="line">        <span class="comment">// This is should be naturally faster than Test 1, because it range is less than the whole</span></div>
<div class="line">        <span class="comment">//</span></div>
<div class="line">        <a class="code" href="sample11_8cpp.html#a35469dd094dc5eaf7328f2b36d7c04bd">bv_count_range</a>(bv);</div>
<div class="line"> </div>
<div class="line">        <span class="comment">// Test 3.</span></div>
<div class="line">        <span class="comment">// Uses bvector&lt;&gt;::count_range() together with bvector&lt;&gt;::count_blocks() </span></div>
<div class="line">        <span class="comment">// (pre-calculated bit-count for each block).</span></div>
<div class="line">        <span class="comment">// It make sense to use this method if bit-vector is constant (or chnages infrequently)</span></div>
<div class="line">        <span class="comment">// and we need to do many range counting calculations</span></div>
<div class="line">        <span class="comment">//</span></div>
<div class="line">        <a class="code" href="sample11_8cpp.html#a4d9edd508c01ff7825dd1dd6c5cb159d">bv_count_range_acc</a>(bv);</div>
<div class="line"> </div>
<div class="line">        <span class="comment">// Test 4.</span></div>
<div class="line">        <span class="comment">// Uses bvector&lt;&gt;::count_to() to compute population count to a specified element.</span></div>
<div class="line">        <span class="comment">// Equivalent of count_range(0, to);</span></div>
<div class="line">        <span class="comment">// This method uses acceleration structure using bvector&lt;&gt;::running_count_blocks()</span></div>
<div class="line">        <span class="comment">// It is similar to count_range acceleration, but uses a different (faster) algorithm</span></div>
<div class="line">        <span class="comment">//</span></div>
<div class="line">        <a class="code" href="sample11_8cpp.html#aee1d3b9b188e54f8b1fd35e8362f3b7c">bv_count_to_acc</a>(bv);</div>
<div class="line"> </div>
<div class="line">        <span class="comment">// Test 5.</span></div>
<div class="line">        <span class="comment">// Uses bvector&lt;&gt;::count_to() twice to simulate count_range()</span></div>
<div class="line">        <span class="comment">// using counting difference:</span></div>
<div class="line">        <span class="comment">// count_r = count_to(0, from) - count_to(0, to-1)</span></div>
<div class="line">        <span class="comment">// This method can actually be faster than count_range()</span></div>
<div class="line">        <span class="comment">//</span></div>
<div class="line">        <a class="code" href="sample11_8cpp.html#a4c3aa36d9bdcf58161571ffb69f5211a">bv_count_to_range_acc</a>(bv);</div>
<div class="line"> </div>
<div class="line">        <span class="comment">// Test 6.</span></div>
<div class="line">        <span class="comment">// Compute range population count via a mask vector and logical AND operation.</span></div>
<div class="line">        <span class="comment">// Not the fastest method, but can be useful, when multiple ranges needs to be computed</span></div>
<div class="line">        <span class="comment">//</span></div>
<div class="line">        <a class="code" href="sample11_8cpp.html#aed38ada83d28bf639a9c13a307626b8b">bv_count_and</a>(bv);</div>
<div class="line"> </div>
<div class="line">        <span class="comment">// Test 7.</span></div>
<div class="line">        <span class="comment">// Compute cout using counted_enumerator iterator</span></div>
<div class="line">        <span class="comment">// method combines iteratrion over bit vector and sliding population count</span></div>
<div class="line">        <a class="code" href="sample11_8cpp.html#af4945f066e89c9bc289f6ce7dc60da4d">bv_counted_enumerator</a>(bv);</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line">        <span class="comment">// print all test timing results</span></div>
<div class="line">        <span class="comment">//</span></div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;                                                        &quot;</span></div>
<div class="line">                  &lt;&lt; std::endl;</div>
<div class="line">                  </div>
<div class="line">        <a name="a36"></a><a class="code" href="classbm_1_1chrono__taker.html#a30b45453d952d14afe56c29087970899">bm::chrono_taker::print_duration_map</a>(<a class="code" href="sample11_8cpp.html#a6cb51d150528a5d2d87acb3e88f450bc">timing_map</a>, <a name="a37"></a><a class="code" href="classbm_1_1chrono__taker.html#a9a41e5f2fe48ba472fd77a1dbd86457dad530ca7863ce7e60f4fa221e1dfa64a2">bm::chrono_taker::ct_ops_per_sec</a>);</div>
<div class="line">    }</div>
<div class="line">    <span class="keywordflow">catch</span>(std::exception&amp; ex)</div>
<div class="line">    {</div>
<div class="line">        std::cerr &lt;&lt; ex.what() &lt;&lt; std::endl;</div>
<div class="line">        <span class="keywordflow">return</span> 1;</div>
<div class="line">    }</div>
<div class="line"> </div>
<div class="line">    <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
<div class="line"> </div>
</div><!-- fragment --> </div><!-- contents -->
<div class="ttc" id="asample11_8cpp_html_a48ceb6492f4796160706cf8565472ff3"><div class="ttname"><a href="sample11_8cpp.html#a48ceb6492f4796160706cf8565472ff3">pre_heat</a></div><div class="ttdeci">static bm::bvector ::size_type pre_heat(const bm::bvector&lt;&gt; &amp;bv)</div><div class="ttdoc">&quot;pre-heat&quot; CPU to minimize dynamic overclocking effects</div><div class="ttdef"><b>Definition:</b> <a href="sample11_8cpp_source.html#l00096">sample11.cpp:96</a></div></div>
<div class="ttc" id="aclassbm_1_1bvector_html_aafb2ecaa1a55856533e6b4afbf788eae"><div class="ttname"><a href="classbm_1_1bvector.html#aafb2ecaa1a55856533e6b4afbf788eae">bm::bvector::set_range</a></div><div class="ttdeci">bvector&lt; Alloc &gt; &amp; set_range(size_type left, size_type right, bool value=true)</div><div class="ttdoc">Sets all bits in the specified closed interval [left,right] Interval must be inside the bvector's siz...</div><div class="ttdef"><b>Definition:</b> <a href="bm_8h_source.html#l02158">bm.h:2158</a></div></div>
<div class="ttc" id="aclassbm_1_1bvector_html_af30532c371bfdc8e2ba02bc2115b004d"><div class="ttname"><a href="classbm_1_1bvector.html#af30532c371bfdc8e2ba02bc2115b004d">bm::bvector::calc_stat</a></div><div class="ttdeci">void calc_stat(struct bm::bvector&lt; Alloc &gt;::statistics *st) const BMNOEXCEPT</div><div class="ttdoc">Calculates bitvector statistics.</div><div class="ttdef"><b>Definition:</b> <a href="bm_8h_source.html#l03393">bm.h:3393</a></div></div>
<div class="ttc" id="asample11_8cpp_html_ab7285eede6cb5443b9f6544fc25dc4b0"><div class="ttname"><a href="sample11_8cpp.html#ab7285eede6cb5443b9f6544fc25dc4b0">generate_bvector</a></div><div class="ttdeci">static void generate_bvector(bm::bvector&lt;&gt; &amp;bv)</div><div class="ttdoc">generate pseudo-random bit-vector, mix of blocks</div><div class="ttdef"><b>Definition:</b> <a href="sample11_8cpp_source.html#l00057">sample11.cpp:57</a></div></div>
<div class="ttc" id="aclassbm_1_1bvector_html_ac9ed62250af37ade811aaf20b7a8d9a2"><div class="ttname"><a href="classbm_1_1bvector.html#ac9ed62250af37ade811aaf20b7a8d9a2">bm::bvector::rs_index_type</a></div><div class="ttdeci">rs_index&lt; allocator_type &gt; rs_index_type</div><div class="ttdef"><b>Definition:</b> <a href="bm_8h_source.html#l00831">bm.h:831</a></div></div>
<div class="ttc" id="asample11_8cpp_html_a12d500a3c5d539076999df209ab93064"><div class="ttname"><a href="sample11_8cpp.html#a12d500a3c5d539076999df209ab93064">benchmark_count</a></div><div class="ttdeci">const unsigned benchmark_count</div><div class="ttdef"><b>Definition:</b> <a href="sample11_8cpp_source.html#l00046">sample11.cpp:46</a></div></div>
<div class="ttc" id="asample11_8cpp_html_a6cb51d150528a5d2d87acb3e88f450bc"><div class="ttname"><a href="sample11_8cpp.html#a6cb51d150528a5d2d87acb3e88f450bc">timing_map</a></div><div class="ttdeci">bm::chrono_taker::duration_map_type timing_map</div><div class="ttdef"><b>Definition:</b> <a href="sample11_8cpp_source.html#l00044">sample11.cpp:44</a></div></div>
<div class="ttc" id="aclassbm_1_1chrono__taker_html"><div class="ttname"><a href="classbm_1_1chrono__taker.html">bm::chrono_taker</a></div><div class="ttdoc">Utility class to collect performance measurements and statistics.</div><div class="ttdef"><b>Definition:</b> <a href="bmtimer_8h_source.html#l00039">bmtimer.h:39</a></div></div>
<div class="ttc" id="asample11_8cpp_html_af4945f066e89c9bc289f6ce7dc60da4d"><div class="ttname"><a href="sample11_8cpp.html#af4945f066e89c9bc289f6ce7dc60da4d">bv_counted_enumerator</a></div><div class="ttdeci">static void bv_counted_enumerator(const bm::bvector&lt;&gt; &amp;bv)</div><div class="ttdoc">count_to implemented via bm::bvector&lt;&gt;::counted_enumerator</div><div class="ttdef"><b>Definition:</b> <a href="sample11_8cpp_source.html#l00267">sample11.cpp:267</a></div></div>
<div class="ttc" id="astructbm_1_1bv__statistics_html_a7be7eba0cd58b422085b2c8c75c7e188"><div class="ttname"><a href="structbm_1_1bv__statistics.html#a7be7eba0cd58b422085b2c8c75c7e188">bm::bv_statistics::bit_blocks</a></div><div class="ttdeci">size_t bit_blocks</div><div class="ttdoc">Number of bit blocks.</div><div class="ttdef"><b>Definition:</b> <a href="bmfunc_8h_source.html#l00056">bmfunc.h:56</a></div></div>
<div class="ttc" id="abm_8h_html_ad9736d9521d713fa5d48859aa720bfdd"><div class="ttname"><a href="bm_8h.html#ad9736d9521d713fa5d48859aa720bfdd">BM_DECLARE_TEMP_BLOCK</a></div><div class="ttdeci">#define BM_DECLARE_TEMP_BLOCK(x)</div><div class="ttdef"><b>Definition:</b> <a href="bm_8h_source.html#l00047">bm.h:47</a></div></div>
<div class="ttc" id="aclassbm_1_1bvector_html_a99395aaa8ab689455054bda9b261de60"><div class="ttname"><a href="classbm_1_1bvector.html#a99395aaa8ab689455054bda9b261de60">bm::bvector::count_range</a></div><div class="ttdeci">size_type count_range(size_type left, size_type right, const rs_index_type &amp;rs_idx) const BMNOEXCEPT</div><div class="ttdoc">Returns count of 1 bits in the given range [left..right] Uses rank-select index to accelerate the sea...</div><div class="ttdef"><b>Definition:</b> <a href="bm_8h_source.html#l02959">bm.h:2959</a></div></div>
<div class="ttc" id="asample11_8cpp_html_aee1d3b9b188e54f8b1fd35e8362f3b7c"><div class="ttname"><a href="sample11_8cpp.html#aee1d3b9b188e54f8b1fd35e8362f3b7c">bv_count_to_acc</a></div><div class="ttdeci">static void bv_count_to_acc(const bm::bvector&lt;&gt; &amp;bv)</div><div class="ttdoc">count_to() test using pre-calculated rank-select index</div><div class="ttdef"><b>Definition:</b> <a href="sample11_8cpp_source.html#l00178">sample11.cpp:178</a></div></div>
<div class="ttc" id="asample11_8cpp_html_ab25c9ea3f03a5bdc900317e043b8bdaa"><div class="ttname"><a href="sample11_8cpp.html#ab25c9ea3f03a5bdc900317e043b8bdaa">bv_count_test</a></div><div class="ttdeci">static void bv_count_test(const bm::bvector&lt;&gt; &amp;bv)</div><div class="ttdoc">simple population count for the whole vector</div><div class="ttdef"><b>Definition:</b> <a href="sample11_8cpp_source.html#l00113">sample11.cpp:113</a></div></div>
<div class="ttc" id="aclassbm_1_1bvector_1_1counted__enumerator_html_a30a400c9f580df410961d3818fcbb66f"><div class="ttname"><a href="classbm_1_1bvector_1_1counted__enumerator.html#a30a400c9f580df410961d3818fcbb66f">bm::bvector::counted_enumerator::count</a></div><div class="ttdeci">size_type count() const BMNOEXCEPT</div><div class="ttdoc">Number of bits ON starting from the .</div><div class="ttdef"><b>Definition:</b> <a href="bm_8h_source.html#l00757">bm.h:757</a></div></div>
<div class="ttc" id="asample11_8cpp_html_a0bda51ccc776fd4e0af7cf8bec7aeb63"><div class="ttname"><a href="sample11_8cpp.html#a0bda51ccc776fd4e0af7cf8bec7aeb63">vector_max</a></div><div class="ttdeci">unsigned vector_max</div><div class="ttdef"><b>Definition:</b> <a href="sample11_8cpp_source.html#l00047">sample11.cpp:47</a></div></div>
<div class="ttc" id="abmalgo_8h_html"><div class="ttname"><a href="bmalgo_8h.html">bmalgo.h</a></div><div class="ttdoc">Algorithms for bvector&lt;&gt; (main include)</div></div>
<div class="ttc" id="asample11_8cpp_html_aed38ada83d28bf639a9c13a307626b8b"><div class="ttname"><a href="sample11_8cpp.html#aed38ada83d28bf639a9c13a307626b8b">bv_count_and</a></div><div class="ttdeci">static void bv_count_and(const bm::bvector&lt;&gt; &amp;bv)</div><div class="ttdoc">count_range implemented via bm::count_and</div><div class="ttdef"><b>Definition:</b> <a href="sample11_8cpp_source.html#l00237">sample11.cpp:237</a></div></div>
<div class="ttc" id="astructbm_1_1bv__statistics_html_a68582594950732906ddea7a99f8cd0b7"><div class="ttname"><a href="structbm_1_1bv__statistics.html#a68582594950732906ddea7a99f8cd0b7">bm::bv_statistics::gap_blocks</a></div><div class="ttdeci">size_t gap_blocks</div><div class="ttdoc">Number of GAP blocks.</div><div class="ttdef"><b>Definition:</b> <a href="bmfunc_8h_source.html#l00057">bmfunc.h:57</a></div></div>
<div class="ttc" id="asample11_8cpp_html_a4d9edd508c01ff7825dd1dd6c5cb159d"><div class="ttname"><a href="sample11_8cpp.html#a4d9edd508c01ff7825dd1dd6c5cb159d">bv_count_range_acc</a></div><div class="ttdeci">static void bv_count_range_acc(const bm::bvector&lt;&gt; &amp;bv)</div><div class="ttdoc">count_range() test using pre-calculated blocks bit count</div><div class="ttdef"><b>Definition:</b> <a href="sample11_8cpp_source.html#l00152">sample11.cpp:152</a></div></div>
<div class="ttc" id="aclassbm_1_1bvector_html"><div class="ttname"><a href="classbm_1_1bvector.html">bm::bvector&lt;&gt;</a></div></div>
<div class="ttc" id="aclassbm_1_1bvector_html_a52b4259a5cc4ebd8953832c696e24f02"><div class="ttname"><a href="classbm_1_1bvector.html#a52b4259a5cc4ebd8953832c696e24f02">bm::bvector::set</a></div><div class="ttdeci">bvector&lt; Alloc &gt; &amp; set(size_type n, bool val=true)</div><div class="ttdoc">Sets bit n if val is true, clears bit n if val is false.</div><div class="ttdef"><b>Definition:</b> <a href="bm_8h_source.html#l03581">bm.h:3581</a></div></div>
<div class="ttc" id="aclassbm_1_1bvector_html_a3009ba9b116f13f4933a48641f3a695d"><div class="ttname"><a href="classbm_1_1bvector.html#a3009ba9b116f13f4933a48641f3a695d">bm::bvector::count</a></div><div class="ttdeci">size_type count() const BMNOEXCEPT</div><div class="ttdoc">population cout (count of ON bits)</div><div class="ttdef"><b>Definition:</b> <a href="bm_8h_source.html#l02194">bm.h:2194</a></div></div>
<div class="ttc" id="aclassbm_1_1bvector_1_1iterator__base_html_a3f6af7f5b46c0219b28916187d302c43"><div class="ttname"><a href="classbm_1_1bvector_1_1iterator__base.html#a3f6af7f5b46c0219b28916187d302c43">bm::bvector::iterator_base::valid</a></div><div class="ttdeci">bool valid() const BMNOEXCEPT</div><div class="ttdoc">Checks if iterator is still valid. Analog of != 0 comparison for pointers.</div><div class="ttdef"><b>Definition:</b> <a href="bm_8h_source.html#l00280">bm.h:280</a></div></div>
<div class="ttc" id="asample11_8cpp_html_a9b287f91e2adf83c3131895cd6e07195"><div class="ttname"><a href="sample11_8cpp.html#a9b287f91e2adf83c3131895cd6e07195">gen</a></div><div class="ttdeci">std::mt19937 gen(rand_dev())</div></div>
<div class="ttc" id="abmtimer_8h_html"><div class="ttname"><a href="bmtimer_8h.html">bmtimer.h</a></div><div class="ttdoc">Timing utilities for benchmarking (internal)</div></div>
<div class="ttc" id="aclassbm_1_1chrono__taker_html_a9a41e5f2fe48ba472fd77a1dbd86457dad530ca7863ce7e60f4fa221e1dfa64a2"><div class="ttname"><a href="classbm_1_1chrono__taker.html#a9a41e5f2fe48ba472fd77a1dbd86457dad530ca7863ce7e60f4fa221e1dfa64a2">bm::chrono_taker::ct_ops_per_sec</a></div><div class="ttdeci">@ ct_ops_per_sec</div><div class="ttdef"><b>Definition:</b> <a href="bmtimer_8h_source.html#l00059">bmtimer.h:59</a></div></div>
<div class="ttc" id="agroup__bvector_html_ggad0b87b3b7292383a864d27feaf1c9effa7fe09d1d7c62a813db922c396c0cbc9c"><div class="ttname"><a href="group__bvector.html#ggad0b87b3b7292383a864d27feaf1c9effa7fe09d1d7c62a813db922c396c0cbc9c">bm::BM_GAP</a></div><div class="ttdeci">@ BM_GAP</div><div class="ttdoc">GAP compression is ON.</div><div class="ttdef"><b>Definition:</b> <a href="bmconst_8h_source.html#l00144">bmconst.h:144</a></div></div>
<div class="ttc" id="asample11_8cpp_html_a840291bc02cba5474a4cb46a9b9566fe"><div class="ttname"><a href="sample11_8cpp.html#a840291bc02cba5474a4cb46a9b9566fe">main</a></div><div class="ttdeci">int main(void)</div><div class="ttdef"><b>Definition:</b> <a href="sample11_8cpp_source.html#l00292">sample11.cpp:292</a></div></div>
<div class="ttc" id="aclassbm_1_1chrono__taker_html_add1676592117ed0eaa2fa6279a71b46a"><div class="ttname"><a href="classbm_1_1chrono__taker.html#add1676592117ed0eaa2fa6279a71b46a">bm::chrono_taker::duration_map_type</a></div><div class="ttdeci">std::map&lt; std::string, statistics &gt; duration_map_type</div><div class="ttdoc">test name to duration map</div><div class="ttdef"><b>Definition:</b> <a href="bmtimer_8h_source.html#l00065">bmtimer.h:65</a></div></div>
<div class="ttc" id="agroup__setalgo_html_ga5fb1131811b7b834dfc56a3874667a65"><div class="ttname"><a href="group__setalgo.html#ga5fb1131811b7b834dfc56a3874667a65">bm::count_and</a></div><div class="ttdeci">BV::size_type count_and(const BV &amp;bv1, const BV &amp;bv2) BMNOEXCEPT</div><div class="ttdoc">Computes bitcount of AND operation of two bitsets.</div><div class="ttdef"><b>Definition:</b> <a href="bmalgo_8h_source.html#l00049">bmalgo.h:49</a></div></div>
<div class="ttc" id="asample11_8cpp_html_a35469dd094dc5eaf7328f2b36d7c04bd"><div class="ttname"><a href="sample11_8cpp.html#a35469dd094dc5eaf7328f2b36d7c04bd">bv_count_range</a></div><div class="ttdeci">static void bv_count_range(const bm::bvector&lt;&gt; &amp;bv)</div><div class="ttdoc">count_range() test</div><div class="ttdef"><b>Definition:</b> <a href="sample11_8cpp_source.html#l00131">sample11.cpp:131</a></div></div>
<div class="ttc" id="aclassbm_1_1chrono__taker_html_a30b45453d952d14afe56c29087970899"><div class="ttname"><a href="classbm_1_1chrono__taker.html#a30b45453d952d14afe56c29087970899">bm::chrono_taker::print_duration_map</a></div><div class="ttdeci">static void print_duration_map(const duration_map_type &amp;dmap, format fmt=ct_time)</div><div class="ttdef"><b>Definition:</b> <a href="bmtimer_8h_source.html#l00127">bmtimer.h:127</a></div></div>
<div class="ttc" id="aclassbm_1_1bvector_html_adfb63744a9d6039d9e8daa38cf21e3c6"><div class="ttname"><a href="classbm_1_1bvector.html#adfb63744a9d6039d9e8daa38cf21e3c6">bm::bvector::build_rs_index</a></div><div class="ttdeci">void build_rs_index(rs_index_type *rs_idx, bvector&lt; Alloc &gt; *bv_blocks=0) const</div><div class="ttdoc">compute running total of all blocks in bit vector (rank-select index)</div><div class="ttdef"><b>Definition:</b> <a href="bm_8h_source.html#l02290">bm.h:2290</a></div></div>
<div class="ttc" id="aclassbm_1_1bvector_html_a86b939f3aed555dc073e8c26e9efea71"><div class="ttname"><a href="classbm_1_1bvector.html#a86b939f3aed555dc073e8c26e9efea71">bm::bvector::first</a></div><div class="ttdeci">enumerator first() const</div><div class="ttdoc">Returns enumerator pointing on the first non-zero bit.</div><div class="ttdef"><b>Definition:</b> <a href="bm_8h_source.html#l01770">bm.h:1770</a></div></div>
<div class="ttc" id="aclassbm_1_1bvector_html_a405dd9ed048c935c84a5086ec8ba3649"><div class="ttname"><a href="classbm_1_1bvector.html#a405dd9ed048c935c84a5086ec8ba3649">bm::bvector::size_type</a></div><div class="ttdeci">bm::id_t size_type</div><div class="ttdef"><b>Definition:</b> <a href="bm_8h_source.html#l00117">bm.h:117</a></div></div>
<div class="ttc" id="aclassbm_1_1bvector_1_1counted__enumerator_html"><div class="ttname"><a href="classbm_1_1bvector_1_1counted__enumerator.html">bm::bvector::counted_enumerator</a></div><div class="ttdoc">Constant iterator designed to enumerate &quot;ON&quot; bits counted_enumerator keeps bitcount,...</div><div class="ttdef"><b>Definition:</b> <a href="bm_8h_source.html#l00715">bm.h:715</a></div></div>
<div class="ttc" id="asample11_8cpp_html_a4c3aa36d9bdcf58161571ffb69f5211a"><div class="ttname"><a href="sample11_8cpp.html#a4c3aa36d9bdcf58161571ffb69f5211a">bv_count_to_range_acc</a></div><div class="ttdeci">static void bv_count_to_range_acc(const bm::bvector&lt;&gt; &amp;bv)</div><div class="ttdoc">count_range implemented via two count_to() calls using pre-calculated rank-select index</div><div class="ttdef"><b>Definition:</b> <a href="sample11_8cpp_source.html#l00204">sample11.cpp:204</a></div></div>
<div class="ttc" id="abm_8h_html"><div class="ttname"><a href="bm_8h.html">bm.h</a></div><div class="ttdoc">Compressed bit-vector bvector&lt;&gt; container, set algebraic methods, traversal iterators.</div></div>
<div class="ttc" id="aclassbm_1_1bvector_html_a622e6827d799a561e2f0db28f7ac19d2"><div class="ttname"><a href="classbm_1_1bvector.html#a622e6827d799a561e2f0db28f7ac19d2">bm::bvector::optimize</a></div><div class="ttdeci">void optimize(bm::word_t *temp_block=0, optmode opt_mode=opt_compress, statistics *stat=0)</div><div class="ttdoc">Optimize memory bitvector's memory allocation.</div><div class="ttdef"><b>Definition:</b> <a href="bm_8h_source.html#l03071">bm.h:3071</a></div></div>
<div class="ttc" id="asample11_8cpp_html_a8ae0e64af654605402aa541a12f3cb88"><div class="ttname"><a href="sample11_8cpp.html#a8ae0e64af654605402aa541a12f3cb88">rand_dis</a></div><div class="ttdeci">std::uniform_int_distribution rand_dis(1, int(vector_max))</div></div>
<div class="ttc" id="aclassbm_1_1bvector_html_ad3e0e88f17cc86b58e006186955c461b"><div class="ttname"><a href="classbm_1_1bvector.html#ad3e0e88f17cc86b58e006186955c461b">bm::bvector::count_to</a></div><div class="ttdeci">size_type count_to(size_type n, const rs_index_type &amp;rs_idx) const BMNOEXCEPT</div><div class="ttdoc">Returns count of 1 bits (population) in [0..right] range.</div><div class="ttdef"><b>Definition:</b> <a href="bm_8h_source.html#l02533">bm.h:2533</a></div></div>
<div class="ttc" id="astructbm_1_1bvector_1_1statistics_html"><div class="ttname"><a href="structbm_1_1bvector_1_1statistics.html">bm::bvector::statistics</a></div><div class="ttdoc">Statistical information about bitset's memory allocation details.</div><div class="ttdef"><b>Definition:</b> <a href="bm_8h_source.html#l00121">bm.h:121</a></div></div>
<div class="ttc" id="asample11_8cpp_html_a4d7cf7e96896f9aebdd79fed7c8bab7b"><div class="ttname"><a href="sample11_8cpp.html#a4d7cf7e96896f9aebdd79fed7c8bab7b">rand_dev</a></div><div class="ttdeci">std::random_device rand_dev</div><div class="ttdef"><b>Definition:</b> <a href="sample11_8cpp_source.html#l00049">sample11.cpp:49</a></div></div>
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.17
</small></address>
</body>
</html>