1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Function template integer_sort</title> 5<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../../../index.html" title="Boost.Sort"> 8<link rel="up" href="../../../header/boost/sort/spreadsort/integer_sort_hpp.html" title="Header <boost/sort/spreadsort/integer_sort.hpp>"> 9<link rel="prev" href="integer__idm45878543954640.html" title="Function template integer_sort"> 10<link rel="next" href="integer__idm45878543906608.html" title="Function template integer_sort"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td> 15<td align="center"><a href="../../../../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="integer__idm45878543954640.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../../header/boost/sort/spreadsort/integer_sort_hpp.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="integer__idm45878543906608.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="refentry"> 26<a name="boost.sort.spreadsort.integer__idm45878543931680"></a><div class="titlepage"></div> 27<div class="refnamediv"> 28<h2><span class="refentrytitle">Function template integer_sort</span></h2> 29<p>boost::sort::spreadsort::integer_sort — Integer sort algorithm using random access iterators with just right-shift functor. (All variants fall back to <code class="computeroutput">boost::sort::pdqsort</code> if the data size is too small, < <code class="computeroutput">detail::min_sort_size</code>). </p> 30</div> 31<h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2> 32<div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: <<a class="link" href="../../../header/boost/sort/spreadsort/integer_sort_hpp.html" title="Header <boost/sort/spreadsort/integer_sort.hpp>">boost/sort/spreadsort/integer_sort.hpp</a>> 33 34</span> 35<span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> RandomAccessIter<span class="special">,</span> <span class="keyword">typename</span> Right_shift<span class="special">></span> 36 <span class="keyword">void</span> <span class="identifier">integer_sort</span><span class="special">(</span><span class="identifier">RandomAccessIter</span> first<span class="special">,</span> <span class="identifier">RandomAccessIter</span> last<span class="special">,</span> 37 <span class="identifier">Right_shift</span> shift<span class="special">)</span><span class="special">;</span></pre></div> 38<div class="refsect1"> 39<a name="idm45477845328160"></a><h2>Description</h2> 40<p><code class="computeroutput">integer_sort</code> is a fast templated in-place hybrid radix/comparison algorithm, which in testing tends to be roughly 50% to 2X faster than <code class="computeroutput">std::sort</code> for large tests (>=100kB).<br> 41 </p> 42<p><b>Performance: </b>Worst-case performance is <span class="emphasis"><em> O(N * (lg(range)/s + s)) </em></span>, so <code class="computeroutput">integer_sort</code> is asymptotically faster than pure comparison-based algorithms. <code class="computeroutput">s</code> is <code class="computeroutput">max_splits</code>, which defaults to 11, so its worst-case with default settings for 32-bit integers is <span class="emphasis"><em> O(N * ((32/11) </em></span> slow radix-based iterations fast comparison-based iterations).<br> 43<br> 44Some performance plots of runtime vs. n and log(range) are provided:<br> 45 <a href="../../../../../doc/graph/windows_integer_sort.htm" target="_top">windows_integer_sort</a><br> 46 <a href="../../../../../doc/graph/osx_integer_sort.htm" target="_top">osx_integer_sort</a></p> 47<p> 48 49 50 51 52 53 54</p> 55<div class="warning"><table border="0" summary="Warning"> 56<tr> 57<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../../../doc/src/images/warning.png"></td> 58<th align="left">Warning</th> 59</tr> 60<tr><td align="left" valign="top"><p>Throwing an exception may cause data loss. This will also throw if a small vector resize throws, in which case there will be no data loss. </p></td></tr> 61</table></div> 62<p> 63</p> 64<div class="warning"><table border="0" summary="Warning"> 65<tr> 66<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../../../doc/src/images/warning.png"></td> 67<th align="left">Warning</th> 68</tr> 69<tr><td align="left" valign="top"><p>Invalid arguments cause undefined behaviour. </p></td></tr> 70</table></div> 71<p> 72</p> 73<div class="note"><table border="0" summary="Note"> 74<tr> 75<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td> 76<th align="left">Note</th> 77</tr> 78<tr><td align="left" valign="top"><p><code class="computeroutput">spreadsort</code> function provides a wrapper that calls the fastest sorting algorithm available for a data type, enabling faster generic-programming.</p></td></tr> 79</table></div> 80<p> 81</p> 82<p>The lesser of <span class="emphasis"><em> O(N*log(N)) </em></span> comparisons and <span class="emphasis"><em> O(N*log(K/S + S)) </em></span>operations worst-case, where: </p> 83<p> 84 85</p> 86<p>* N is <code class="computeroutput">last</code> - <code class="computeroutput">first</code>, </p> 87<p> 88 89</p> 90<p>* K is the log of the range in bits (32 for 32-bit integers using their full range), </p> 91<p> 92 93</p> 94<p>* S is a constant called max_splits, defaulting to 11 (except for strings where it is the log of the character size). </p> 95<p> 96 97</p> 98<div class="variablelist"><table border="0" class="variablelist compact"> 99<colgroup> 100<col align="left" valign="top"> 101<col> 102</colgroup> 103<tbody> 104<tr> 105<td><p><span class="term">Parameters:</span></p></td> 106<td><div class="variablelist"><table border="0" class="variablelist compact"> 107<colgroup> 108<col align="left" valign="top"> 109<col> 110</colgroup> 111<tbody> 112<tr> 113<td><p><span class="term"><code class="computeroutput">first</code></span></p></td> 114<td><p>Iterator pointer to first element. </p></td> 115</tr> 116<tr> 117<td><p><span class="term"><code class="computeroutput">last</code></span></p></td> 118<td><p>Iterator pointing to one beyond the end of data. </p></td> 119</tr> 120<tr> 121<td><p><span class="term"><code class="computeroutput">shift</code></span></p></td> 122<td><p>A functor that returns the result of shifting the value_type right a specified number of bits.</p></td> 123</tr> 124</tbody> 125</table></div></td> 126</tr> 127<tr> 128<td><p><span class="term">Requires:</span></p></td> 129<td><p>[<code class="computeroutput">first</code>, <code class="computeroutput">last</code>) is a valid range. </p></td> 130</tr> 131<tr> 132<td><p><span class="term">Requires:</span></p></td> 133<td><p><code class="computeroutput">RandomAccessIter</code> <code class="computeroutput">value_type</code> is mutable. </p></td> 134</tr> 135<tr> 136<td><p><span class="term">Requires:</span></p></td> 137<td><p><code class="computeroutput">RandomAccessIter</code> <code class="computeroutput">value_type</code> is <a href="http://en.cppreference.com/w/cpp/concept/LessThanComparable" target="_top">LessThanComparable</a> </p></td> 138</tr> 139<tr> 140<td><p><span class="term">Postconditions:</span></p></td> 141<td><p>The elements in the range [<code class="computeroutput">first</code>, <code class="computeroutput">last</code>) are sorted in ascending order.</p></td> 142</tr> 143<tr> 144<td><p><span class="term">Throws:</span></p></td> 145<td>std::exception Propagates exceptions if any of the element comparisons, the element swaps (or moves), the right shift, subtraction of right-shifted elements, functors, or any operations on iterators throw.</td> 146</tr> 147</tbody> 148</table></div> 149</div> 150</div> 151<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 152<td align="left"></td> 153<td align="right"><div class="copyright-footer">Copyright © 2014-2017 Steven 154 Ross, Francisco Tapia, Orson Peters<p> 155 Distributed under the <a href="http://boost.org/LICENSE_1_0.txt" target="_top">Boost 156 Software License, Version 1.0</a>. 157 </p> 158</div></td> 159</tr></table> 160<hr> 161<div class="spirit-nav"> 162<a accesskey="p" href="integer__idm45878543954640.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../../header/boost/sort/spreadsort/integer_sort_hpp.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="integer__idm45878543906608.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> 163</div> 164</body> 165</html> 166