File: svsample01_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 (157 lines) | stat: -rwxr-xr-x 13,949 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
<!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++: svsample01.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">svsample01.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<p>Example of how to use bm::sparse_vector&lt;&gt; template class to set values</p><dl class="section see"><dt>See also</dt><dd><a class="el" href="classbm_1_1sparse__vector.html#ae7a505562b0f056868aa4b11864eae55" title="Import list of elements from a C-style array.">bm::sparse_vector&lt;&gt;::import</a> </dd>
<dd>
<a class="el" href="classbm_1_1sparse__vector.html#a13e498908f6a3c2361d451a97f50b5ed" title="access specified element with bounds checking">bm::sparse_vector&lt;&gt;::at</a> </dd>
<dd>
<a class="el" href="classbm_1_1sparse__vector.html#af9f218aa3af25cdfc9088cc0affdaa8f" title="run memory optimization for all vector plains">bm::sparse_vector&lt;&gt;::optimize</a> </dd>
<dd>
<a class="el" href="classbm_1_1sparse__vector.html#a468ddeec517a36a4a9333008703acfab" title="return size of the vector">bm::sparse_vector&lt;&gt;::size</a></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 svsample01.cpp</span></div>
<div class="line"><span class="comment">  Example of how to use bm::sparse_vector&lt;&gt; template class to set values</span></div>
<div class="line"><span class="comment"> </span></div>
<div class="line"><span class="comment">  \sa bm::sparse_vector&lt;&gt;::import</span></div>
<div class="line"><span class="comment">  \sa bm::sparse_vector&lt;&gt;::at</span></div>
<div class="line"><span class="comment">  \sa bm::sparse_vector&lt;&gt;::optimize</span></div>
<div class="line"><span class="comment">  \sa bm::sparse_vector&lt;&gt;::size</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 svsample01.cpp</span></div>
<div class="line"><span class="comment">    \brief Example: sparse_vector&lt;&gt; container set values</span></div>
<div class="line"><span class="comment">*/</span></div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#include &lt;iostream&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="bmsparsevec_8h.html">bmsparsevec.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="keywordtype">int</span> <a name="a0"></a><a class="code" href="svsample01_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 name="_a1"></a><a class="code" href="classbm_1_1sparse__vector.html">bm::sparse_vector&lt;unsigned, bm::bvector&lt;&gt;</a> &gt; sv1;</div>
<div class="line">        </div>
<div class="line">        <span class="keywordtype">unsigned</span> arr[3] = {1,2,3};</div>
<div class="line">        sv1.<a name="a2"></a><a class="code" href="classbm_1_1sparse__vector.html#ae7a505562b0f056868aa4b11864eae55">import</a>(arr, 3); <span class="comment">// import from a C-style array (fastest way to populate)</span></div>
<div class="line"> </div>
<div class="line">        <span class="comment">// optimize memory allocation of sparse vector</span></div>
<div class="line">        {</div>
<div class="line">            <a name="a3"></a><a class="code" href="bm_8h.html#ad9736d9521d713fa5d48859aa720bfdd">BM_DECLARE_TEMP_BLOCK</a>(tb)</div>
<div class="line">            sv1.<a name="a4"></a><a class="code" href="classbm_1_1sparse__vector.html#af9f218aa3af25cdfc9088cc0affdaa8f">optimize</a>(tb);</div>
<div class="line">        }</div>
<div class="line">        </div>
<div class="line">        cout &lt;&lt; <span class="stringliteral">&quot;sv1.size() = &quot;</span> &lt;&lt; sv1.<a name="a5"></a><a class="code" href="classbm_1_1sparse__vector.html#a468ddeec517a36a4a9333008703acfab">size</a>() &lt;&lt; endl;</div>
<div class="line">        cout &lt;&lt; <span class="stringliteral">&quot;sv[]:&quot;</span>;</div>
<div class="line">        </div>
<div class="line">        <span class="comment">// print the vector elements using direct access operator</span></div>
<div class="line">        <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0; i &lt; sv1.<a class="code" href="classbm_1_1sparse__vector.html#a468ddeec517a36a4a9333008703acfab">size</a>(); ++i)</div>
<div class="line">        {</div>
<div class="line">            cout &lt;&lt; sv1.<a name="a6"></a><a class="code" href="classbm_1_1sparse__vector.html#a13e498908f6a3c2361d451a97f50b5ed">at</a>(i) &lt;&lt; <span class="stringliteral">&quot;,&quot;</span>;</div>
<div class="line">        }</div>
<div class="line">        cout &lt;&lt; endl;</div>
<div class="line"> </div>
<div class="line">        <span class="comment">// add more at the end</span></div>
<div class="line">        <span class="keywordtype">unsigned</span> arr2[5] = {10, 20, 30, 40, 50};</div>
<div class="line">        sv1.<a class="code" href="classbm_1_1sparse__vector.html#ae7a505562b0f056868aa4b11864eae55">import</a>(arr2, 5, sv1.<a class="code" href="classbm_1_1sparse__vector.html#a468ddeec517a36a4a9333008703acfab">size</a>());</div>
<div class="line">        </div>
<div class="line">        cout &lt;&lt; <span class="stringliteral">&quot;sv1.size() = &quot;</span> &lt;&lt; sv1.<a class="code" href="classbm_1_1sparse__vector.html#a468ddeec517a36a4a9333008703acfab">size</a>() &lt;&lt; endl;</div>
<div class="line">        cout &lt;&lt; <span class="stringliteral">&quot;sv[]:&quot;</span>;</div>
<div class="line">        <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0; i &lt; sv1.<a class="code" href="classbm_1_1sparse__vector.html#a468ddeec517a36a4a9333008703acfab">size</a>(); ++i)</div>
<div class="line">        {</div>
<div class="line">            cout &lt;&lt; sv1.<a class="code" href="classbm_1_1sparse__vector.html#a13e498908f6a3c2361d451a97f50b5ed">at</a>(i) &lt;&lt; <span class="stringliteral">&quot;,&quot;</span>;</div>
<div class="line">        }</div>
<div class="line">        cout &lt;&lt; endl;</div>
<div class="line"> </div>
<div class="line">        </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"> </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="aclassbm_1_1sparse__vector_html_af9f218aa3af25cdfc9088cc0affdaa8f"><div class="ttname"><a href="classbm_1_1sparse__vector.html#af9f218aa3af25cdfc9088cc0affdaa8f">bm::sparse_vector::optimize</a></div><div class="ttdeci">void optimize(bm::word_t *temp_block=0, typename bvector_type::optmode opt_mode=bvector_type::opt_compress, typename sparse_vector&lt; Val, BV &gt;::statistics *stat=0)</div><div class="ttdoc">run memory optimization for all vector plains</div><div class="ttdef"><b>Definition:</b> <a href="bmsparsevec_8h_source.html#l01728">bmsparsevec.h:1728</a></div></div>
<div class="ttc" id="aclassbm_1_1sparse__vector_html"><div class="ttname"><a href="classbm_1_1sparse__vector.html">bm::sparse_vector</a></div><div class="ttdoc">sparse vector with runtime compression using bit transposition method</div><div class="ttdef"><b>Definition:</b> <a href="bmsparsevec_8h_source.html#l00081">bmsparsevec.h:81</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="abmsparsevec_8h_html"><div class="ttname"><a href="bmsparsevec_8h.html">bmsparsevec.h</a></div><div class="ttdoc">Sparse constainer sparse_vector&lt;&gt; for integer types using bit-transposition transform.</div></div>
<div class="ttc" id="aclassbm_1_1sparse__vector_html_ae7a505562b0f056868aa4b11864eae55"><div class="ttname"><a href="classbm_1_1sparse__vector.html#ae7a505562b0f056868aa4b11864eae55">bm::sparse_vector::import</a></div><div class="ttdeci">void import(const value_type *arr, size_type arr_size, size_type offset=0, bool set_not_null=true)</div><div class="ttdoc">Import list of elements from a C-style array.</div><div class="ttdef"><b>Definition:</b> <a href="bmsparsevec_8h_source.html#l00994">bmsparsevec.h:994</a></div></div>
<div class="ttc" id="aclassbm_1_1sparse__vector_html_a468ddeec517a36a4a9333008703acfab"><div class="ttname"><a href="classbm_1_1sparse__vector.html#a468ddeec517a36a4a9333008703acfab">bm::sparse_vector::size</a></div><div class="ttdeci">size_type size() const BMNOEXCEPT</div><div class="ttdoc">return size of the vector</div><div class="ttdef"><b>Definition:</b> <a href="bmsparsevec_8h_source.html#l00644">bmsparsevec.h:644</a></div></div>
<div class="ttc" id="aclassbm_1_1sparse__vector_html_a13e498908f6a3c2361d451a97f50b5ed"><div class="ttname"><a href="classbm_1_1sparse__vector.html#a13e498908f6a3c2361d451a97f50b5ed">bm::sparse_vector::at</a></div><div class="ttdeci">value_type at(size_type idx) const</div><div class="ttdoc">access specified element with bounds checking</div><div class="ttdef"><b>Definition:</b> <a href="bmsparsevec_8h_source.html#l01434">bmsparsevec.h:1434</a></div></div>
<div class="ttc" id="asvsample01_8cpp_html_a840291bc02cba5474a4cb46a9b9566fe"><div class="ttname"><a href="svsample01_8cpp.html#a840291bc02cba5474a4cb46a9b9566fe">main</a></div><div class="ttdeci">int main(void)</div><div class="ttdef"><b>Definition:</b> <a href="svsample01_8cpp_source.html#l00040">svsample01.cpp:40</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>
<!-- 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>