mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-11-29 01:03:45 +00:00
fix next|prev_permutation implementations
This commit is contained in:
parent
057dec630c
commit
2c0b1d4513
8 changed files with 150 additions and 141 deletions
|
@ -43,35 +43,34 @@ namespace testspr {
|
|||
}
|
||||
// 順列
|
||||
// 範囲の切り出し
|
||||
// !!!
|
||||
// {
|
||||
// SPROUT_STATIC_CONSTEXPR auto permutation = sprout::next_permutation(
|
||||
// sprout::sub(arr1, 2, 4)
|
||||
// );
|
||||
// TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
// permutation.first,
|
||||
// array<int, 3>{{2, 4, 3}}
|
||||
// ));
|
||||
// TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
// sprout::get_internal(permutation.first),
|
||||
// array<int, 5>{{1, 2, 4, 3, 5}}
|
||||
// ));
|
||||
// TESTSPR_BOTH_ASSERT(permutation.second);
|
||||
// }
|
||||
// {
|
||||
// SPROUT_STATIC_CONSTEXPR auto permutation = sprout::fit::next_permutation(
|
||||
// sprout::sub(arr1, 2, 4)
|
||||
// );
|
||||
// TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
// permutation.first,
|
||||
// array<int, 3>{{2, 4, 3}}
|
||||
// ));
|
||||
// TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
// sprout::get_internal(permutation.first),
|
||||
// array<int, 5>{{1, 2, 4, 3, 5}}
|
||||
// ));
|
||||
// TESTSPR_BOTH_ASSERT(permutation.second);
|
||||
// }
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto permutation = sprout::next_permutation(
|
||||
sprout::sub(arr1, 1, 4)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
permutation.first,
|
||||
array<int, 3>{{2, 4, 3}}
|
||||
));
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
sprout::get_internal(permutation.first),
|
||||
array<int, 5>{{1, 2, 4, 3, 5}}
|
||||
));
|
||||
TESTSPR_BOTH_ASSERT(permutation.second);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto permutation = sprout::fit::next_permutation(
|
||||
sprout::sub(arr1, 1, 4)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
permutation.first,
|
||||
array<int, 3>{{2, 4, 3}}
|
||||
));
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
sprout::get_internal(permutation.first),
|
||||
array<int, 5>{{1, 2, 4, 3, 5}}
|
||||
));
|
||||
TESTSPR_BOTH_ASSERT(permutation.second);
|
||||
}
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 5>{{1, 2, 3, 4, 5}};
|
||||
|
@ -101,37 +100,36 @@ namespace testspr {
|
|||
}
|
||||
// 順列
|
||||
// 範囲の切り出し
|
||||
// !!!
|
||||
// {
|
||||
// SPROUT_STATIC_CONSTEXPR auto permutation = sprout::next_permutation(
|
||||
// sprout::sub(arr1, 2, 4),
|
||||
// testspr::less<int>()
|
||||
// );
|
||||
// TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
// permutation.first,
|
||||
// array<int, 3>{{2, 4, 3}}
|
||||
// ));
|
||||
// TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
// sprout::get_internal(permutation.first),
|
||||
// array<int, 5>{{1, 2, 4, 3, 5}}
|
||||
// ));
|
||||
// TESTSPR_BOTH_ASSERT(permutation.second);
|
||||
// }
|
||||
// {
|
||||
// SPROUT_STATIC_CONSTEXPR auto permutation = sprout::fit::next_permutation(
|
||||
// sprout::sub(arr1, 2, 4),
|
||||
// testspr::less<int>()
|
||||
// );
|
||||
// TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
// permutation.first,
|
||||
// array<int, 3>{{2, 4, 3}}
|
||||
// ));
|
||||
// TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
// sprout::get_internal(permutation.first),
|
||||
// array<int, 5>{{1, 2, 4, 3, 5}}
|
||||
// ));
|
||||
// TESTSPR_BOTH_ASSERT(permutation.second);
|
||||
// }
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto permutation = sprout::next_permutation(
|
||||
sprout::sub(arr1, 1, 4),
|
||||
testspr::less<int>()
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
permutation.first,
|
||||
array<int, 3>{{2, 4, 3}}
|
||||
));
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
sprout::get_internal(permutation.first),
|
||||
array<int, 5>{{1, 2, 4, 3, 5}}
|
||||
));
|
||||
TESTSPR_BOTH_ASSERT(permutation.second);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto permutation = sprout::fit::next_permutation(
|
||||
sprout::sub(arr1, 1, 4),
|
||||
testspr::less<int>()
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
permutation.first,
|
||||
array<int, 3>{{2, 4, 3}}
|
||||
));
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
sprout::get_internal(permutation.first),
|
||||
array<int, 5>{{1, 2, 4, 3, 5}}
|
||||
));
|
||||
TESTSPR_BOTH_ASSERT(permutation.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace testspr
|
||||
|
|
|
@ -43,35 +43,34 @@ namespace testspr {
|
|||
}
|
||||
// 順列
|
||||
// 範囲の切り出し
|
||||
// !!!
|
||||
// {
|
||||
// SPROUT_STATIC_CONSTEXPR auto permutation = sprout::prev_permutation(
|
||||
// sprout::sub(arr1, 2, 4)
|
||||
// );
|
||||
// TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
// permutation.first,
|
||||
// array<int, 3>{{4, 2, 3}}
|
||||
// ));
|
||||
// TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
// sprout::get_internal(permutation.first),
|
||||
// array<int, 5>{{5, 4, 2, 3, 1}}
|
||||
// ));
|
||||
// TESTSPR_BOTH_ASSERT(permutation.second);
|
||||
// }
|
||||
// {
|
||||
// SPROUT_STATIC_CONSTEXPR auto permutation = sprout::fit::prev_permutation(
|
||||
// sprout::sub(arr1, 2, 4)
|
||||
// );
|
||||
// TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
// permutation.first,
|
||||
// array<int, 3>{{4, 2, 3}}
|
||||
// ));
|
||||
// TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
// sprout::get_internal(permutation.first),
|
||||
// array<int, 5>{{5, 4, 2, 3, 1}}
|
||||
// ));
|
||||
// TESTSPR_BOTH_ASSERT(permutation.second);
|
||||
// }
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto permutation = sprout::prev_permutation(
|
||||
sprout::sub(arr1, 1, 4)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
permutation.first,
|
||||
array<int, 3>{{4, 2, 3}}
|
||||
));
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
sprout::get_internal(permutation.first),
|
||||
array<int, 5>{{5, 4, 2, 3, 1}}
|
||||
));
|
||||
TESTSPR_BOTH_ASSERT(permutation.second);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto permutation = sprout::fit::prev_permutation(
|
||||
sprout::sub(arr1, 1, 4)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
permutation.first,
|
||||
array<int, 3>{{4, 2, 3}}
|
||||
));
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
sprout::get_internal(permutation.first),
|
||||
array<int, 5>{{5, 4, 2, 3, 1}}
|
||||
));
|
||||
TESTSPR_BOTH_ASSERT(permutation.second);
|
||||
}
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 5>{{5, 4, 3, 2, 1}};
|
||||
|
@ -101,37 +100,36 @@ namespace testspr {
|
|||
}
|
||||
// 順列
|
||||
// 範囲の切り出し
|
||||
// !!!
|
||||
// {
|
||||
// SPROUT_STATIC_CONSTEXPR auto permutation = sprout::prev_permutation(
|
||||
// sprout::sub(arr1, 2, 4),
|
||||
// testspr::less<int>()
|
||||
// );
|
||||
// TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
// permutation.first,
|
||||
// array<int, 3>{{4, 2, 3}}
|
||||
// ));
|
||||
// TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
// sprout::get_internal(permutation.first),
|
||||
// array<int, 5>{{5, 4, 2, 3, 1}}
|
||||
// ));
|
||||
// TESTSPR_BOTH_ASSERT(permutation.second);
|
||||
// }
|
||||
// {
|
||||
// SPROUT_STATIC_CONSTEXPR auto permutation = sprout::fit::prev_permutation(
|
||||
// sprout::sub(arr1, 2, 4),
|
||||
// testspr::less<int>()
|
||||
// );
|
||||
// TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
// permutation.first,
|
||||
// array<int, 3>{{4, 2, 3}}
|
||||
// ));
|
||||
// TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
// sprout::get_internal(permutation.first),
|
||||
// array<int, 5>{{5, 4, 2, 3, 1}}
|
||||
// ));
|
||||
// TESTSPR_BOTH_ASSERT(permutation.second);
|
||||
// }
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto permutation = sprout::prev_permutation(
|
||||
sprout::sub(arr1, 1, 4),
|
||||
testspr::less<int>()
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
permutation.first,
|
||||
array<int, 3>{{4, 2, 3}}
|
||||
));
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
sprout::get_internal(permutation.first),
|
||||
array<int, 5>{{5, 4, 2, 3, 1}}
|
||||
));
|
||||
TESTSPR_BOTH_ASSERT(permutation.second);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto permutation = sprout::fit::prev_permutation(
|
||||
sprout::sub(arr1, 1, 4),
|
||||
testspr::less<int>()
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
permutation.first,
|
||||
array<int, 3>{{4, 2, 3}}
|
||||
));
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
sprout::get_internal(permutation.first),
|
||||
array<int, 5>{{5, 4, 2, 3, 1}}
|
||||
));
|
||||
TESTSPR_BOTH_ASSERT(permutation.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace testspr
|
||||
|
|
|
@ -59,7 +59,6 @@ namespace sprout {
|
|||
typename std::iterator_traits<RandomAccessIterator>::difference_type len
|
||||
)
|
||||
{
|
||||
typedef typename std::iterator_traits<RandomAccessIterator>::difference_type difference_type;
|
||||
typedef typename std::iterator_traits<RandomAccessIterator>::value_type value_type;
|
||||
if (len > 1) {
|
||||
len = (len - 2) / 2;
|
||||
|
|
|
@ -15,8 +15,14 @@
|
|||
#include <sprout/algorithm/fixed/results.hpp>
|
||||
#include <sprout/algorithm/fixed/swap_element.hpp>
|
||||
#include <sprout/algorithm/fixed/reverse_copy.hpp>
|
||||
#include <sprout/algorithm/fixed/reverse.hpp>
|
||||
#include <sprout/sub_array/sub_array.hpp>
|
||||
#include <sprout/detail/predef.hpp>
|
||||
#if SPROUT_GCC_EARLIER(4, 8, 2)
|
||||
# include <sprout/algorithm/fit/reverse_copy.hpp>
|
||||
# include <sprout/range/algorithm/fixed/copy_backward.hpp>
|
||||
#else
|
||||
# include <sprout/iterator/reverse_iterator.hpp>
|
||||
# include <sprout/algorithm/fixed/copy_backward.hpp>
|
||||
#endif
|
||||
#include <sprout/utility/pair/pair.hpp>
|
||||
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT
|
||||
|
||||
|
@ -27,7 +33,11 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR Result
|
||||
next_permutation_impl_4(Container const& cont, Difference d) {
|
||||
return Result(
|
||||
sprout::get_internal(sprout::fixed::reverse(sprout::sub_array<Container const&>(cont, d, sprout::size(cont)))),
|
||||
#if SPROUT_GCC_EARLIER(4, 8, 2)
|
||||
sprout::range::fixed::copy_backward(sprout::fit::reverse_copy(sprout::next(sprout::begin(cont), d), sprout::end(cont), cont), cont),
|
||||
#else
|
||||
sprout::fixed::copy_backward(sprout::make_reverse_iterator(sprout::end(cont)), sprout::make_reverse_iterator(sprout::next(sprout::begin(cont), d)), cont),
|
||||
#endif
|
||||
true
|
||||
);
|
||||
}
|
||||
|
|
|
@ -15,8 +15,14 @@
|
|||
#include <sprout/algorithm/fixed/results.hpp>
|
||||
#include <sprout/algorithm/fixed/swap_element.hpp>
|
||||
#include <sprout/algorithm/fixed/reverse_copy.hpp>
|
||||
#include <sprout/algorithm/fixed/reverse.hpp>
|
||||
#include <sprout/sub_array/sub_array.hpp>
|
||||
#include <sprout/detail/predef.hpp>
|
||||
#if SPROUT_GCC_EARLIER(4, 8, 2)
|
||||
# include <sprout/algorithm/fit/reverse_copy.hpp>
|
||||
# include <sprout/range/algorithm/fixed/copy_backward.hpp>
|
||||
#else
|
||||
# include <sprout/iterator/reverse_iterator.hpp>
|
||||
# include <sprout/algorithm/fixed/copy_backward.hpp>
|
||||
#endif
|
||||
#include <sprout/utility/pair/pair.hpp>
|
||||
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT
|
||||
|
||||
|
@ -27,7 +33,11 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR Result
|
||||
prev_permutation_impl_4(Container const& cont, Difference d) {
|
||||
return Result(
|
||||
sprout::get_internal(sprout::fixed::reverse(sprout::sub_array<Container const&>(cont, d, sprout::size(cont)))),
|
||||
#if SPROUT_GCC_EARLIER(4, 8, 2)
|
||||
sprout::range::fixed::copy_backward(sprout::fit::reverse_copy(sprout::next(sprout::begin(cont), d), sprout::end(cont), cont), cont),
|
||||
#else
|
||||
sprout::fixed::copy_backward(sprout::make_reverse_iterator(sprout::end(cont)), sprout::make_reverse_iterator(sprout::next(sprout::begin(cont), d)), cont),
|
||||
#endif
|
||||
true
|
||||
);
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
#include <climits>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
//#include <sprout/bit/popcount.hpp>
|
||||
#include <sprout/bit/shlr.hpp>
|
||||
|
||||
namespace sprout {
|
||||
|
@ -31,11 +30,6 @@ namespace sprout {
|
|||
return __builtin_parityll(x);
|
||||
}
|
||||
# endif
|
||||
// template<typename Integral>
|
||||
// inline SPROUT_CONSTEXPR int
|
||||
// parity(Integral x) {
|
||||
// return sprout::popcount(x) & 1;
|
||||
// }
|
||||
template<std::size_t N, typename Integral>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||
(N == 1),
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace sprout {
|
|||
typename sprout::fixed::results::algorithm<Result>::type
|
||||
>::type
|
||||
container_complate_backward_2(Result const& result, Args const&... args) {
|
||||
return container_complate_backward_2(result, *sprout::prev(sprout::internal_end(result), sizeof...(Args) + 1), args...);
|
||||
return sprout::detail::container_complate_backward_2(result, *sprout::prev(sprout::internal_end(result), sizeof...(Args) + 1), args...);
|
||||
}
|
||||
template<typename Result, typename... Args>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||
|
@ -58,8 +58,8 @@ namespace sprout {
|
|||
)
|
||||
{
|
||||
return remain != 0
|
||||
? container_complate_backward_1(result, remain - 1, args..., *sprout::prev(sprout::internal_end(result), remain))
|
||||
: container_complate_backward_2(result, args...)
|
||||
? sprout::detail::container_complate_backward_1(result, remain - 1, args..., *sprout::prev(sprout::internal_end(result), remain))
|
||||
: sprout::detail::container_complate_backward_2(result, args...)
|
||||
;
|
||||
}
|
||||
template<typename Result, typename... Args>
|
||||
|
@ -76,7 +76,7 @@ namespace sprout {
|
|||
typename sprout::fixed::results::algorithm<Result>::type
|
||||
>::type
|
||||
container_complate_backward(Result const& result, Args const&... args) {
|
||||
return container_complate_backward_1(result, sprout::internal_end_offset_backward(result), args...);
|
||||
return sprout::detail::container_complate_backward_1(result, sprout::internal_end_offset_backward(result), args...);
|
||||
}
|
||||
} // namespace detail
|
||||
} // namespace sprout
|
||||
|
|
|
@ -148,16 +148,16 @@ fi
|
|||
if [ -z "${clang_version}" ]; then
|
||||
clang_version=" "
|
||||
fi
|
||||
for user_macro in ${user_macros}; do
|
||||
for user_macro in ${user_macros[*]}; do
|
||||
define_options="${define_options} -D${user_macro}"
|
||||
done
|
||||
for include_path in ${include_paths}; do
|
||||
for include_path in ${include_paths[*]}; do
|
||||
include_options="${include_options} -I${include_path}"
|
||||
done
|
||||
all_options="-v -Wall -pedantic ${define_options} ${include_options} ${common_options[*]}"
|
||||
vo=0
|
||||
vkey=""
|
||||
for option in ${compiler_options}; do
|
||||
for option in ${compiler_options[*]}; do
|
||||
if [ ${vo} -eq 0 ]; then
|
||||
vkey=${option}
|
||||
vo=1
|
||||
|
@ -166,7 +166,7 @@ for option in ${compiler_options}; do
|
|||
vo=0
|
||||
fi
|
||||
done
|
||||
for option in ${version_options}; do
|
||||
for option in ${version_options[*]}; do
|
||||
if [ ${vo} -eq 0 ]; then
|
||||
vkey=${option}
|
||||
vo=1
|
||||
|
|
Loading…
Reference in a new issue