tlx
Loading...
Searching...
No Matches
cswap.hpp
Go to the documentation of this file.
1
/*******************************************************************************
2
* tlx/sort/networks/cswap.hpp
3
*
4
* Conditional swap implementation used for sorting networks.
5
*
6
* Part of tlx - http://panthema.net/tlx
7
*
8
* Copyright (C) 2018-2020 Jasper Marianczuk <jasper.marianczuk@gmail.com>
9
* Copyright (C) 2020 Timo Bingmann <tb@panthema.net>
10
*
11
* All rights reserved. Published under the Boost Software License, Version 1.0
12
******************************************************************************/
13
14
#ifndef TLX_SORT_NETWORKS_CSWAP_HEADER
15
#define TLX_SORT_NETWORKS_CSWAP_HEADER
16
17
#include <algorithm>
18
19
namespace
tlx
{
20
21
//! \addtogroup tlx_sort
22
//! \{
23
//! \name Implementations of Sorting Networks
24
//! \{
25
26
//! Implementations of sorting networks for up to sixteen elements.
27
namespace
sort_networks
{
28
29
//! Conditional swap implementation used for sorting networks: trivial portable
30
//! C++ implementation with custom comparison method and std::swap().
31
template
<
typename
Comparator>
32
class
CS_IfSwap
33
{
34
public
:
35
CS_IfSwap
(Comparator cmp) :
cmp_
(cmp) { }
36
37
template
<
typename
Type>
38
inline
void
operator ()
(Type& left, Type& right) {
39
if
(
cmp_
(right, left)) { std::swap(left, right); }
40
}
41
42
protected
:
43
Comparator
cmp_
;
44
};
45
46
/******************************************************************************/
47
48
//! \}
49
//! \}
50
51
}
// namespace sort_networks
52
}
// namespace tlx
53
54
#endif
// !TLX_SORT_NETWORKS_CSWAP_HEADER
55
56
/******************************************************************************/
tlx::sort_networks::CS_IfSwap::operator()
void operator()(Type &left, Type &right)
Definition
cswap.hpp:38
tlx::sort_networks::CS_IfSwap< std::less< typename std::iterator_traits< Iterator >::value_type > >::cmp_
std::less< typename std::iterator_traits< Iterator >::value_type > cmp_
Definition
cswap.hpp:43
tlx::sort_networks::CS_IfSwap::CS_IfSwap
CS_IfSwap(Comparator cmp)
Definition
cswap.hpp:35
tlx::sort_networks
Implementations of sorting networks for up to sixteen elements.
Definition
best.hpp:24
tlx
Definition
exclusive_scan.hpp:17
tlx
sort
networks
cswap.hpp
Generated on Sun Jan 19 2025 00:00:00 for tlx by
1.13.2