|
ADS
Algorithms and Data Structures
|
Sorting networks, beyond the book: sequences of comparators \( ( i , j ) \), \( i \ne j \), each putting the smaller of \( A[ i ] \) and \( A[ j ] \) in \( A[ i ] \), fixed in advance whatever the input, so that the comparators of a round touch disjoint places and run in parallel (in hardware, on SIMD lanes, on a GPU): More...
#include "ADS/Contract.h"#include "ADS/sort/Sorted.h"#include <algorithm>#include <bit>#include <cstddef>#include <functional>#include <utility>#include <vector>#include "ADS/sort/impl/SortingNetworks.tpp"Go to the source code of this file.
Namespaces | |
| namespace | ADS |
Typedefs | |
| using | ADS::Comparator = std::pair< std::size_t , std::size_t > |
| a comparator \( ( i , j ) \) of a network: the smaller of \( A[ i ] \) and \( A[ j ] \) goes to \( A[ i ] \) | |
Functions | |
| std::vector< Comparator > | ADS::mergeExchangeNetwork (std::size_t n) |
| the merge exchange of Batcher for \( n \) items | |
| std::vector< Comparator > | ADS::bitonicNetwork (std::size_t n) |
| the bitonic sorter for \( n \) items | |
| template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>> | |
| void | ADS::applyNetwork (Store &&A, const std::vector< Comparator > &N, C less=C()) |
| the comparators of \( N \) applied to \( A \) in their order | |
| template<class T, class C = std::less<>> | |
| void | ADS::applyNetwork (std::vector< T > &A, const std::vector< Comparator > &N, C less=C()) |
| applyNetwork() above on a vector | |
| template<SortRange R, class... P> requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { applyNetwork( v , std::forward< P >( p )... ); } | |
| decltype(auto) | ADS::applyNetwork (R &&A, P &&... p) |
| applyNetwork() on the range \( A \) [see SortRange], the other arguments as for a vector, in place: on the span of its items if \( A \) is contiguous, on its view otherwise, since the sort reads the items by their ranks only | |
Sorting networks, beyond the book: sequences of comparators \( ( i , j ) \), \( i \ne j \), each putting the smaller of \( A[ i ] \) and \( A[ j ] \) in \( A[ i ] \), fixed in advance whatever the input, so that the comparators of a round touch disjoint places and run in parallel (in hardware, on SIMD lanes, on a GPU):
The contracts [see Contract.h]: the comparators of a network join two distinct places within \( n \), a bitonic network needs \( n \) a power of 2, and applyNetwork() a vector of at least \( n \) items. The functions are defined in SortingNetworks.tpp.