14#ifndef TLX_SORT_NETWORKS_BOSE_NELSON_HEADER
15#define TLX_SORT_NETWORKS_BOSE_NELSON_HEADER
24namespace sort_networks {
32namespace bose_nelson {
35template <
typename Iterator>
37 std::less<typename std::iterator_traits<Iterator>::value_type> >;
42template <
typename Iterator,
typename CSwap>
43static inline void merge1_1(Iterator a, Iterator b, CSwap cswap) {
48template <
typename Iterator,
typename CSwap>
49static inline void merge1_2(Iterator a, Iterator b, CSwap cswap) {
55template <
typename Iterator,
typename CSwap>
56static inline void merge2_1(Iterator a, Iterator b, CSwap cswap) {
62template <
typename Iterator,
typename CSwap>
63static inline void merge2_2(Iterator a, Iterator b, CSwap cswap) {
70template <
typename Iterator,
typename CSwap>
71static inline void merge2_3(Iterator a, Iterator b, CSwap cswap) {
78template <
typename Iterator,
typename CSwap>
79static inline void merge3_2(Iterator a, Iterator b, CSwap cswap) {
86template <
typename Iterator,
typename CSwap>
87static inline void merge3_3(Iterator a, Iterator b, CSwap cswap) {
94template <
typename Iterator,
typename CSwap>
95static inline void merge3_4(Iterator a, Iterator b, CSwap cswap) {
102template <
typename Iterator,
typename CSwap>
103static inline void merge4_3(Iterator a, Iterator b, CSwap cswap) {
110template <
typename Iterator,
typename CSwap>
111static inline void merge4_4(Iterator a, Iterator b, CSwap cswap) {
118template <
typename Iterator,
typename CSwap>
119static inline void merge4_5(Iterator a, Iterator b, CSwap cswap) {
126template <
typename Iterator,
typename CSwap>
127static inline void merge5_5(Iterator a, Iterator b, CSwap cswap) {
134template <
typename Iterator,
typename CSwap>
135static inline void merge5_6(Iterator a, Iterator b, CSwap cswap) {
142template <
typename Iterator,
typename CSwap>
143static inline void merge6_6(Iterator a, Iterator b, CSwap cswap) {
150template <
typename Iterator,
typename CSwap>
151static inline void merge6_7(Iterator a, Iterator b, CSwap cswap) {
158template <
typename Iterator,
typename CSwap>
159static inline void merge7_7(Iterator a, Iterator b, CSwap cswap) {
166template <
typename Iterator,
typename CSwap>
167static inline void merge7_8(Iterator a, Iterator b, CSwap cswap) {
174template <
typename Iterator,
typename CSwap>
175static inline void merge8_8(Iterator a, Iterator b, CSwap cswap) {
184template <
typename Iterator,
typename CSwap = DefaultCSwap<Iterator> >
185static inline void sort2(Iterator a, CSwap cswap = CSwap()) {
190template <
typename Iterator,
typename CSwap = DefaultCSwap<Iterator> >
191static inline void sort3(Iterator a, CSwap cswap = CSwap()) {
197template <
typename Iterator,
typename CSwap = DefaultCSwap<Iterator> >
198static void sort4(Iterator a, CSwap cswap = CSwap()) {
205template <
typename Iterator,
typename CSwap = DefaultCSwap<Iterator> >
206static void sort5(Iterator a, CSwap cswap = CSwap()) {
213template <
typename Iterator,
typename CSwap = DefaultCSwap<Iterator> >
214static void sort6(Iterator a, CSwap cswap = CSwap()) {
221template <
typename Iterator,
typename CSwap = DefaultCSwap<Iterator> >
222static void sort7(Iterator a, CSwap cswap = CSwap()) {
229template <
typename Iterator,
typename CSwap = DefaultCSwap<Iterator> >
230static void sort8(Iterator a, CSwap cswap = CSwap()) {
237template <
typename Iterator,
typename CSwap = DefaultCSwap<Iterator> >
238static void sort9(Iterator a, CSwap cswap = CSwap()) {
245template <
typename Iterator,
typename CSwap = DefaultCSwap<Iterator> >
246static void sort10(Iterator a, CSwap cswap = CSwap()) {
253template <
typename Iterator,
typename CSwap = DefaultCSwap<Iterator> >
254static void sort11(Iterator a, CSwap cswap = CSwap()) {
261template <
typename Iterator,
typename CSwap = DefaultCSwap<Iterator> >
262static void sort12(Iterator a, CSwap cswap = CSwap()) {
269template <
typename Iterator,
typename CSwap = DefaultCSwap<Iterator> >
270static void sort13(Iterator a, CSwap cswap = CSwap()) {
277template <
typename Iterator,
typename CSwap = DefaultCSwap<Iterator> >
278static void sort14(Iterator a, CSwap cswap = CSwap()) {
285template <
typename Iterator,
typename CSwap = DefaultCSwap<Iterator> >
286static void sort15(Iterator a, CSwap cswap = CSwap()) {
293template <
typename Iterator,
typename CSwap = DefaultCSwap<Iterator> >
294static void sort16(Iterator a, CSwap cswap = CSwap()) {
304template <
typename Iterator,
typename Comparator =
305 std::less<typename std::iterator_traits<Iterator>::value_type> >
306static void sort(Iterator begin, Iterator end, Comparator cmp = Comparator()) {
309 switch (end - begin) {
Conditional swap implementation used for sorting networks: trivial portable C++ implementation with c...
static void sort5(Iterator a, CSwap cswap=CSwap())
Bose-Nelson sorting network for five elements.
static void sort4(Iterator a, CSwap cswap=CSwap())
Bose-Nelson sorting network for four elements.
static void sort7(Iterator a, CSwap cswap=CSwap())
Bose-Nelson sorting network for seven elements.
static void sort2(Iterator a, CSwap cswap=CSwap())
Bose-Nelson sorting network for two elements.
static void merge1_2(Iterator a, Iterator b, CSwap cswap)
merge network for element arrays length one and two
static void merge5_5(Iterator a, Iterator b, CSwap cswap)
merge network for element arrays length five and five
static void sort13(Iterator a, CSwap cswap=CSwap())
Bose-Nelson sorting network for thirteen elements.
static void merge2_2(Iterator a, Iterator b, CSwap cswap)
merge network for element arrays length two and two
static void merge2_1(Iterator a, Iterator b, CSwap cswap)
merge network for element arrays length two and one
static void sort8(Iterator a, CSwap cswap=CSwap())
Bose-Nelson sorting network for eight elements.
static void merge6_6(Iterator a, Iterator b, CSwap cswap)
merge network for element arrays length six and six
static void merge8_8(Iterator a, Iterator b, CSwap cswap)
merge network for element arrays length eight and eight
static void sort15(Iterator a, CSwap cswap=CSwap())
Bose-Nelson sorting network for fifteen elements.
static void sort9(Iterator a, CSwap cswap=CSwap())
Bose-Nelson sorting network for nine elements.
static void merge6_7(Iterator a, Iterator b, CSwap cswap)
merge network for element arrays length six and seven
static void sort16(Iterator a, CSwap cswap=CSwap())
Bose-Nelson sorting network for sixteen elements.
static void merge2_3(Iterator a, Iterator b, CSwap cswap)
merge network for element arrays length two and three
static void merge4_4(Iterator a, Iterator b, CSwap cswap)
merge network for element arrays length four and four
static void sort12(Iterator a, CSwap cswap=CSwap())
Bose-Nelson sorting network for twelve elements.
static void sort10(Iterator a, CSwap cswap=CSwap())
Bose-Nelson sorting network for ten elements.
static void sort3(Iterator a, CSwap cswap=CSwap())
Bose-Nelson sorting network for three elements.
static void merge3_4(Iterator a, Iterator b, CSwap cswap)
merge network for element arrays length three and four
static void sort14(Iterator a, CSwap cswap=CSwap())
Bose-Nelson sorting network for fourteen elements.
static void merge4_5(Iterator a, Iterator b, CSwap cswap)
merge network for element arrays length four and five
static void sort6(Iterator a, CSwap cswap=CSwap())
Bose-Nelson sorting network for six elements.
static void merge1_1(Iterator a, Iterator b, CSwap cswap)
merge network for element arrays length one and one
static void merge3_2(Iterator a, Iterator b, CSwap cswap)
merge network for element arrays length three and two
static void sort(Iterator begin, Iterator end, Comparator cmp=Comparator())
Call Bose-Network sorting network for up to sixteen elements with given comparison method.
static void sort11(Iterator a, CSwap cswap=CSwap())
Bose-Nelson sorting network for eleven elements.
static void merge7_8(Iterator a, Iterator b, CSwap cswap)
merge network for element arrays length seven and eight
static void merge4_3(Iterator a, Iterator b, CSwap cswap)
merge network for element arrays length four and three
static void merge3_3(Iterator a, Iterator b, CSwap cswap)
merge network for element arrays length three and three
static void merge5_6(Iterator a, Iterator b, CSwap cswap)
merge network for element arrays length five and six
static void merge7_7(Iterator a, Iterator b, CSwap cswap)
merge network for element arrays length seven and seven