Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ee0bf8b
Fix sort.idx line endings
spreadsort Jan 29, 2023
641c2f0
Clarify pdqsort documentation and add to doxygen
spreadsort Jan 30, 2023
6df06af
Mention include requirements
spreadsort Jan 30, 2023
82ef138
Fix overflow issue with signed subtraction in float_sort
spreadsort Apr 20, 2023
0386b32
Apply `use std::swap` idiom for all calls to `std::swap`
melton1968 Jun 6, 2023
c438e4e
Merge pull request #73 from cpp-core/develop
spreadsort Jun 9, 2023
f908029
Markdown conversion for README.md
nigels-com Aug 26, 2023
4967785
Merge pull request #75 from nigels-com/readme
spreadsort Aug 28, 2023
531d497
Add files via upload
fjtapia Aug 29, 2023
0754579
Add files via upload
fjtapia Aug 29, 2023
6465245
Fix typo in error message
nigels-com Sep 5, 2023
bf131a2
Update macOS github workflow for macos-12 (Monterey)
nigels-com Sep 5, 2023
f24f82b
correction of pedantic errors
fjtapia Sep 6, 2023
2930231
correction of errors showed with the pedantic option
fjtapia Sep 6, 2023
27f4a74
Merge pull request #76 from nigels-com/message-typo
spreadsort Sep 6, 2023
e1a2bd2
Merge pull request #77 from nigels-com/macos-12
spreadsort Sep 6, 2023
2fa0aca
Resolve Issue #64 - boost/sort/common/util/insert.hpp need not includ…
nigels-com Sep 10, 2023
de1c07e
Merge pull request #78 from nigels-com/insert-include
spreadsort Sep 10, 2023
11099a2
pdqsort: Resolve MS compiler warnings about assigning size_t to unsig…
Sep 11, 2023
5daa1d4
pdqsort: Resolve MS compiler warnings about assigning size_t to unsig…
Sep 11, 2023
a9e684e
Add files via upload
fjtapia Sep 13, 2023
e5393b7
Add files via upload
fjtapia Sep 13, 2023
9aa7e7d
Merge pull request #79 from nigels-com/pdqsort-ms-warnings
spreadsort Sep 20, 2023
cb7df6b
Merge pull request #81 from boostorg/master
spreadsort Sep 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ jobs:
- name: "TOOLSET=clang CXXSTD=03,11,14,1z Job 2"
buildtype: "boost"
packages: ""
os: "macos-10.15"
os: "macos-12"
cxx: "clang++"
sources: ""
llvm_os: ""
llvm_ver: ""
xcode_version: 11.7
xcode_version: 14.2
toolset: "clang"
cxxstd: "03,11,14,1z"

Expand Down
72 changes: 37 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,79 +1,81 @@
<h1>BOOST SORT</H1>
# BOOST SORT

<H2>Introduction</h2>
## Introduction

The goal of the Boost Sort Library is provide to the users, the most modern and fast sorting algorithms.

This library provides stable and not stable sorting algorithms, in single thread and parallel versions.

These algorithms do not use any other library or utility. The parallel algorithms need a C++11 compliant compiler.

<h2>Single Thread Algorithms</h2>
Detailed [boost API documentation](https://www.boost.org/doc/libs/release/libs/sort/) also available.

## Single Thread Algorithms

| | | | |
Algorithm |Stable | Additional memory |Best, average, and worst case | Comparison method |
------------------|-------|----------------------------|-------------------------------|---------------------|
spreadsort | no | key_length | N, N sqrt(LogN), | Hybrid radix sort |
| | | min(N logN, N key_length) | |
pdqsort | no | Log N | N, N LogN, N LogN | Comparison operator |
spinsort | yes | N / 2 | N, N LogN, N LogN | Comparison operator |
flat_stable_sort | yes |size of the data / 256 + 8K | N, N LogN, N LogN | Comparison operator |
| | | | |

| Algorithm |Stable | Additional memory |Best, average, and worst case | Comparison method |
|-------------------|-------|----------------------------|-------------------------------|---------------------|
| spreadsort | no | key_length | N, N sqrt(LogN), | Hybrid radix sort |
| | | | min(N logN, N key_length) | |
| pdqsort | no | Log N | N, N LogN, N LogN | Comparison operator |
| spinsort | yes | N / 2 | N, N LogN, N LogN | Comparison operator |
| flat_stable_sort | yes |size of the data / 256 + 8K | N, N LogN, N LogN | Comparison operator |

- **spreadsort** is a novel hybrid radix sort algorithm, extremely fast, designed and developed by Steven Ross.

- **pdqsort** is a improvement of the quick sort algorithm, designed and developed by Orson Peters.
- **spreadsort** is a [novel hybrid radix sort algorithm](https://en.wikipedia.org/wiki/Spreadsort), extremely fast, designed and developed by Steven Ross.
[(paper)](doc/papers/original_spreadsort06_2002.pdf)

- **pdqsort** is a [improvement of the quick sort algorithm](https://en.wikipedia.org/wiki/Introsort#pdqsort), designed and developed by Orson Peters.
[(paper)](https://arxiv.org/pdf/2106.05123.pdf)

- **spinsort** is a stable sort, fast with random and with near sorted data, designed and developed by Francisco Tapia.

- **flat_stable_sort** stable sort with a small additional memory (around 1% of the size of the data), provide the 80% - 90% of the speed of spinsort, being fast with random and with near sorted data, designed and developed by Francisco Tapia.
[(paper)](doc/papers/flat_stable_sort_eng.pdf)


<h2>Parallel Algorithms</h2>
## Parallel Algorithms


| | | |
Algorithm |Stable | Additional memory |Best, average, and worst case |
----------------------|-------|------------------------|------------------------------|
block_indirect_sort | no |block_size * num_threads| N, N LogN , N LogN |
sample_sort | yes | N | N, N LogN , N LogN |
parallel_stable_sort | yes | N / 2 | N, N LogN , N LogN |
| | | |
| Algorithm |Stable | Additional memory |Best, average, and worst case |
|-----------------------|-------|------------------------|------------------------------|
| block_indirect_sort | no |block_size * num_threads| N, N LogN , N LogN |
| sample_sort | yes | N | N, N LogN , N LogN |
| parallel_stable_sort | yes | N / 2 | N, N LogN , N LogN |


- **Sample_sort** is a implementation of the [Samplesort algorithm](https://en.wikipedia.org/wiki/Samplesort) done by Francisco Tapia.
- **Sample_sort** is a implementation of the [Samplesort algorithm](https://en.wikipedia.org/wiki/Samplesort) done by Francisco Tapia.

- **Parallel_stable_sort** is based on the samplesort algorithm, but using a half of the memory used by sample_sort, conceived and implemented by Francisco Tapia.

- **Block_indirect_sort** is a novel parallel sort algorithm, very fast, with low additional memory consumption, conceived and implemented by Francisco Tapia.
[(paper)](doc/papers/block_indirect_sort_en.pdf)

The **block_size** is an internal parameter of the algorithm, which in order to achieve the
highest speed, changes according to the size of the objects to sort according to the next table. The strings use a block_size of 128.


| | | | | | | |
object size (bytes) | 1 - 15 | 16 - 31 | 32 - 63 | 64 - 127|128 - 255|256 - 511| 512 - |
--------------------------------|--------|---------|---------|---------|---------|---------|----------|
block_size (number of elements) | 4096 | 2048 | 1024 | 768 | 512 | 256 | 128 |
| | | | | | | |
| object size (bytes) | 1 - 15 | 16 - 31 | 32 - 63 | 64 - 127|128 - 255|256 - 511| 512 - |
|---------------------------------|--------|---------|---------|---------|---------|---------|----------|
| block_size (number of elements) | 4096 | 2048 | 1024 | 768 | 512 | 256 | 128 |


## Installation

<h2>Installation </h2>
- This library is **include only**.
- Don't need to link with any static or dynamic library. Only need a C++11 compiler
- Only need to include the file boost/sort/sort.hpp


<h2>Author and Copyright</h2>
This library is integrated in the [Boost Library](https://boost.org) .
## Author and Copyright

This library is integrated in the [Boost Library](https://boost.org).


Copyright 2017

- [Steven Ross *(spreadsort@gmail.com)* ](mail:spreadsort@gmail.com)
- [Francisco Tapia *(fjtapia@gmail.com)* ](mail:fjtapia@gmail.com)
- [Orson Peters *(orsonpeters@gmail.com)* ](mail:orsonpeters@gmail.com)
- [Steven Ross](mailto:spreadsort@gmail.com)
- [Francisco Tapia](mailto:fjtapia@gmail.com)
- [Orson Peters](mailto:orsonpeters@gmail.com)

Distributed under the [Boost Software License, Version 1.0. ](http://www.boost.org/LICENSE_1_0.txt) (See http://www.boost.org/LICENSE_1_0.txt)
Distributed under the [Boost Software License, Version 1.0](https://www.boost.org/LICENSE_1_0.txt).
1 change: 1 addition & 0 deletions doc/Jamfile.v2
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ doxygen autodoc
:
[ glob $(here)/../include/boost/sort.hpp ]
[ glob $(here)/../include/boost/sort/spreadsort/*.hpp ]
[ glob $(here)/../include/boost/sort/pdqsort/pdqsort.hpp ]
# [ glob $(here)/../include/boost/sort/detail/spreadsort/*.hpp ] # Hide implementation/detail for now.
# but could also include this and switch Boost.Sort C++ reference info to include implementation/detail or not using Doxygen macro DETAIL.
# See http://www.stack.nl/~dimitri/doxygen/manual/commands.html#cmdcond
Expand Down
3 changes: 2 additions & 1 deletion doc/introduction.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ The goal of the Boost Sort Library is provide to the users, the most modern, fas

This library provides stable and unstable sorting algorithms, in single threaded and parallel versions.

These algorithms do not use any other library or utility. The parallel algorithms need a C++11 compliant compiler.
These algorithms do not use any other library or utility, you only need to include boost/sort/sort.hpp
or one of the more specific headers. The parallel algorithms need a C++11 compliant compiler.

[h4[_Single Thread Algorithms]]

Expand Down
3 changes: 2 additions & 1 deletion doc/pdqsort.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ introsort. It is identical in usage to __std_sort.

Pattern-defeating quicksort is available through two calls, __pdqsort and __pdqsort_branchless. Both
have identical guarantees, behavior and overloads as __std_sort, with the exception of the C++17
parallel execution policy argument. Thus you can simply replace a call to __std_sort with __pdqsort,
parallel execution policy argument. Thus you can replace a call to __std_sort with
boost::sort::pdqsort, available from boost/sort/pdqsort/pdqsort.hpp,
it is simply a faster implementation. It is almost always appropriate to simply call __pdqsort and
ignore __pdqsort_branchless.

Expand Down
75 changes: 38 additions & 37 deletions doc/sort.idx
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
# sort.idx for Boost.Sort/Spreadsort Quickbook, Doxygen and Auto-index.

# Note needs more customization to be useful in practice! TODO?

#!debug "\<\w*\>"

# Sort Header files.
#!scan-path "/boost/sort/" ".*\.*pp" true
!scan-path "../include/boost/sort" ".*\.hpp" false
!scan-path "../include/boost/sort/spreadsort" ".*\.hpp" false

# All example source files, assuming no sub-folders.
# sort example files.
!scan-path "../example" ".*\.cpp" true

# Allow alternative spellings colour | color, and plurals etc.
color \<\w*(colour|color)\w*\>
container \<contain\w*\>
data
deque \<deque\w*\>
example \<example\w*\>
font \<font\w*\>
greek
quartile \<quartile\w*\>
histogram
ioflags
origin
outlier
maximum \<max\w*\>
minimum \<min\w*\>
precision
range \<\w*\range\w*\>
scaling \<\w*\scal\w*\>
tick \<\w*\tick\w*\>
title
Unicode \<unicode\w*\>
vector \<\w*\vector\w*\>
# sort.idx for Boost.Sort/Spreadsort Quickbook, Doxygen and Auto-index.

# Note needs more customization to be useful in practice! TODO?

#!debug "\<\w*\>"

# Sort Header files.
#!scan-path "/boost/sort/" ".*\.*pp" true
!scan-path "../include/boost/sort" ".*\.hpp" false
!scan-path "../include/boost/sort/spreadsort" ".*\.hpp" false
!scan-path "../include/boost/sort/pdqsort" ".*\.hpp" false

# All example source files, assuming no sub-folders.
# sort example files.
!scan-path "../example" ".*\.cpp" true

# Allow alternative spellings colour | color, and plurals etc.
color \<\w*(colour|color)\w*\>
container \<contain\w*\>
data
deque \<deque\w*\>
example \<example\w*\>
font \<font\w*\>
greek
quartile \<quartile\w*\>
histogram
ioflags
origin
outlier
maximum \<max\w*\>
minimum \<min\w*\>
precision
range \<\w*\range\w*\>
scaling \<\w*\scal\w*\>
tick \<\w*\tick\w*\>
title
Unicode \<unicode\w*\>
vector \<\w*\vector\w*\>
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ parallel_sort<Block_size, Iter_t, Compare>
::parallel_sort(backbone_t &bkbn, Iter_t first, Iter_t last)
: bk(bkbn), counter(0)
{
using std::swap;
assert((last - first) >= 0);
size_t nelem = size_t(last - first);

Expand All @@ -153,7 +154,7 @@ ::parallel_sort(backbone_t &bkbn, Iter_t first, Iter_t last)
size_t nelem2 = nelem >> 1;
Iter_t it1 = first, it2 = last - 1;
for (size_t i = 0; i < nelem2; ++i)
std::swap(*(it1++), *(it2--));
swap(*(it1++), *(it2--));
return;
};

Expand Down Expand Up @@ -188,6 +189,7 @@ template<uint32_t Block_size, class Iter_t, class Compare>
void parallel_sort<Block_size, Iter_t, Compare>
::divide_sort(Iter_t first, Iter_t last, uint32_t level)
{
using std::swap;
//------------------- check if sort -----------------------------------
bool sorted = true;
for (Iter_t it1 = first, it2 = first + 1;
Expand All @@ -211,14 +213,14 @@ ::divide_sort(Iter_t first, Iter_t last, uint32_t level)

while (c_first < c_last)
{
std::swap(*(c_first++), *(c_last--));
swap(*(c_first++), *(c_last--));
while (bk.cmp(*c_first, val))
++c_first;
while (bk.cmp(val, *c_last))
--c_last;
};

std::swap(*first, *c_last);
swap(*first, *c_last);

// insert the work of the second half in the stack of works
function_divide_sort(c_first, last, level - 1, counter, bk.error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ ::block_indirect_sort(Iter_t first, Iter_t last, Compare cmp, uint32_t nthr)
Iter_t it1 = first, it2 = last - 1;
for (size_t i = 0; i < nelem2; ++i)
{
std::swap(*(it1++), *(it2--));
using std::swap;
swap(*(it1++), *(it2--));
};
return;
};
Expand Down
2 changes: 1 addition & 1 deletion include/boost/sort/common/file_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ inline int fill_vector_uint64(const std::string & filename,
size_t uCount = length / 8;
if (uCount < NElem)
{
throw std::ios_base::failure("incorrect lenght of the file\n");
throw std::ios_base::failure("incorrect length of the file\n");
};
V.clear();
V.reserve(NElem);
Expand Down
Loading