|
0 |
<?xml version="1.0" encoding="utf-8"?>
|
|
1 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
|
2 |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
3 |
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
|
4 |
<head>
|
|
5 |
<title>README</title>
|
|
6 |
<!-- 2018-12-20 Do 20:45 -->
|
|
7 |
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
|
8 |
<meta name="generator" content="Org-mode" />
|
|
9 |
<meta name="author" content="Andreas Tille" />
|
|
10 |
<style type="text/css">
|
|
11 |
<!--/*--><![CDATA[/*><!--*/
|
|
12 |
.title { text-align: center; }
|
|
13 |
.todo { font-family: monospace; color: red; }
|
|
14 |
.done { color: green; }
|
|
15 |
.tag { background-color: #eee; font-family: monospace;
|
|
16 |
padding: 2px; font-size: 80%; font-weight: normal; }
|
|
17 |
.timestamp { color: #bebebe; }
|
|
18 |
.timestamp-kwd { color: #5f9ea0; }
|
|
19 |
.right { margin-left: auto; margin-right: 0px; text-align: right; }
|
|
20 |
.left { margin-left: 0px; margin-right: auto; text-align: left; }
|
|
21 |
.center { margin-left: auto; margin-right: auto; text-align: center; }
|
|
22 |
.underline { text-decoration: underline; }
|
|
23 |
#postamble p, #preamble p { font-size: 90%; margin: .2em; }
|
|
24 |
p.verse { margin-left: 3%; }
|
|
25 |
pre {
|
|
26 |
border: 1px solid #ccc;
|
|
27 |
box-shadow: 3px 3px 3px #eee;
|
|
28 |
padding: 8pt;
|
|
29 |
font-family: monospace;
|
|
30 |
overflow: auto;
|
|
31 |
margin: 1.2em;
|
|
32 |
}
|
|
33 |
pre.src {
|
|
34 |
position: relative;
|
|
35 |
overflow: visible;
|
|
36 |
padding-top: 1.2em;
|
|
37 |
}
|
|
38 |
pre.src:before {
|
|
39 |
display: none;
|
|
40 |
position: absolute;
|
|
41 |
background-color: white;
|
|
42 |
top: -10px;
|
|
43 |
right: 10px;
|
|
44 |
padding: 3px;
|
|
45 |
border: 1px solid black;
|
|
46 |
}
|
|
47 |
pre.src:hover:before { display: inline;}
|
|
48 |
pre.src-sh:before { content: 'sh'; }
|
|
49 |
pre.src-bash:before { content: 'sh'; }
|
|
50 |
pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
|
|
51 |
pre.src-R:before { content: 'R'; }
|
|
52 |
pre.src-perl:before { content: 'Perl'; }
|
|
53 |
pre.src-java:before { content: 'Java'; }
|
|
54 |
pre.src-sql:before { content: 'SQL'; }
|
|
55 |
|
|
56 |
table { border-collapse:collapse; }
|
|
57 |
caption.t-above { caption-side: top; }
|
|
58 |
caption.t-bottom { caption-side: bottom; }
|
|
59 |
td, th { vertical-align:top; }
|
|
60 |
th.right { text-align: center; }
|
|
61 |
th.left { text-align: center; }
|
|
62 |
th.center { text-align: center; }
|
|
63 |
td.right { text-align: right; }
|
|
64 |
td.left { text-align: left; }
|
|
65 |
td.center { text-align: center; }
|
|
66 |
dt { font-weight: bold; }
|
|
67 |
.footpara:nth-child(2) { display: inline; }
|
|
68 |
.footpara { display: block; }
|
|
69 |
.footdef { margin-bottom: 1em; }
|
|
70 |
.figure { padding: 1em; }
|
|
71 |
.figure p { text-align: center; }
|
|
72 |
.inlinetask {
|
|
73 |
padding: 10px;
|
|
74 |
border: 2px solid gray;
|
|
75 |
margin: 10px;
|
|
76 |
background: #ffffcc;
|
|
77 |
}
|
|
78 |
#org-div-home-and-up
|
|
79 |
{ text-align: right; font-size: 70%; white-space: nowrap; }
|
|
80 |
textarea { overflow-x: auto; }
|
|
81 |
.linenr { font-size: smaller }
|
|
82 |
.code-highlighted { background-color: #ffff00; }
|
|
83 |
.org-info-js_info-navigation { border-style: none; }
|
|
84 |
#org-info-js_console-label
|
|
85 |
{ font-size: 10px; font-weight: bold; white-space: nowrap; }
|
|
86 |
.org-info-js_search-highlight
|
|
87 |
{ background-color: #ffff00; color: #000000; font-weight: bold; }
|
|
88 |
/*]]>*/-->
|
|
89 |
</style>
|
|
90 |
<script type="text/javascript">
|
|
91 |
/*
|
|
92 |
@licstart The following is the entire license notice for the
|
|
93 |
JavaScript code in this tag.
|
|
94 |
|
|
95 |
Copyright (C) 2012-2013 Free Software Foundation, Inc.
|
|
96 |
|
|
97 |
The JavaScript code in this tag is free software: you can
|
|
98 |
redistribute it and/or modify it under the terms of the GNU
|
|
99 |
General Public License (GNU GPL) as published by the Free Software
|
|
100 |
Foundation, either version 3 of the License, or (at your option)
|
|
101 |
any later version. The code is distributed WITHOUT ANY WARRANTY;
|
|
102 |
without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
103 |
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
|
|
104 |
|
|
105 |
As additional permission under GNU GPL version 3 section 7, you
|
|
106 |
may distribute non-source (e.g., minimized or compacted) forms of
|
|
107 |
that code without the copy of the GNU GPL normally required by
|
|
108 |
section 4, provided you include this license notice and a URL
|
|
109 |
through which recipients can access the Corresponding Source.
|
|
110 |
|
|
111 |
|
|
112 |
@licend The above is the entire license notice
|
|
113 |
for the JavaScript code in this tag.
|
|
114 |
*/
|
|
115 |
<!--/*--><![CDATA[/*><!--*/
|
|
116 |
function CodeHighlightOn(elem, id)
|
|
117 |
{
|
|
118 |
var target = document.getElementById(id);
|
|
119 |
if(null != target) {
|
|
120 |
elem.cacheClassElem = elem.className;
|
|
121 |
elem.cacheClassTarget = target.className;
|
|
122 |
target.className = "code-highlighted";
|
|
123 |
elem.className = "code-highlighted";
|
|
124 |
}
|
|
125 |
}
|
|
126 |
function CodeHighlightOff(elem, id)
|
|
127 |
{
|
|
128 |
var target = document.getElementById(id);
|
|
129 |
if(elem.cacheClassElem)
|
|
130 |
elem.className = elem.cacheClassElem;
|
|
131 |
if(elem.cacheClassTarget)
|
|
132 |
target.className = elem.cacheClassTarget;
|
|
133 |
}
|
|
134 |
/*]]>*///-->
|
|
135 |
</script>
|
|
136 |
</head>
|
|
137 |
<body>
|
|
138 |
<div id="content">
|
|
139 |
<h1 class="title">README</h1>
|
|
140 |
<div id="table-of-contents">
|
|
141 |
<h2>Table of Contents</h2>
|
|
142 |
<div id="text-table-of-contents">
|
|
143 |
<ul>
|
|
144 |
<li><a href="#sec-1">1. C++ Header Tools</a>
|
|
145 |
<ul>
|
|
146 |
<li><a href="#sec-1-1">1.1. Examples</a>
|
|
147 |
<ul>
|
|
148 |
<li><a href="#sec-1-1-1">1.1.1. logger</a></li>
|
|
149 |
<li><a href="#sec-1-1-2">1.1.2. zstr</a></li>
|
|
150 |
<li><a href="#sec-1-1-3">1.1.3. alg</a></li>
|
|
151 |
<li><a href="#sec-1-1-4">1.1.4. logsum</a></li>
|
|
152 |
<li><a href="#sec-1-1-5">1.1.5. pfor</a></li>
|
|
153 |
<li><a href="#sec-1-1-6">1.1.6. tpool</a></li>
|
|
154 |
</ul>
|
|
155 |
</li>
|
|
156 |
<li><a href="#sec-1-2">1.2. License</a></li>
|
|
157 |
</ul>
|
|
158 |
</li>
|
|
159 |
</ul>
|
|
160 |
</div>
|
|
161 |
</div>
|
|
162 |
|
|
163 |
<div id="outline-container-sec-1" class="outline-2">
|
|
164 |
<h2 id="sec-1"><span class="section-number-2">1</span> C++ Header Tools</h2>
|
|
165 |
<div class="outline-text-2" id="text-1">
|
|
166 |
<p>
|
|
167 |
A collection of C++ (mostly, C++11) header-only utility libraries.
|
|
168 |
</p>
|
|
169 |
</div>
|
|
170 |
|
|
171 |
<div id="outline-container-sec-1-1" class="outline-3">
|
|
172 |
<h3 id="sec-1-1"><span class="section-number-3">1.1</span> Examples</h3>
|
|
173 |
<div class="outline-text-3" id="text-1-1">
|
|
174 |
<p>
|
|
175 |
Below you can find code snippets. For full examples and some tests, see the <i>examples</i> folder. In some cases, sample programs are included in the header files themselves, and they can be enabled by specific CPP defines.
|
|
176 |
</p>
|
|
177 |
</div>
|
|
178 |
|
|
179 |
<div id="outline-container-sec-1-1-1" class="outline-4">
|
|
180 |
<h4 id="sec-1-1-1"><span class="section-number-4">1.1.1</span> logger</h4>
|
|
181 |
<div class="outline-text-4" id="text-1-1-1">
|
|
182 |
<p>
|
|
183 |
A thread-safe facility-based logging mechanism.
|
|
184 |
</p>
|
|
185 |
|
|
186 |
<pre class="example">
|
|
187 |
#include "logger.hpp"
|
|
188 |
...
|
|
189 |
logger::Logger::set_default_level("info");
|
|
190 |
int c = 0;
|
|
191 |
LOG(info) << "now you see me; c=" << ++c << "\n";
|
|
192 |
assert(c == 1);
|
|
193 |
LOG(debug) << "now you don't; c=" << ++c << "\n";
|
|
194 |
assert(c == 1);
|
|
195 |
</pre>
|
|
196 |
</div>
|
|
197 |
</div>
|
|
198 |
|
|
199 |
<div id="outline-container-sec-1-1-2" class="outline-4">
|
|
200 |
<h4 id="sec-1-1-2"><span class="section-number-4">1.1.2</span> zstr</h4>
|
|
201 |
<div class="outline-text-4" id="text-1-1-2">
|
|
202 |
<p>
|
|
203 |
A ZLib wrapper.
|
|
204 |
</p>
|
|
205 |
|
|
206 |
<pre class="example">
|
|
207 |
#include "zstr.hpp"
|
|
208 |
...
|
|
209 |
zstr::ifstream(argv[1]) >> i;
|
|
210 |
</pre>
|
|
211 |
</div>
|
|
212 |
</div>
|
|
213 |
|
|
214 |
<div id="outline-container-sec-1-1-3" class="outline-4">
|
|
215 |
<h4 id="sec-1-1-3"><span class="section-number-4">1.1.3</span> alg</h4>
|
|
216 |
<div class="outline-text-4" id="text-1-1-3">
|
|
217 |
<p>
|
|
218 |
Collection of new and extended SL algorithms. Contents:
|
|
219 |
</p>
|
|
220 |
|
|
221 |
<ul class="org-ul">
|
|
222 |
<li><code>for_each[_it][_advance]</code>: Apply functor to elements in range. Options: take iterator pair or range as input; pass iterator instead of element to functor; store next iterator prior to applying functor (e.g. use: remove elements from a list in one pass.)
|
|
223 |
</li>
|
|
224 |
|
|
225 |
<li><code>(min|max|minmax)[_value]_of</code>: Find min and/or max in range. Options: take iterator pair or range as input; optionally use functor to extract key; return iterator(s) or value(s).
|
|
226 |
</li>
|
|
227 |
|
|
228 |
<li><code>mean_stdv_of</code>: Find mean and sample stdv of elements in range. Options: take iterator pair or range as input; optionally use functor to extract key.
|
|
229 |
</li>
|
|
230 |
|
|
231 |
<li><code>(equal|all|any)_of</code>: Check that all elements in a range are equal, or that all are true, or that at least one is true. Options: take iterator pair or range as input; optionally use functor to extract key.
|
|
232 |
</li>
|
|
233 |
|
|
234 |
<li><code>os_join</code>: Use <code>operator <<</code> overloads to print range or to convert it to string using a custom separator. Options: take iterator pair or range as input; optionally use functor to extract key.
|
|
235 |
</li>
|
|
236 |
</ul>
|
|
237 |
|
|
238 |
<pre class="example">
|
|
239 |
#include "alg.hpp"
|
|
240 |
...
|
|
241 |
std::list<int> l{3, 6, 10, 18};
|
|
242 |
// erase elements == 0 mod 5 => l == {3, 6, 18}
|
|
243 |
alg::for_each_it_advance(l, [&l] (std::list<int>::iterator it) { if (*it%5 == 0) l.erase(it); });
|
|
244 |
// iterator to minimum value mod 5 => iterator to 6
|
|
245 |
auto it_min_val_mod_5 = alg::min_of(l, [] (int i) { return i%5; });
|
|
246 |
// all equal mod 3 => true
|
|
247 |
bool equal_mod_3 = alg::equal_of(l, [] (int i) { return i%3; });
|
|
248 |
// to ostream => "l: 3, 6, 18"
|
|
249 |
std::cout << "l: " << alg::os_join(l, ", ") << std::endl;
|
|
250 |
</pre>
|
|
251 |
</div>
|
|
252 |
</div>
|
|
253 |
|
|
254 |
<div id="outline-container-sec-1-1-4" class="outline-4">
|
|
255 |
<h4 id="sec-1-1-4"><span class="section-number-4">1.1.4</span> logsum</h4>
|
|
256 |
<div class="outline-text-4" id="text-1-1-4">
|
|
257 |
<p>
|
|
258 |
Floating point additions in logarithmic space using table lookup.
|
|
259 |
</p>
|
|
260 |
|
|
261 |
<p>
|
|
262 |
<b>Note</b>: This library is based on Sean Eddy's code, originall part of HMMER. The version included in here is header-only, and it using implicit table initialization (no need to explicitly call <code>p7_FLogsumInit()</code>).
|
|
263 |
</p>
|
|
264 |
|
|
265 |
<pre class="example">
|
|
266 |
#include "logsum.hpp"
|
|
267 |
...
|
|
268 |
float r = p7_FLogsum(.5, .3); // ~= log(exp(.5) + exp(.3))
|
|
269 |
</pre>
|
|
270 |
</div>
|
|
271 |
</div>
|
|
272 |
|
|
273 |
<div id="outline-container-sec-1-1-5" class="outline-4">
|
|
274 |
<h4 id="sec-1-1-5"><span class="section-number-4">1.1.5</span> pfor</h4>
|
|
275 |
<div class="outline-text-4" id="text-1-1-5">
|
|
276 |
<p>
|
|
277 |
A C++11-based parallel for, with optional output sorting.
|
|
278 |
</p>
|
|
279 |
|
|
280 |
<pre class="example">
|
|
281 |
#include "pfor.hpp"
|
|
282 |
...
|
|
283 |
std::vector< unsigned > v(1000);
|
|
284 |
unsigned crt_idx = 0;
|
|
285 |
pfor::pfor< unsigned >(
|
|
286 |
4, // num_threads
|
|
287 |
10, // chunk_size
|
|
288 |
[&] (unsigned& i) // get_item
|
|
289 |
{
|
|
290 |
if (crt_idx >= v.size()) return false;
|
|
291 |
i = crt_idx++; return true;
|
|
292 |
},
|
|
293 |
[&] (unsigned& i) // process_item
|
|
294 |
{
|
|
295 |
v[i] = i*i;
|
|
296 |
});
|
|
297 |
</pre>
|
|
298 |
</div>
|
|
299 |
</div>
|
|
300 |
|
|
301 |
<div id="outline-container-sec-1-1-6" class="outline-4">
|
|
302 |
<h4 id="sec-1-1-6"><span class="section-number-4">1.1.6</span> tpool</h4>
|
|
303 |
<div class="outline-text-4" id="text-1-1-6">
|
|
304 |
<p>
|
|
305 |
A C++11-based thread pool.
|
|
306 |
</p>
|
|
307 |
|
|
308 |
<pre class="example">
|
|
309 |
#include "tpool.hpp"
|
|
310 |
...
|
|
311 |
void some_work(unsigned tid, unsigned i);
|
|
312 |
...
|
|
313 |
// create a pool of 4 worker threads
|
|
314 |
tpool::tpool p(4);
|
|
315 |
// perform 10 rounds of work
|
|
316 |
for (int unsigned = 0; round < 10; ++round)
|
|
317 |
{
|
|
318 |
// in each round, work on n items
|
|
319 |
for (unsigned i = 0; i < n; i += 2)
|
|
320 |
{
|
|
321 |
p.add_job(std::bind(some_work, std::placeholders::_1, i));
|
|
322 |
// Note: the lambda must capture i by value, not by reference
|
|
323 |
p.add_job([&,i] (unsigned tid) { some_work(tid, i + 1); });
|
|
324 |
}
|
|
325 |
p.wait_jobs();
|
|
326 |
}
|
|
327 |
</pre>
|
|
328 |
</div>
|
|
329 |
</div>
|
|
330 |
</div>
|
|
331 |
|
|
332 |
<div id="outline-container-sec-1-2" class="outline-3">
|
|
333 |
<h3 id="sec-1-2"><span class="section-number-3">1.2</span> License</h3>
|
|
334 |
<div class="outline-text-3" id="text-1-2">
|
|
335 |
<p>
|
|
336 |
<i>MIT License</i>.
|
|
337 |
</p>
|
|
338 |
</div>
|
|
339 |
</div>
|
|
340 |
</div>
|
|
341 |
</div>
|
|
342 |
<div id="postamble" class="status">
|
|
343 |
<p class="author">Author: Andreas Tille</p>
|
|
344 |
<p class="date">Created: 2018-12-20 Do 20:45</p>
|
|
345 |
<p class="creator"><a href="http://www.gnu.org/software/emacs/">Emacs</a> 25.2.2 (<a href="http://orgmode.org">Org</a> mode 8.2.10)</p>
|
|
346 |
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
|
|
347 |
</div>
|
|
348 |
</body>
|
|
349 |
</html>
|