-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lukas Larisch
committed
Jun 29, 2021
1 parent
3a8548c
commit a215c35
Showing
4,055 changed files
with
789,808 additions
and
0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
Copyright (c) Alexander Zaitsev <[email protected]>, 2017 | ||
Distributed under the Boost Software License, Version 1.0. (See | ||
accompanying file LICENSE_1_0.txt or copy at | ||
http://www.boost.org/LICENSE_1_0.txt) | ||
See http://www.boost.org/ for latest version. | ||
Based on https://blogs.msdn.microsoft.com/oldnewthing/20170104-00/?p=95115 | ||
*/ | ||
|
||
/// \file apply_permutation.hpp | ||
/// \brief Apply permutation to a sequence. | ||
/// \author Alexander Zaitsev | ||
|
||
#ifndef BOOST_ALGORITHM_APPLY_PERMUTATION_HPP | ||
#define BOOST_ALGORITHM_APPLY_PERMUTATION_HPP | ||
|
||
#include <algorithm> | ||
#include <type_traits> | ||
|
||
#include <boost/range/begin.hpp> | ||
#include <boost/range/end.hpp> | ||
|
||
namespace boost { namespace algorithm | ||
{ | ||
|
||
/// \fn apply_permutation ( RandomAccessIterator1 item_begin, RandomAccessIterator1 item_end, RandomAccessIterator2 ind_begin ) | ||
/// \brief Reorder item sequence with index sequence order | ||
/// | ||
/// \param item_begin The start of the item sequence | ||
/// \param item_end One past the end of the item sequence | ||
/// \param ind_begin The start of the index sequence. | ||
/// | ||
/// \note Item sequence size should be equal to index size. Otherwise behavior is undefined. | ||
/// Complexity: O(N). | ||
template<typename RandomAccessIterator1, typename RandomAccessIterator2> | ||
void | ||
apply_permutation(RandomAccessIterator1 item_begin, RandomAccessIterator1 item_end, | ||
RandomAccessIterator2 ind_begin, RandomAccessIterator2 ind_end) | ||
{ | ||
typedef typename std::iterator_traits<RandomAccessIterator1>::difference_type Diff; | ||
typedef typename std::iterator_traits<RandomAccessIterator2>::difference_type Index; | ||
using std::swap; | ||
Diff size = std::distance(item_begin, item_end); | ||
for (Diff i = 0; i < size; i++) | ||
{ | ||
Diff current = i; | ||
while (i != ind_begin[current]) | ||
{ | ||
Index next = ind_begin[current]; | ||
swap(item_begin[current], item_begin[next]); | ||
ind_begin[current] = current; | ||
current = next; | ||
} | ||
ind_begin[current] = current; | ||
} | ||
} | ||
|
||
/// \fn apply_reverse_permutation ( RandomAccessIterator1 item_begin, RandomAccessIterator1 item_end, RandomAccessIterator2 ind_begin ) | ||
/// \brief Reorder item sequence with index sequence order | ||
/// | ||
/// \param item_begin The start of the item sequence | ||
/// \param item_end One past the end of the item sequence | ||
/// \param ind_begin The start of the index sequence. | ||
/// | ||
/// \note Item sequence size should be equal to index size. Otherwise behavior is undefined. | ||
/// Complexity: O(N). | ||
template<typename RandomAccessIterator1, typename RandomAccessIterator2> | ||
void | ||
apply_reverse_permutation( | ||
RandomAccessIterator1 item_begin, | ||
RandomAccessIterator1 item_end, | ||
RandomAccessIterator2 ind_begin, | ||
RandomAccessIterator2 ind_end) | ||
{ | ||
typedef typename std::iterator_traits<RandomAccessIterator2>::difference_type Diff; | ||
using std::swap; | ||
Diff length = std::distance(item_begin, item_end); | ||
for (Diff i = 0; i < length; i++) | ||
{ | ||
while (i != ind_begin[i]) | ||
{ | ||
Diff next = ind_begin[i]; | ||
swap(item_begin[i], item_begin[next]); | ||
swap(ind_begin[i], ind_begin[next]); | ||
} | ||
} | ||
} | ||
|
||
/// \fn apply_permutation ( Range1 item_range, Range2 ind_range ) | ||
/// \brief Reorder item sequence with index sequence order | ||
/// | ||
/// \param item_range The item sequence | ||
/// \param ind_range The index sequence | ||
/// | ||
/// \note Item sequence size should be equal to index size. Otherwise behavior is undefined. | ||
/// Complexity: O(N). | ||
template<typename Range1, typename Range2> | ||
void | ||
apply_permutation(Range1& item_range, Range2& ind_range) | ||
{ | ||
apply_permutation(boost::begin(item_range), boost::end(item_range), | ||
boost::begin(ind_range), boost::end(ind_range)); | ||
} | ||
|
||
/// \fn apply_reverse_permutation ( Range1 item_range, Range2 ind_range ) | ||
/// \brief Reorder item sequence with index sequence order | ||
/// | ||
/// \param item_range The item sequence | ||
/// \param ind_range The index sequence | ||
/// | ||
/// \note Item sequence size should be equal to index size. Otherwise behavior is undefined. | ||
/// Complexity: O(N). | ||
template<typename Range1, typename Range2> | ||
void | ||
apply_reverse_permutation(Range1& item_range, Range2& ind_range) | ||
{ | ||
apply_reverse_permutation(boost::begin(item_range), boost::end(item_range), | ||
boost::begin(ind_range), boost::end(ind_range)); | ||
} | ||
|
||
}} | ||
#endif //BOOST_ALGORITHM_APPLY_PERMUTATION_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
Copyright (c) Marshall Clow 2017. | ||
Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
*/ | ||
|
||
/// \file exclusive_scan.hpp | ||
/// \brief ??? | ||
/// \author Marshall Clow | ||
|
||
#ifndef BOOST_ALGORITHM_EXCLUSIVE_SCAN_HPP | ||
#define BOOST_ALGORITHM_EXCLUSIVE_SCAN_HPP | ||
|
||
#include <functional> // for std::plus | ||
#include <iterator> // for std::iterator_traits | ||
|
||
#include <boost/range/begin.hpp> | ||
#include <boost/range/end.hpp> | ||
#include <boost/range/value_type.hpp> | ||
|
||
namespace boost { namespace algorithm { | ||
|
||
template<class InputIterator, class OutputIterator, class T, class BinaryOperation> | ||
OutputIterator exclusive_scan(InputIterator first, InputIterator last, | ||
OutputIterator result, T init, BinaryOperation bOp) | ||
{ | ||
if (first != last) | ||
{ | ||
T saved = init; | ||
do | ||
{ | ||
init = bOp(init, *first); | ||
*result = saved; | ||
saved = init; | ||
++result; | ||
} while (++first != last); | ||
} | ||
return result; | ||
} | ||
|
||
template<class InputIterator, class OutputIterator, class T> | ||
OutputIterator exclusive_scan(InputIterator first, InputIterator last, | ||
OutputIterator result, T init) | ||
{ | ||
typedef typename std::iterator_traits<InputIterator>::value_type VT; | ||
return boost::algorithm::exclusive_scan(first, last, result, init, std::plus<VT>()); | ||
} | ||
|
||
}} // namespace boost and algorithm | ||
|
||
#endif // BOOST_ALGORITHM_EXCLUSIVE_SCAN_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
Copyright (c) Marshall Clow 2017. | ||
Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
*/ | ||
|
||
/// \file for_each_n.hpp | ||
/// \brief Apply a functor to the elements of a sequence | ||
/// \author Marshall Clow | ||
|
||
#ifndef BOOST_ALGORITHM_FOR_EACH_N_HPP | ||
#define BOOST_ALGORITHM_FOR_EACH_N_HPP | ||
|
||
#include <utility> // for std::pair | ||
|
||
namespace boost { namespace algorithm { | ||
|
||
/// \fn for_each_n(InputIterator first, Size n, Function f); | ||
/// \return first + n | ||
/// | ||
/// \param first The start of the first range. | ||
/// \param n One past the end of the first range. | ||
/// \param f A functor to apply to the elements of the sequence | ||
/// \note If f returns a result, the result is ignored. | ||
template<class InputIterator, class Size, class Function> | ||
InputIterator for_each_n(InputIterator first, Size n, Function f) | ||
{ | ||
for ( ; n > 0; --n, ++first ) | ||
f(*first); | ||
|
||
return first; | ||
} | ||
|
||
}} // namespace boost and algorithm | ||
|
||
#endif // BOOST_ALGORITHM_FOR_EACH_N_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
Copyright (c) Marshall Clow 2017. | ||
Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
*/ | ||
|
||
/// \file transform_reduce.hpp | ||
/// \brief Combine the (transformed) elements of a sequence (or two) into a single value. | ||
/// \author Marshall Clow | ||
|
||
#ifndef BOOST_ALGORITHM_TRANSFORM_REDUCE_HPP | ||
#define BOOST_ALGORITHM_TRANSFORM_REDUCE_HPP | ||
|
||
#include <functional> // for std::plus | ||
#include <iterator> // for std::iterator_traits | ||
|
||
#include <boost/range/begin.hpp> | ||
#include <boost/range/end.hpp> | ||
#include <boost/range/value_type.hpp> | ||
|
||
namespace boost { namespace algorithm { | ||
|
||
template<class InputIterator, class OutputIterator, class T, class BinaryOperation> | ||
OutputIterator inclusive_scan(InputIterator first, InputIterator last, | ||
OutputIterator result, BinaryOperation bOp, T init) | ||
{ | ||
for (; first != last; ++first, (void) ++result) { | ||
init = bOp(init, *first); | ||
*result = init; | ||
} | ||
return result; | ||
} | ||
|
||
|
||
template<class InputIterator, class OutputIterator, class BinaryOperation> | ||
OutputIterator inclusive_scan(InputIterator first, InputIterator last, | ||
OutputIterator result, BinaryOperation bOp) | ||
{ | ||
if (first != last) { | ||
typename std::iterator_traits<InputIterator>::value_type init = *first; | ||
*result++ = init; | ||
if (++first != last) | ||
return boost::algorithm::inclusive_scan(first, last, result, bOp, init); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
template<class InputIterator, class OutputIterator> | ||
OutputIterator inclusive_scan(InputIterator first, InputIterator last, | ||
OutputIterator result) | ||
{ | ||
typedef typename std::iterator_traits<InputIterator>::value_type VT; | ||
return boost::algorithm::inclusive_scan(first, last, result, std::plus<VT>()); | ||
} | ||
|
||
}} // namespace boost and algorithm | ||
|
||
#endif // BOOST_ALGORITHM_TRANSFORM_REDUCE_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
Copyright (c) Marshall Clow 2017. | ||
Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
*/ | ||
|
||
/// \file reduce.hpp | ||
/// \brief Combine the elements of a sequence into a single value | ||
/// \author Marshall Clow | ||
|
||
#ifndef BOOST_ALGORITHM_REDUCE_HPP | ||
#define BOOST_ALGORITHM_REDUCE_HPP | ||
|
||
#include <functional> // for std::plus | ||
#include <iterator> // for std::iterator_traits | ||
|
||
#include <boost/range/begin.hpp> | ||
#include <boost/range/end.hpp> | ||
#include <boost/range/value_type.hpp> | ||
|
||
namespace boost { namespace algorithm { | ||
|
||
template<class InputIterator, class T, class BinaryOperation> | ||
T reduce(InputIterator first, InputIterator last, T init, BinaryOperation bOp) | ||
{ | ||
; | ||
for (; first != last; ++first) | ||
init = bOp(init, *first); | ||
return init; | ||
} | ||
|
||
template<class InputIterator, class T> | ||
T reduce(InputIterator first, InputIterator last, T init) | ||
{ | ||
typedef typename std::iterator_traits<InputIterator>::value_type VT; | ||
return boost::algorithm::reduce(first, last, init, std::plus<VT>()); | ||
} | ||
|
||
template<class InputIterator> | ||
typename std::iterator_traits<InputIterator>::value_type | ||
reduce(InputIterator first, InputIterator last) | ||
{ | ||
return boost::algorithm::reduce(first, last, | ||
typename std::iterator_traits<InputIterator>::value_type()); | ||
} | ||
|
||
template<class Range> | ||
typename boost::range_value<Range>::type | ||
reduce(const Range &r) | ||
{ | ||
return boost::algorithm::reduce(boost::begin(r), boost::end(r)); | ||
} | ||
|
||
// Not sure that this won't be ambiguous (1) | ||
template<class Range, class T> | ||
T reduce(const Range &r, T init) | ||
{ | ||
return boost::algorithm::reduce(boost::begin (r), boost::end (r), init); | ||
} | ||
|
||
|
||
// Not sure that this won't be ambiguous (2) | ||
template<class Range, class T, class BinaryOperation> | ||
T reduce(const Range &r, T init, BinaryOperation bOp) | ||
{ | ||
return boost::algorithm::reduce(boost::begin(r), boost::end(r), init, bOp); | ||
} | ||
|
||
}} // namespace boost and algorithm | ||
|
||
#endif // BOOST_ALGORITHM_REDUCE_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
Copyright (c) Marshall Clow 2017. | ||
Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
*/ | ||
|
||
/// \file transform_exclusive_scan.hpp | ||
/// \brief ???? | ||
/// \author Marshall Clow | ||
|
||
#ifndef BOOST_ALGORITHM_TRANSFORM_EXCLUSIVE_SCAN_HPP | ||
#define BOOST_ALGORITHM_TRANSFORM_EXCLUSIVE_SCAN_HPP | ||
|
||
#include <functional> // for std::plus | ||
#include <iterator> // for std::iterator_traits | ||
|
||
#include <boost/range/begin.hpp> | ||
#include <boost/range/end.hpp> | ||
#include <boost/range/value_type.hpp> | ||
|
||
namespace boost { namespace algorithm { | ||
|
||
template<class InputIterator, class OutputIterator, class T, | ||
class BinaryOperation, class UnaryOperation> | ||
OutputIterator transform_exclusive_scan(InputIterator first, InputIterator last, | ||
OutputIterator result, T init, | ||
BinaryOperation bOp, UnaryOperation uOp) | ||
{ | ||
if (first != last) | ||
{ | ||
T saved = init; | ||
do | ||
{ | ||
init = bOp(init, uOp(*first)); | ||
*result = saved; | ||
saved = init; | ||
++result; | ||
} while (++first != last); | ||
} | ||
return result; | ||
} | ||
|
||
}} // namespace boost and algorithm | ||
|
||
#endif // BOOST_ALGORITHM_TRANSFORM_EXCLUSIVE_SCAN_HPP |
Oops, something went wrong.