You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- put sorting network implementations in separate files
- put tests for each network implementation in a separate file (allows for faster compilation)
- add githook to automatically create a single header implementation
- update readme
- add .clangformat
The compare and swap operation is the fundamental element a sorting network is composed of. The default implementation works well on scalar types, but if you want to specify a custom implementation (e.g. when hardware intrinsics should be used) you may do this by providing a compare and swap functor to the `sorting_network::operator()` as in following example:
91
91
92
92
```cpp
93
-
#include<sorting_network_cpp/sorting_network.hpp>
93
+
#include<sorting_network_cpp/sorting_network.h>
94
94
95
95
#include<array>
96
96
97
97
voidexample(std::array<float,3>& arr)
98
98
{
99
-
quxflux::sorting_net::sorting_network<3>{}(arr, [](float& a, float& b){
99
+
quxflux::sorting_net::sorting_network<3>{}(arr.begin(), [](float& a, float& b){
100
100
const auto b_cpy = b;
101
101
b = std::max(a, b);
102
102
a = std::min(a, b_cpy);
103
103
});
104
104
}
105
105
```
106
106
107
+
## Single header implementation
108
+
A single header implementation is available which allows experimenting with the sorting networks on [godbolt](https://godbolt.org/z/69WMqMY3c).
109
+
107
110
## Requirements
108
111
A compiler with C++17 support
109
112
@@ -114,6 +117,11 @@ For the bare sorting functionality no dependencies are required. If you want to
114
117
* Depending on the implementation of the comparator the performance advantage of a sorting net compared to a regular sorting algorithm (e.g. `std::sort`) may diminish or even result in worse performance. This can be seen in the [interactive benchmark results overview](https://raw.githack.com/quxflux/sorting_network_cpp/master/doc/data_explorer.htm) for the data type `Vec2i Z-order` which causes in most cases all variants of sorting networks being outperformed by `std::sort` (see [src/benchmark.cpp](src/benchmark.cpp) for the implementation of the aforementioned data type).
115
118
* msvc will fail compiling larger `insertion_sort` networks in certain (unknown) configurations with `fatal error C1202: recursive type or function dependency context too complex`
116
119
120
+
## Development notes
121
+
* A pre-push [githook](https://git-scm.com/docs/githooks) is available in [.githooks](./.githooks/) which will automatically create the single header implementation.
122
+
To enable the hook execute
123
+
`git config --local core.hooksPath .githooks` in the repository directory (python required)
124
+
117
125
## References / Acknowledgements
118
126
* ["A Sorting Problem"](https://dl.acm.org/doi/pdf/10.1145/321119.321126) by Bose et al.
119
127
* ["Sorting networks and their applications"](https://core.ac.uk/download/pdf/192393620.pdf) by Batcher
@@ -125,4 +133,4 @@ For the bare sorting functionality no dependencies are required. If you want to
125
133
* [Chart.js](https://www.chartjs.org/) and [Papa Parse](https://www.papaparse.com/) for the visualization of benchmark results
0 commit comments