spinsort.qbk 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. [/===========================================================================
  2. Copyright (c) 2017 Steven Ross, Francisco Tapia, Orson Peters
  3. Distributed under the Boost Software License, Version 1.0
  4. See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt
  6. =============================================================================/]
  7. [section:spinsort 2.3.- spinsort]
  8. [section:spinsort_description Description]
  9. [:
  10. [*Spinsort] is a new stable sort algorithm, designed and implemented by Francisco Tapia for the Boost Sort Library.
  11. This algorithm combines several ideas used to optimize other stable sort algorithms.
  12. [*[teletype]
  13. ``
  14. | | | |
  15. Algorithm | Stable | Additional Memory | Best, average, and worst case |
  16. ------------+---------+-------------------+--------------------------------+
  17. spinsort | Yes | N / 2 | N, NlogN , NlogN |
  18. | | | |
  19. ``
  20. ]
  21. The algorithm is most efficient when the data are nearly sorted. Many times the new elements are inserted at the end
  22. of the sorted elements, or some elements are modified, breaking the order of the elements. In these cases, spinsort
  23. is very fast.
  24. ]
  25. [endsect] [/section:spinsort_description Description]
  26. [section:spinsort_benchmark Benchmark]
  27. [:
  28. The benchmark with 100000000 64 bits integers, comparing with the std::stable_sort of the GCC 6.3 compiler shows the mentioned characteristics, running on a Intel i7-5820K CPU @ 3.30GH .
  29. [*[teletype]
  30. ``
  31. Data |std::stable_sort | spin_sort |
  32. -------------------------------+-----------------+--------------+
  33. random | 8.62 | 9.73 |
  34. | | |
  35. sorted | 4.88 | 0.06 |
  36. sorted + 0.1% end | 4.92 | 0.41 |
  37. sorted + 1% end | 4.97 | 0.55 |
  38. sorted + 10% end | 5.73 | 1.32 |
  39. | | |
  40. sorted + 0.1% middle | 6.58 | 1.89 |
  41. sorted + 1% middle | 7.06 | 2.12 |
  42. sorted + 10% middle | 9.56 | 4.02 |
  43. | | |
  44. reverse sorted | 0.13 | 0.14 |
  45. reverse sorted + 0.1% end | 5.22 | 0.52 |
  46. reverse sorted + 1% end | 5.29 | 0.66 |
  47. reverse sorted + 10% end | 6.03 | 1.45 |
  48. | | |
  49. reverse sorted + 0.1% middle | 6.52 | 1.89 |
  50. reverse sorted + 1% middle | 7.09 | 2.12 |
  51. reverse sorted + 10% middle | 9.46 | 4.02 |
  52. | | |
  53. -------------------------------+-----------------+--------------+
  54. ``
  55. ]
  56. ]
  57. [endsect] [/section:spinsort_benchmark Benchmark]
  58. [section:spinsort_programming Programming]
  59. [:
  60. You only need to include the file boost/sort/sort.hpp to use spinsort.
  61. The spinsort function is in the namespace boost::sort
  62. [c++]
  63. ``
  64. #include <boost/sort/sort.hpp>
  65. template <class iter_t, typename compare>
  66. void spinsort (iter_t first, iter_t last, compare comp = compare());
  67. ``
  68. This algorithm uses a [*comparison object], in the same way as the standard library sort
  69. algorithms. If you don't define it, the comparison object defaults to std::less, which uses
  70. the < operator internally for comparisons.
  71. This algorithm is [*exception safe], meaning that, the exceptions generated by the algorithm
  72. guarantee the integrity of the objects to sort, but not their relative order. If the exception
  73. is generated inside the objects (in the move or copy constructors) the results are undefined.
  74. ]
  75. [endsect] [/section:spinsort_programming Programming]
  76. [endsect]