File size: 4,103 Bytes
9375c9a |
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 |
<html><!-- Created using the cpp_pretty_printer from the dlib C++ library. See http://dlib.net for updates. --><head><title>dlib C++ Library - array_tools.h</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2013 Davis E. King ([email protected])
</font><font color='#009900'>// License: Boost Software License See LICENSE.txt for the full license.
</font><font color='#0000FF'>#ifndef</font> DLIB_ARRAY_tOOLS_H_
<font color='#0000FF'>#define</font> DLIB_ARRAY_tOOLS_H_
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../assert.h.html'>../assert.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='array_tools_abstract.h.html'>array_tools_abstract.h</a>"
<font color='#0000FF'>namespace</font> dlib
<b>{</b>
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> T<font color='#5555FF'>></font>
<font color='#0000FF'><u>void</u></font> <b><a name='split_array'></a>split_array</b> <font face='Lucida Console'>(</font>
T<font color='#5555FF'>&</font> a,
T<font color='#5555FF'>&</font> b,
<font color='#0000FF'><u>double</u></font> frac
<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#009900'>// make sure requires clause is not broken
</font> <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font><font color='#979000'>0</font> <font color='#5555FF'><</font><font color='#5555FF'>=</font> frac <font color='#5555FF'>&</font><font color='#5555FF'>&</font> frac <font color='#5555FF'><</font><font color='#5555FF'>=</font> <font color='#979000'>1</font>,
"<font color='#CC0000'>\t void split_array()</font>"
<font color='#5555FF'><</font><font color='#5555FF'><</font> "<font color='#CC0000'>\n\t frac must be between 0 and 1.</font>"
<font color='#5555FF'><</font><font color='#5555FF'><</font> "<font color='#CC0000'>\n\t frac: </font>" <font color='#5555FF'><</font><font color='#5555FF'><</font> frac
<font face='Lucida Console'>)</font>;
<font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> asize <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'><</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>></font><font face='Lucida Console'>(</font>a.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>frac<font face='Lucida Console'>)</font>;
<font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> bsize <font color='#5555FF'>=</font> a.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>asize;
b.<font color='#BB00BB'>resize</font><font face='Lucida Console'>(</font>bsize<font face='Lucida Console'>)</font>;
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'><</font> b.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>swap</font><font face='Lucida Console'>(</font>b[i], a[i<font color='#5555FF'>+</font>asize]<font face='Lucida Console'>)</font>;
<b>}</b>
a.<font color='#BB00BB'>resize</font><font face='Lucida Console'>(</font>asize<font face='Lucida Console'>)</font>;
<b>}</b>
<b>}</b>
<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_ARRAY_tOOLS_H_
</font>
</pre></body></html> |