1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2<html xmlns="http://www.w3.org/1999/xhtml"> 3<head> 4<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> 5<meta http-equiv="X-UA-Compatible" content="IE=9"/> 6<meta name="generator" content="Doxygen 1.8.9.1"/> 7<title>Boost.Sort: /example/sample.cpp</title> 8<link href="tabs.css" rel="stylesheet" type="text/css"/> 9<script type="text/javascript" src="jquery.js"></script> 10<script type="text/javascript" src="dynsections.js"></script> 11<link href="search/search.css" rel="stylesheet" type="text/css"/> 12<script type="text/javascript" src="search/searchdata.js"></script> 13<script type="text/javascript" src="search/search.js"></script> 14<script type="text/javascript"> 15 $(document).ready(function() { init_search(); }); 16</script> 17<link href="doxygen.css" rel="stylesheet" type="text/css" /> 18</head> 19<body> 20<div id="top"><!-- do not remove this div, it is closed by doxygen! --> 21<div id="titlearea"> 22<table cellspacing="0" cellpadding="0"> 23 <tbody> 24 <tr style="height: 56px;"> 25 <td style="padding-left: 0.5em;"> 26 <div id="projectname">Boost.Sort 27 </div> 28 </td> 29 </tr> 30 </tbody> 31</table> 32</div> 33<!-- end header part --> 34<!-- Generated by Doxygen 1.8.9.1 --> 35<script type="text/javascript"> 36var searchBox = new SearchBox("searchBox", "search",false,'Search'); 37</script> 38 <div id="navrow1" class="tabs"> 39 <ul class="tablist"> 40 <li><a href="index.html"><span>Main Page</span></a></li> 41 <li><a href="namespaces.html"><span>Namespaces</span></a></li> 42 <li><a href="annotated.html"><span>Classes</span></a></li> 43 <li><a href="files.html"><span>Files</span></a></li> 44 <li><a href="examples.html"><span>Examples</span></a></li> 45 <li> 46 <div id="MSearchBox" class="MSearchBoxInactive"> 47 <span class="left"> 48 <img id="MSearchSelect" src="search/mag_sel.png" 49 onmouseover="return searchBox.OnSearchSelectShow()" 50 onmouseout="return searchBox.OnSearchSelectHide()" 51 alt=""/> 52 <input type="text" id="MSearchField" value="Search" accesskey="S" 53 onfocus="searchBox.OnSearchFieldFocus(true)" 54 onblur="searchBox.OnSearchFieldFocus(false)" 55 onkeyup="searchBox.OnSearchFieldChange(event)"/> 56 </span><span class="right"> 57 <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a> 58 </span> 59 </div> 60 </li> 61 </ul> 62 </div> 63</div><!-- top --> 64<!-- window showing the filter options --> 65<div id="MSearchSelectWindow" 66 onmouseover="return searchBox.OnSearchSelectShow()" 67 onmouseout="return searchBox.OnSearchSelectHide()" 68 onkeydown="return searchBox.OnSearchSelectKey(event)"> 69</div> 70 71<!-- iframe showing the search results (closed by default) --> 72<div id="MSearchResultsWindow"> 73<iframe src="javascript:void(0)" frameborder="0" 74 name="MSearchResults" id="MSearchResults"> 75</iframe> 76</div> 77 78<div class="header"> 79 <div class="headertitle"> 80<div class="title">/example/sample.cpp</div> </div> 81</div><!--header--> 82<div class="contents"> 83<p>Integer sort algorithm using random access iterators. All variants fall back to <code>std::sort</code> if the data is too small.<code>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>std::sort</code> for large tests (>=100kB).<br /> 84Worst-case performance is <em> O(N * (lg(range)/s + s)) </em>, so <code>integer_sort</code> is asymptotically faster than pure comparison-based algorithms. <code>s</code> is <code>max_splits</code>, which defaults to 11, so its worst-case with default settings for 32-bit integers is <em> O(N * ((32/11) </em> slow radix-based iterations fast comparison-based iterations).<br /> 85<br /> 86Some performance plots of runtime vs. n and log(range) are provided:<br /> 87 <a href="../../../graph/windows_integer_sort.htm">windows_integer_sort</a> <br /> 88 <a href="../../../graph/osx_integer_sort.htm">osx_integer_sort</a></p> 89<dl class="tparams"><dt>Template Parameters</dt><dd> 90 <table class="tparams"> 91 <tr><td class="paramname">RandomAccessIter</td><td><a href="http://www.cplusplus.com/reference/iterator/RandomAccessIterator/">Random access iterator</a> </td></tr> 92 </table> 93 </dd> 94</dl> 95<dl class="params"><dt>Parameters</dt><dd> 96 <table class="params"> 97 <tr><td class="paramdir">[in]</td><td class="paramname">first</td><td>Iterator pointer to first element. </td></tr> 98 <tr><td class="paramdir">[in]</td><td class="paramname">last</td><td>Iterator pointing to one beyond the end of data.</td></tr> 99 </table> 100 </dd> 101</dl> 102<dl class="section pre"><dt>Precondition</dt><dd>[<code>first</code>, <code>last</code>) is a valid range. </dd> 103<dd> 104<code>RandomAccessIter</code> <code>value_type</code> is mutable. </dd> 105<dd> 106<code>RandomAccessIter</code> <code>value_type</code> is <a href="http://en.cppreference.com/w/cpp/concept/LessThanComparable">LessThanComparable</a> </dd> 107<dd> 108<code>RandomAccessIter</code> <code>value_type</code> supports the <code>operator>></code>, which returns an integer-type right-shifted a specified number of bits. </dd></dl> 109<dl class="section post"><dt>Postcondition</dt><dd>The elements in the range [<code>first</code>, <code>last</code>) are sorted in ascending order.</dd></dl> 110<dl class="section return"><dt>Returns</dt><dd><code>void</code>.</dd></dl> 111<dl class="exception"><dt>Exceptions</dt><dd> 112 <table class="exception"> 113 <tr><td class="paramname">Propagates</td><td>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></tr> 114 </table> 115 </dd> 116</dl> 117<dl class="section warning"><dt>Warning</dt><dd>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. </dd> 118<dd> 119Invalid arguments cause undefined behaviour. </dd></dl> 120<dl class="section note"><dt>Note</dt><dd><code>spreadsort</code> function provides a wrapper that calls the fastest sorting algorithm available for a data type, enabling faster generic-programming.</dd></dl> 121<dl class="section remark"><dt>Remarks</dt><dd>The lesser of <em> O(N*log(N)) </em> comparisons and <em> O(N*log(K/S + S)) </em>operations worst-case, where: </dd> 122<dd> 123* N is <code>last</code> - <code>first</code>, </dd> 124<dd> 125* K is the log of the range in bits (32 for 32-bit integers using their full range), </dd> 126<dd> 127* S is a constant called max_splits, defaulting to 11 (except for strings where it is the log of the character size).</dd></dl> 128<div class="fragment"></div><!-- fragment --> </div><!-- contents --> 129<!-- start footer part --> 130<hr class="footer"/><address class="footer"><small> 131Generated on Tue Jan 6 2015 16:36:35 for Boost.Sort by  <a href="http://www.doxygen.org/index.html"> 132<img class="footer" src="doxygen.png" alt="doxygen"/> 133</a> 1.8.9.1 134</small></address> 135</body> 136</html> 137