_2example_2sample_8cpp-example.html 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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">
  36. var 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&#160;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. <!-- iframe showing the search results (closed by default) -->
  71. <div id="MSearchResultsWindow">
  72. <iframe src="javascript:void(0)" frameborder="0"
  73. name="MSearchResults" id="MSearchResults">
  74. </iframe>
  75. </div>
  76. <div class="header">
  77. <div class="headertitle">
  78. <div class="title">/example/sample.cpp</div> </div>
  79. </div><!--header-->
  80. <div class="contents">
  81. <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 (&gt;=100kB).<br />
  82. Worst-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 />
  83. <br />
  84. Some performance plots of runtime vs. n and log(range) are provided:<br />
  85. <a href="../../../graph/windows_integer_sort.htm">windows_integer_sort</a> <br />
  86. <a href="../../../graph/osx_integer_sort.htm">osx_integer_sort</a></p>
  87. <dl class="tparams"><dt>Template Parameters</dt><dd>
  88. <table class="tparams">
  89. <tr><td class="paramname">RandomAccessIter</td><td><a href="http://www.cplusplus.com/reference/iterator/RandomAccessIterator/">Random access iterator</a> </td></tr>
  90. </table>
  91. </dd>
  92. </dl>
  93. <dl class="params"><dt>Parameters</dt><dd>
  94. <table class="params">
  95. <tr><td class="paramdir">[in]</td><td class="paramname">first</td><td>Iterator pointer to first element. </td></tr>
  96. <tr><td class="paramdir">[in]</td><td class="paramname">last</td><td>Iterator pointing to one beyond the end of data.</td></tr>
  97. </table>
  98. </dd>
  99. </dl>
  100. <dl class="section pre"><dt>Precondition</dt><dd>[<code>first</code>, <code>last</code>) is a valid range. </dd>
  101. <dd>
  102. <code>RandomAccessIter</code> <code>value_type</code> is mutable. </dd>
  103. <dd>
  104. <code>RandomAccessIter</code> <code>value_type</code> is <a href="http://en.cppreference.com/w/cpp/concept/LessThanComparable">LessThanComparable</a> </dd>
  105. <dd>
  106. <code>RandomAccessIter</code> <code>value_type</code> supports the <code>operator&gt;&gt;</code>, which returns an integer-type right-shifted a specified number of bits. </dd></dl>
  107. <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>
  108. <dl class="section return"><dt>Returns</dt><dd><code>void</code>.</dd></dl>
  109. <dl class="exception"><dt>Exceptions</dt><dd>
  110. <table class="exception">
  111. <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>
  112. </table>
  113. </dd>
  114. </dl>
  115. <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>
  116. <dd>
  117. Invalid arguments cause undefined behaviour. </dd></dl>
  118. <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>
  119. <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>
  120. <dd>
  121. * N is <code>last</code> - <code>first</code>, </dd>
  122. <dd>
  123. * K is the log of the range in bits (32 for 32-bit integers using their full range), </dd>
  124. <dd>
  125. * S is a constant called max_splits, defaulting to 11 (except for strings where it is the log of the character size).</dd></dl>
  126. <div class="fragment"></div><!-- fragment --> </div><!-- contents -->
  127. <!-- start footer part -->
  128. <hr class="footer"/><address class="footer"><small>
  129. Generated on Tue Jan 6 2015 16:36:35 for Boost.Sort by &#160;<a href="http://www.doxygen.org/index.html">
  130. <img class="footer" src="doxygen.png" alt="doxygen"/>
  131. </a> 1.8.9.1
  132. </small></address>
  133. </body>
  134. </html>