1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-11-12 21:09:01 +00:00

add bozo_sort

This commit is contained in:
bolero-MURAKAMI 2012-07-25 23:10:01 +09:00
parent a64938fad0
commit 8cd36c14bd
24 changed files with 1322 additions and 8 deletions

View file

@ -0,0 +1,137 @@
#ifndef SPROUT_LIBS_ALGORITHM_TEST_BOZO_SORT_CPP
#define SPROUT_LIBS_ALGORITHM_TEST_BOZO_SORT_CPP
#include <sprout/algorithm/bozo_sort.hpp>
#include <sprout/random.hpp>
#include <sprout/random/unique_seed.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_bozo_sort_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 5>{{5, 1, 4, 2, 3}};
// ソート
{
SPROUT_STATIC_CONSTEXPR auto sorted = sprout::bozo_sort(
arr1,
sprout::random::default_random_engine(SPROUT_UNIQUE_SEED)
);
TESTSPR_BOTH_ASSERT(testspr::equal(
sorted,
array<int, 5>{{1, 2, 3, 4, 5}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::bozo_sort(
arr1,
sprout::random::default_random_engine(SPROUT_UNIQUE_SEED)
);
TESTSPR_BOTH_ASSERT(testspr::equal(
sorted,
array<int, 5>{{1, 2, 3, 4, 5}}
));
}
// ソート
// 範囲の切り出し
{
SPROUT_STATIC_CONSTEXPR auto sorted = sprout::bozo_sort(
sprout::sub(arr1, 1, 4),
sprout::random::default_random_engine(SPROUT_UNIQUE_SEED)
);
TESTSPR_BOTH_ASSERT(testspr::equal(
sorted,
array<int, 3>{{1, 2, 4}}
));
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get_internal(sorted),
array<int, 5>{{5, 1, 2, 4, 3}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::bozo_sort(
sprout::sub(arr1, 1, 4),
sprout::random::default_random_engine(SPROUT_UNIQUE_SEED)
);
TESTSPR_BOTH_ASSERT(testspr::equal(
sorted,
array<int, 3>{{1, 2, 4}}
));
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get_internal(sorted),
array<int, 5>{{5, 1, 2, 4, 3}}
));
}
}
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 5>{{5, 1, 4, 2, 3}};
// ソート
{
SPROUT_STATIC_CONSTEXPR auto sorted = sprout::bozo_sort(
arr1,
sprout::random::default_random_engine(SPROUT_UNIQUE_SEED),
testspr::less<int>()
);
TESTSPR_BOTH_ASSERT(testspr::equal(
sorted,
array<int, 5>{{1, 2, 3, 4, 5}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::bozo_sort(
arr1,
sprout::random::default_random_engine(SPROUT_UNIQUE_SEED),
testspr::less<int>()
);
TESTSPR_BOTH_ASSERT(testspr::equal(
sorted,
array<int, 5>{{1, 2, 3, 4, 5}}
));
}
// ソート
// 範囲の切り出し
{
SPROUT_STATIC_CONSTEXPR auto sorted = sprout::bozo_sort(
sprout::sub(arr1, 1, 4),
sprout::random::default_random_engine(SPROUT_UNIQUE_SEED),
testspr::less<int>()
);
TESTSPR_BOTH_ASSERT(testspr::equal(
sorted,
array<int, 3>{{1, 2, 4}}
));
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get_internal(sorted),
array<int, 5>{{5, 1, 2, 4, 3}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::bozo_sort(
sprout::sub(arr1, 1, 4),
sprout::random::default_random_engine(SPROUT_UNIQUE_SEED),
testspr::less<int>()
);
TESTSPR_BOTH_ASSERT(testspr::equal(
sorted,
array<int, 3>{{1, 2, 4}}
));
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get_internal(sorted),
array<int, 5>{{5, 1, 2, 4, 3}}
));
}
}
}
} // namespace testspr
#ifndef TESTSPR_CPP_INCLUDE
# define TESTSPR_TEST_FUNCTION testspr::algorithm_bozo_sort_test
# include <testspr/include_main.hpp>
#endif
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_BOZO_SORT_CPP

View file

@ -0,0 +1,179 @@
#ifndef SPROUT_LIBS_ALGORITHM_TEST_BOZO_SORT_RESULT_CPP
#define SPROUT_LIBS_ALGORITHM_TEST_BOZO_SORT_RESULT_CPP
#include <sprout/algorithm/bozo_sort_result.hpp>
#include <sprout/random.hpp>
#include <sprout/random/unique_seed.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_bozo_sort_result_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 5>{{5, 1, 4, 2, 3}};
SPROUT_STATIC_CONSTEXPR auto g = sprout::random::default_random_engine(SPROUT_UNIQUE_SEED);
// ソート
{
SPROUT_STATIC_CONSTEXPR auto sorted = sprout::bozo_sort_result(
arr1,
g
);
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get<0>(sorted),
array<int, 5>{{1, 2, 3, 4, 5}}
));
SPROUT_STATIC_CONSTEXPR auto sorted2 = sprout::bozo_sort_result(
sprout::get<0>(sorted),
sprout::get<1>(sorted)
);
TESTSPR_BOTH_ASSERT(sprout::get<1>(sorted) == sprout::get<1>(sorted2));
}
{
SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::bozo_sort_result(
arr1,
g
);
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get<0>(sorted),
array<int, 5>{{1, 2, 3, 4, 5}}
));
SPROUT_STATIC_CONSTEXPR auto sorted2 = sprout::bozo_sort_result(
sprout::get<0>(sorted),
sprout::get<1>(sorted)
);
TESTSPR_BOTH_ASSERT(sprout::get<1>(sorted) == sprout::get<1>(sorted2));
}
// ソート
// 範囲の切り出し
{
SPROUT_STATIC_CONSTEXPR auto sorted = sprout::bozo_sort_result(
sprout::sub(arr1, 1, 4),
g
);
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get<0>(sorted),
array<int, 3>{{1, 2, 4}}
));
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get_internal(sprout::get<0>(sorted)),
array<int, 5>{{5, 1, 2, 4, 3}}
));
SPROUT_STATIC_CONSTEXPR auto sorted2 = sprout::bozo_sort_result(
sprout::get<0>(sorted),
sprout::get<1>(sorted)
);
TESTSPR_BOTH_ASSERT(sprout::get<1>(sorted) == sprout::get<1>(sorted2));
}
{
SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::bozo_sort_result(
sprout::sub(arr1, 1, 4),
g
);
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get<0>(sorted),
array<int, 3>{{1, 2, 4}}
));
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get_internal(sprout::get<0>(sorted)),
array<int, 5>{{5, 1, 2, 4, 3}}
));
SPROUT_STATIC_CONSTEXPR auto sorted2 = sprout::bozo_sort_result(
sprout::get<0>(sorted),
sprout::get<1>(sorted)
);
TESTSPR_BOTH_ASSERT(sprout::get<1>(sorted) == sprout::get<1>(sorted2));
}
}
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 5>{{5, 1, 4, 2, 3}};
SPROUT_STATIC_CONSTEXPR auto g = sprout::random::default_random_engine(SPROUT_UNIQUE_SEED);
// ソート
{
SPROUT_STATIC_CONSTEXPR auto sorted = sprout::bozo_sort_result(
arr1,
g,
testspr::less<int>()
);
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get<0>(sorted),
array<int, 5>{{1, 2, 3, 4, 5}}
));
SPROUT_STATIC_CONSTEXPR auto sorted2 = sprout::bozo_sort_result(
sprout::get<0>(sorted),
sprout::get<1>(sorted)
);
TESTSPR_BOTH_ASSERT(sprout::get<1>(sorted) == sprout::get<1>(sorted2));
}
{
SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::bozo_sort_result(
arr1,
g,
testspr::less<int>()
);
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get<0>(sorted),
array<int, 5>{{1, 2, 3, 4, 5}}
));
SPROUT_STATIC_CONSTEXPR auto sorted2 = sprout::bozo_sort_result(
sprout::get<0>(sorted),
sprout::get<1>(sorted)
);
TESTSPR_BOTH_ASSERT(sprout::get<1>(sorted) == sprout::get<1>(sorted2));
}
// ソート
// 範囲の切り出し
{
SPROUT_STATIC_CONSTEXPR auto sorted = sprout::bozo_sort_result(
sprout::sub(arr1, 1, 4),
g,
testspr::less<int>()
);
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get<0>(sorted),
array<int, 3>{{1, 2, 4}}
));
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get_internal(sprout::get<0>(sorted)),
array<int, 5>{{5, 1, 2, 4, 3}}
));
SPROUT_STATIC_CONSTEXPR auto sorted2 = sprout::bozo_sort_result(
sprout::get<0>(sorted),
sprout::get<1>(sorted)
);
TESTSPR_BOTH_ASSERT(sprout::get<1>(sorted) == sprout::get<1>(sorted2));
}
{
SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::bozo_sort_result(
sprout::sub(arr1, 1, 4),
g,
testspr::less<int>()
);
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get<0>(sorted),
array<int, 3>{{1, 2, 4}}
));
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get_internal(sprout::get<0>(sorted)),
array<int, 5>{{5, 1, 2, 4, 3}}
));
SPROUT_STATIC_CONSTEXPR auto sorted2 = sprout::bozo_sort_result(
sprout::get<0>(sorted),
sprout::get<1>(sorted)
);
TESTSPR_BOTH_ASSERT(sprout::get<1>(sorted) == sprout::get<1>(sorted2));
}
}
}
} // namespace testspr
#ifndef TESTSPR_CPP_INCLUDE
# define TESTSPR_TEST_FUNCTION testspr::algorithm_bozo_sort_result_test
# include <testspr/include_main.hpp>
#endif
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_BOZO_SORT_RESULT_CPP

View file

@ -54,8 +54,12 @@
#include "./prev_permutation.cpp"
#include "./swap_element.cpp"
#include "./swap_element_copy.cpp"
#include "./random_swap.cpp"
#include "./random_swap_result.cpp"
#include "./bogo_sort.cpp"
#include "./bogo_sort_result.cpp"
#include "./bozo_sort.cpp"
#include "./bozo_sort_result.cpp"
#ifdef TESTSPR_CPP_INCLUDE_DISABLE_SPROUT_LIBS_ALGORITHM_TEST_MODIFYIING_CPP
# undef TESTSPR_CPP_INCLUDE
@ -111,8 +115,12 @@ namespace testspr {
testspr::algorithm_prev_permutation_test();
testspr::algorithm_swap_element_test();
testspr::algorithm_swap_element_copy_test();
testspr::algorithm_random_swap_test();
testspr::algorithm_random_swap_result_test();
testspr::algorithm_bogo_sort_test();
testspr::algorithm_bogo_sort_result_test();
testspr::algorithm_bozo_sort_test();
testspr::algorithm_bozo_sort_result_test();
}
} // namespace testspr

View file

@ -0,0 +1,78 @@
#ifndef SPROUT_LIBS_ALGORITHM_TEST_RANDOM_SWAP_CPP
#define SPROUT_LIBS_ALGORITHM_TEST_RANDOM_SWAP_CPP
#include <sprout/algorithm/random_swap.hpp>
#include <sprout/random.hpp>
#include <sprout/random/unique_seed.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_random_swap_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};
// ランダムスワップ
{
SPROUT_STATIC_CONSTEXPR auto random_swapped = sprout::random_swap(
arr1,
sprout::random::default_random_engine(SPROUT_UNIQUE_SEED)
);
TESTSPR_BOTH_ASSERT(testspr::is_permutation(
random_swapped,
arr1
));
}
{
SPROUT_STATIC_CONSTEXPR auto random_swapped = sprout::fit::random_swap(
arr1,
sprout::random::default_random_engine(SPROUT_UNIQUE_SEED)
);
TESTSPR_BOTH_ASSERT(testspr::is_permutation(
random_swapped,
arr1
));
}
// ランダムスワップ
// 範囲の切り出し
{
SPROUT_STATIC_CONSTEXPR auto random_swapped = sprout::random_swap(
sprout::sub(arr1, 2, 8),
sprout::random::default_random_engine(SPROUT_UNIQUE_SEED)
);
TESTSPR_BOTH_ASSERT(testspr::is_permutation(
random_swapped,
sprout::sub(arr1, 2, 8)
));
TESTSPR_BOTH_ASSERT(testspr::is_permutation(
sprout::get_internal(random_swapped),
arr1
));
}
{
SPROUT_STATIC_CONSTEXPR auto random_swapped = sprout::fit::random_swap(
sprout::sub(arr1, 2, 8),
sprout::random::default_random_engine(SPROUT_UNIQUE_SEED)
);
TESTSPR_BOTH_ASSERT(testspr::is_permutation(
random_swapped,
sprout::sub(arr1, 2, 8)
));
TESTSPR_BOTH_ASSERT(testspr::is_permutation(
sprout::get_internal(random_swapped),
arr1
));
}
}
}
} // namespace testspr
#ifndef TESTSPR_CPP_INCLUDE
# define TESTSPR_TEST_FUNCTION testspr::algorithm_random_swap_test
# include <testspr/include_main.hpp>
#endif
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_RANDOM_SWAP_CPP

View file

@ -0,0 +1,99 @@
#ifndef SPROUT_LIBS_ALGORITHM_TEST_RANDOM_SWAP_RESULT_CPP
#define SPROUT_LIBS_ALGORITHM_TEST_RANDOM_SWAP_RESULT_CPP
#include <sprout/algorithm/random_swap_result.hpp>
#include <sprout/random.hpp>
#include <sprout/random/unique_seed.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_random_swap_result_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};
SPROUT_STATIC_CONSTEXPR auto g = sprout::random::default_random_engine(SPROUT_UNIQUE_SEED);
// ランダムスワップ
{
SPROUT_STATIC_CONSTEXPR auto random_swapped = sprout::random_swap_result(
arr1,
g
);
TESTSPR_BOTH_ASSERT(testspr::is_permutation(
sprout::get<0>(random_swapped),
arr1
));
SPROUT_STATIC_CONSTEXPR auto random_swapped2 = sprout::random_swap_result(
sprout::get<0>(random_swapped),
g
);
TESTSPR_BOTH_ASSERT(sprout::get<1>(random_swapped) == sprout::get<1>(random_swapped2));
}
{
SPROUT_STATIC_CONSTEXPR auto random_swapped = sprout::fit::random_swap_result(
arr1,
g
);
TESTSPR_BOTH_ASSERT(testspr::is_permutation(
sprout::get<0>(random_swapped),
arr1
));
SPROUT_STATIC_CONSTEXPR auto random_swapped2 = sprout::random_swap_result(
sprout::get<0>(random_swapped),
g
);
TESTSPR_BOTH_ASSERT(sprout::get<1>(random_swapped) == sprout::get<1>(random_swapped2));
}
// ランダムスワップ
// 範囲の切り出し
{
SPROUT_STATIC_CONSTEXPR auto random_swapped = sprout::random_swap_result(
sprout::sub(arr1, 2, 8),
g
);
TESTSPR_BOTH_ASSERT(testspr::is_permutation(
sprout::get<0>(random_swapped),
sprout::sub(arr1, 2, 8)
));
TESTSPR_BOTH_ASSERT(testspr::is_permutation(
sprout::get_internal(sprout::get<0>(random_swapped)),
arr1
));
SPROUT_STATIC_CONSTEXPR auto random_swapped2 = sprout::random_swap_result(
sprout::get<0>(random_swapped),
g
);
TESTSPR_BOTH_ASSERT(sprout::get<1>(random_swapped) == sprout::get<1>(random_swapped2));
}
{
SPROUT_STATIC_CONSTEXPR auto random_swapped = sprout::fit::random_swap_result(
sprout::sub(arr1, 2, 8),
g
);
TESTSPR_BOTH_ASSERT(testspr::is_permutation(
sprout::get<0>(random_swapped),
sprout::sub(arr1, 2, 8)
));
TESTSPR_BOTH_ASSERT(testspr::is_permutation(
sprout::get_internal(sprout::get<0>(random_swapped)),
arr1
));
SPROUT_STATIC_CONSTEXPR auto random_swapped2 = sprout::random_swap_result(
sprout::get<0>(random_swapped),
g
);
TESTSPR_BOTH_ASSERT(sprout::get<1>(random_swapped) == sprout::get<1>(random_swapped2));
}
}
}
} // namespace testspr
#ifndef TESTSPR_CPP_INCLUDE
# define TESTSPR_TEST_FUNCTION testspr::algorithm_random_swap_result_test
# include <testspr/include_main.hpp>
#endif
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_RANDOM_SWAP_RESULT_CPP

View file

@ -0,0 +1,8 @@
#ifndef SPROUT_ALGORITHM_BOZO_SORT_HPP
#define SPROUT_ALGORITHM_BOZO_SORT_HPP
#include <sprout/config.hpp>
#include <sprout/algorithm/fixed/bozo_sort.hpp>
#include <sprout/algorithm/fit/bozo_sort.hpp>
#endif // #ifndef SPROUT_ALGORITHM_BOZO_SORT_HPP

View file

@ -0,0 +1,8 @@
#ifndef SPROUT_ALGORITHM_BOZO_SORT_RESULT_HPP
#define SPROUT_ALGORITHM_BOZO_SORT_RESULT_HPP
#include <sprout/config.hpp>
#include <sprout/algorithm/fixed/bozo_sort_result.hpp>
#include <sprout/algorithm/fit/bozo_sort_result.hpp>
#endif // #ifndef SPROUT_ALGORITHM_BOZO_SORT_RESULT_HPP

View file

@ -48,9 +48,11 @@
#include <sprout/algorithm/fit/sort_heap.hpp>
#include <sprout/algorithm/fit/next_permutation.hpp>
#include <sprout/algorithm/fit/prev_permutation.hpp>
#include <sprout/algorithm/fit/swap_element.hpp>
#include <sprout/algorithm/fit/swap_element_copy.hpp>
#include <sprout/algorithm/fit/random_swap.hpp>
#include <sprout/algorithm/fit/random_swap_result.hpp>
#include <sprout/algorithm/fit/bogo_sort.hpp>
#include <sprout/algorithm/fit/bogo_sort_result.hpp>
#include <sprout/algorithm/fit/bozo_sort.hpp>
#include <sprout/algorithm/fit/bozo_sort_result.hpp>
#endif // #ifndef SPROUT_ALGORITHM_FIT_HPP

View file

@ -0,0 +1,80 @@
#ifndef SPROUT_ALGORITHM_FIT_BOZO_SORT_HPP
#define SPROUT_ALGORITHM_FIT_BOZO_SORT_HPP
#include <sprout/config.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/algorithm/fixed/bozo_sort.hpp>
#include <sprout/algorithm/fit/result_of.hpp>
#include <sprout/sub_array.hpp>
namespace sprout {
namespace fit {
namespace detail {
template<typename Container, typename UniformRandomNumberGenerator, typename Compare>
inline SPROUT_CONSTEXPR typename sprout::fit::result_of::algorithm<Container>::type bozo_sort_impl(
Container const& cont,
UniformRandomNumberGenerator&& g,
Compare comp,
typename sprout::container_traits<Container>::difference_type offset
)
{
return sprout::sub_copy(
sprout::get_internal(sprout::fixed::bozo_sort(cont, sprout::forward<UniformRandomNumberGenerator>(g), comp)),
offset,
offset + sprout::size(cont)
);
}
} // namespace detail
//
// bozo_sort
//
template<typename Container, typename UniformRandomNumberGenerator, typename Compare>
inline SPROUT_CONSTEXPR typename sprout::fit::result_of::algorithm<Container>::type bozo_sort(
Container const& cont,
UniformRandomNumberGenerator&& g,
Compare comp
)
{
return sprout::fit::detail::bozo_sort_impl(
cont,
sprout::forward<UniformRandomNumberGenerator>(g),
comp,
sprout::internal_begin_offset(cont)
);
}
namespace detail {
template<typename Container, typename UniformRandomNumberGenerator>
inline SPROUT_CONSTEXPR typename sprout::fit::result_of::algorithm<Container>::type bozo_sort_impl(
Container const& cont,
UniformRandomNumberGenerator&& g,
typename sprout::container_traits<Container>::difference_type offset
)
{
return sprout::sub_copy(
sprout::get_internal(sprout::fixed::bozo_sort(cont, sprout::forward<UniformRandomNumberGenerator>(g))),
offset,
offset + sprout::size(cont)
);
}
} // namespace detail
//
// bozo_sort
//
template<typename Container, typename UniformRandomNumberGenerator>
inline SPROUT_CONSTEXPR typename sprout::fit::result_of::algorithm<Container>::type bozo_sort(
Container const& cont,
UniformRandomNumberGenerator&& g
)
{
return sprout::fit::detail::bozo_sort_impl(
cont,
sprout::forward<UniformRandomNumberGenerator>(g),
sprout::internal_begin_offset(cont)
);
}
} // namespace fit
} // namespace sprout
#endif // #ifndef SPROUT_ALGORITHM_FIT_BOZO_SORT_HPP

View file

@ -0,0 +1,114 @@
#ifndef SPROUT_ALGORITHM_FIT_BOZO_SORT_RESULT_HPP
#define SPROUT_ALGORITHM_FIT_BOZO_SORT_RESULT_HPP
#include <sprout/config.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/algorithm/fixed/bozo_sort_result.hpp>
#include <sprout/algorithm/fit/result_of.hpp>
#include <sprout/sub_array.hpp>
namespace sprout {
namespace fit {
namespace detail {
template<typename Container, typename UniformRandomNumberGenerator, typename Sorted>
inline SPROUT_CONSTEXPR sprout::tuples::tuple<
typename sprout::fit::result_of::algorithm<Container>::type,
typename std::decay<UniformRandomNumberGenerator>::type
> bozo_sort_result_impl_1(
Sorted const& sorted,
typename sprout::container_traits<Container>::difference_type offset
)
{
typedef sprout::tuples::tuple<
typename sprout::fit::result_of::algorithm<Container>::type,
typename std::decay<UniformRandomNumberGenerator>::type
> result_type;
return result_type(
sprout::sub_copy(
sprout::get_internal(sprout::tuples::get<0>(sorted)),
offset,
offset + sprout::size(sprout::tuples::get<0>(sorted))
),
sprout::tuples::get<1>(sorted)
);
}
template<typename Container, typename UniformRandomNumberGenerator, typename Compare>
inline SPROUT_CONSTEXPR sprout::tuples::tuple<
typename sprout::fit::result_of::algorithm<Container>::type,
typename std::decay<UniformRandomNumberGenerator>::type
> bozo_sort_result_impl(
Container const& cont,
UniformRandomNumberGenerator&& g,
Compare comp,
typename sprout::container_traits<Container>::difference_type offset
)
{
return sprout::fit::detail::bozo_sort_result_impl_1<Container, UniformRandomNumberGenerator>(
sprout::fixed::bozo_sort_result(cont, sprout::forward<UniformRandomNumberGenerator>(g), comp),
offset
);
}
} // namespace detail
//
// bozo_sort_result
//
template<typename Container, typename UniformRandomNumberGenerator, typename Compare>
inline SPROUT_CONSTEXPR sprout::tuples::tuple<
typename sprout::fit::result_of::algorithm<Container>::type,
typename std::decay<UniformRandomNumberGenerator>::type
> bozo_sort_result(
Container const& cont,
UniformRandomNumberGenerator&& g,
Compare comp
)
{
return sprout::fit::detail::bozo_sort_result_impl(
cont,
sprout::forward<UniformRandomNumberGenerator>(g),
comp,
sprout::internal_begin_offset(cont)
);
}
namespace detail {
template<typename Container, typename UniformRandomNumberGenerator>
inline SPROUT_CONSTEXPR sprout::tuples::tuple<
typename sprout::fit::result_of::algorithm<Container>::type,
typename std::decay<UniformRandomNumberGenerator>::type
> bozo_sort_result_impl(
Container const& cont,
UniformRandomNumberGenerator&& g,
typename sprout::container_traits<Container>::difference_type offset
)
{
return sprout::fit::detail::bozo_sort_result_impl_1<Container, UniformRandomNumberGenerator>(
sprout::fixed::bozo_sort_result(cont, sprout::forward<UniformRandomNumberGenerator>(g)),
offset
);
}
} // namespace detail
//
// bozo_sort_result
//
template<typename Container, typename UniformRandomNumberGenerator>
inline SPROUT_CONSTEXPR sprout::tuples::tuple<
typename sprout::fit::result_of::algorithm<Container>::type,
typename std::decay<UniformRandomNumberGenerator>::type
> bozo_sort_result(
Container const& cont,
UniformRandomNumberGenerator&& g
)
{
return sprout::fit::detail::bozo_sort_result_impl(
cont,
sprout::forward<UniformRandomNumberGenerator>(g),
sprout::internal_begin_offset(cont)
);
}
} // namespace fit
} // namespace sprout
#endif // #ifndef SPROUT_ALGORITHM_FIT_BOZO_SORT_RESULT_HPP

View file

@ -0,0 +1,47 @@
#ifndef SPROUT_ALGORITHM_FIT_RANDOM_SWAP_HPP
#define SPROUT_ALGORITHM_FIT_RANDOM_SWAP_HPP
#include <sprout/config.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/algorithm/fixed/random_swap.hpp>
#include <sprout/algorithm/fit/result_of.hpp>
#include <sprout/sub_array.hpp>
namespace sprout {
namespace fit {
namespace detail {
template<typename Container, typename UniformRandomNumberGenerator>
inline SPROUT_CONSTEXPR typename sprout::fit::result_of::algorithm<Container>::type random_swap_impl(
Container const& cont,
UniformRandomNumberGenerator&& g,
typename sprout::container_traits<Container>::difference_type offset
)
{
return sprout::sub_copy(
sprout::get_internal(sprout::fixed::random_swap(cont, sprout::forward<UniformRandomNumberGenerator>(g))),
offset,
offset + sprout::size(cont)
);
}
} // namespace detail
//
// random_swap
//
template<typename Container, typename UniformRandomNumberGenerator>
inline SPROUT_CONSTEXPR typename sprout::fit::result_of::algorithm<Container>::type random_swap(
Container const& cont,
UniformRandomNumberGenerator&& g
)
{
return sprout::fit::detail::random_swap_impl(
cont,
sprout::forward<UniformRandomNumberGenerator>(g),
sprout::internal_begin_offset(cont)
);
}
} // namespace fit
} // namespace sprout
#endif // #ifndef SPROUT_ALGORITHM_FIT_RANDOM_SWAP_HPP

View file

@ -0,0 +1,75 @@
#ifndef SPROUT_ALGORITHM_FIT_RANDOM_SWAP_RESULT_HPP
#define SPROUT_ALGORITHM_FIT_RANDOM_SWAP_RESULT_HPP
#include <sprout/config.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/algorithm/fixed/random_swap_result.hpp>
#include <sprout/algorithm/fit/result_of.hpp>
#include <sprout/sub_array.hpp>
namespace sprout {
namespace fit {
namespace detail {
template<typename Container, typename UniformRandomNumberGenerator, typename Shuffled>
inline SPROUT_CONSTEXPR sprout::tuples::tuple<
typename sprout::fit::result_of::algorithm<Container>::type,
typename std::decay<UniformRandomNumberGenerator>::type
> random_swap_result_impl_1(
Shuffled const& random_swapd,
typename sprout::container_traits<Container>::difference_type offset
)
{
typedef sprout::tuples::tuple<
typename sprout::fit::result_of::algorithm<Container>::type,
typename std::decay<UniformRandomNumberGenerator>::type
> result_type;
return result_type(
sprout::sub_copy(
sprout::get_internal(sprout::tuples::get<0>(random_swapd)),
offset,
offset + sprout::size(sprout::tuples::get<0>(random_swapd))
),
sprout::tuples::get<1>(random_swapd)
);
}
template<typename Container, typename UniformRandomNumberGenerator>
inline SPROUT_CONSTEXPR sprout::tuples::tuple<
typename sprout::fit::result_of::algorithm<Container>::type,
typename std::decay<UniformRandomNumberGenerator>::type
> random_swap_result_impl(
Container const& cont,
UniformRandomNumberGenerator&& g,
typename sprout::container_traits<Container>::difference_type offset
)
{
return sprout::fit::detail::random_swap_result_impl_1<Container, UniformRandomNumberGenerator>(
sprout::fixed::random_swap_result(cont, sprout::forward<UniformRandomNumberGenerator>(g)),
offset
);
}
} // namespace detail
//
// random_swap_result
//
template<typename Container, typename UniformRandomNumberGenerator>
inline SPROUT_CONSTEXPR sprout::tuples::tuple<
typename sprout::fit::result_of::algorithm<Container>::type,
typename std::decay<UniformRandomNumberGenerator>::type
> random_swap_result(
Container const& cont,
UniformRandomNumberGenerator&& g
)
{
return sprout::fit::detail::random_swap_result_impl(
cont,
sprout::forward<UniformRandomNumberGenerator>(g),
sprout::internal_begin_offset(cont)
);
}
} // namespace fit
} // namespace sprout
#endif // #ifndef SPROUT_ALGORITHM_FIT_RANDOM_SWAP_RESULT_HPP

View file

@ -50,7 +50,11 @@
#include <sprout/algorithm/fixed/prev_permutation.hpp>
#include <sprout/algorithm/fixed/swap_element.hpp>
#include <sprout/algorithm/fixed/swap_element_copy.hpp>
#include <sprout/algorithm/fixed/random_swap.hpp>
#include <sprout/algorithm/fixed/random_swap_result.hpp>
#include <sprout/algorithm/fixed/bogo_sort.hpp>
#include <sprout/algorithm/fixed/bogo_sort_result.hpp>
#include <sprout/algorithm/fixed/bozo_sort.hpp>
#include <sprout/algorithm/fixed/bozo_sort_result.hpp>
#endif // #ifndef SPROUT_ALGORITHM_FIXED_HPP

View file

@ -8,7 +8,7 @@
#include <sprout/iterator/operation.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/algorithm/fixed/result_of.hpp>
#include <sprout/algorithm/fixed/shuffle.hpp>
#include <sprout/algorithm/fixed/shuffle_result.hpp>
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT

View file

@ -9,7 +9,7 @@
#include <sprout/iterator/operation.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/algorithm/fixed/result_of.hpp>
#include <sprout/algorithm/fixed/shuffle.hpp>
#include <sprout/algorithm/fixed/shuffle_result.hpp>
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT

View file

@ -0,0 +1,98 @@
#ifndef SPROUT_ALGORITHM_FIXED_BOZO_SORT_HPP
#define SPROUT_ALGORITHM_FIXED_BOZO_SORT_HPP
#include <sprout/config.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/iterator/operation.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/algorithm/fixed/result_of.hpp>
#include <sprout/algorithm/fixed/random_swap_result.hpp>
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT
namespace sprout {
namespace fixed {
namespace detail {
template<typename Container, typename Shuffled, typename Compare>
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Container>::type bozo_sort_impl_1(
Shuffled const& shuffled,
Compare comp
)
{
return NS_SSCRISK_CEL_OR_SPROUT::is_sorted(
sprout::begin(sprout::tuples::get<0>(shuffled)),
sprout::end(sprout::tuples::get<0>(shuffled)),
comp
)
? sprout::tuples::get<0>(shuffled)
: sprout::fixed::detail::bozo_sort_impl_1<Container>(
sprout::fixed::random_swap_result(
sprout::tuples::get<0>(shuffled),
sprout::tuples::get<1>(shuffled)
),
comp
)
;
}
template<typename Container, typename UniformRandomNumberGenerator, typename Compare>
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Container>::type bozo_sort_impl(
Container const& cont,
UniformRandomNumberGenerator&& g,
Compare comp
)
{
return NS_SSCRISK_CEL_OR_SPROUT::is_sorted(
sprout::begin(cont),
sprout::end(cont),
comp
)
? sprout::deep_copy(cont)
: sprout::fixed::detail::bozo_sort_impl_1<Container>(
sprout::fixed::random_swap_result(
cont,
sprout::forward<UniformRandomNumberGenerator>(g)
),
comp
)
;
}
} // namespace detail
//
// bozo_sort
//
template<typename Container, typename UniformRandomNumberGenerator, typename Compare>
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Container>::type bozo_sort(
Container const& cont,
UniformRandomNumberGenerator&& g,
Compare comp
)
{
return sprout::fixed::detail::bozo_sort_impl(
cont,
sprout::forward<UniformRandomNumberGenerator>(g),
comp
);
}
//
// bozo_sort
//
template<typename Container, typename UniformRandomNumberGenerator>
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Container>::type bozo_sort(
Container const& cont,
UniformRandomNumberGenerator&& g
)
{
return sprout::fixed::detail::bozo_sort_impl(
cont,
sprout::forward<UniformRandomNumberGenerator>(g),
NS_SSCRISK_CEL_OR_SPROUT::less<typename sprout::container_traits<Container>::value_type>()
);
}
} // namespace fixed
using sprout::fixed::bozo_sort;
} // namespace sprout
#endif // #ifndef SPROUT_ALGORITHM_FIXED_BOZO_SORT_HPP

View file

@ -0,0 +1,118 @@
#ifndef SPROUT_ALGORITHM_FIXED_BOZO_SORT_RESULT_HPP
#define SPROUT_ALGORITHM_FIXED_BOZO_SORT_RESULT_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/iterator/operation.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/algorithm/fixed/result_of.hpp>
#include <sprout/algorithm/fixed/random_swap_result.hpp>
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT
namespace sprout {
namespace fixed {
namespace detail {
template<typename Container, typename UniformRandomNumberGenerator, typename Shuffled, typename Compare>
inline SPROUT_CONSTEXPR sprout::tuples::tuple<
typename sprout::fixed::result_of::algorithm<Container>::type,
typename std::decay<UniformRandomNumberGenerator>::type
> bozo_sort_result_impl_1(
Shuffled const& shuffled,
Compare comp
)
{
return NS_SSCRISK_CEL_OR_SPROUT::is_sorted(
sprout::begin(sprout::tuples::get<0>(shuffled)),
sprout::end(sprout::tuples::get<0>(shuffled)),
comp
)
? shuffled
: sprout::fixed::detail::bozo_sort_result_impl_1<Container, UniformRandomNumberGenerator>(
sprout::fixed::random_swap_result(
sprout::tuples::get<0>(shuffled),
sprout::tuples::get<1>(shuffled)
),
comp
)
;
}
template<typename Container, typename UniformRandomNumberGenerator, typename Compare>
inline SPROUT_CONSTEXPR sprout::tuples::tuple<
typename sprout::fixed::result_of::algorithm<Container>::type,
typename std::decay<UniformRandomNumberGenerator>::type
> bozo_sort_result_impl(
Container const& cont,
UniformRandomNumberGenerator&& g,
Compare comp
)
{
typedef sprout::tuples::tuple<
typename sprout::fixed::result_of::algorithm<Container>::type,
typename std::decay<UniformRandomNumberGenerator>::type
> result_type;
return NS_SSCRISK_CEL_OR_SPROUT::is_sorted(
sprout::begin(cont),
sprout::end(cont),
comp
)
? result_type(
sprout::deep_copy(cont),
sprout::forward<UniformRandomNumberGenerator>(g)
)
: sprout::fixed::detail::bozo_sort_result_impl_1<Container, UniformRandomNumberGenerator>(
sprout::fixed::random_swap_result(
cont,
sprout::forward<UniformRandomNumberGenerator>(g)
),
comp
)
;
}
} // namespace detail
//
// bozo_sort_result
//
template<typename Container, typename UniformRandomNumberGenerator, typename Compare>
inline SPROUT_CONSTEXPR sprout::tuples::tuple<
typename sprout::fixed::result_of::algorithm<Container>::type,
typename std::decay<UniformRandomNumberGenerator>::type
> bozo_sort_result(
Container const& cont,
UniformRandomNumberGenerator&& g,
Compare comp
)
{
return sprout::fixed::detail::bozo_sort_result_impl(
cont,
sprout::forward<UniformRandomNumberGenerator>(g),
comp
);
}
//
// bozo_sort_result
//
template<typename Container, typename UniformRandomNumberGenerator>
inline SPROUT_CONSTEXPR sprout::tuples::tuple<
typename sprout::fixed::result_of::algorithm<Container>::type,
typename std::decay<UniformRandomNumberGenerator>::type
> bozo_sort_result(
Container const& cont,
UniformRandomNumberGenerator&& g
)
{
return sprout::fixed::detail::bozo_sort_result_impl(
cont,
sprout::forward<UniformRandomNumberGenerator>(g),
NS_SSCRISK_CEL_OR_SPROUT::less<typename sprout::container_traits<Container>::value_type>()
);
}
} // namespace fixed
using sprout::fixed::bozo_sort_result;
} // namespace sprout
#endif // #ifndef SPROUT_ALGORITHM_FIXED_BOZO_SORT_RESULT_HPP

View file

@ -0,0 +1,100 @@
#ifndef SPROUT_ALGORITHM_FIXED_RANDOM_SWAP_HPP
#define SPROUT_ALGORITHM_FIXED_RANDOM_SWAP_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/array.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/iterator/operation.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/algorithm/fixed/result_of.hpp>
#include <sprout/algorithm/fixed/swap_element.hpp>
#include <sprout/random/uniform_int_distribution.hpp>
namespace sprout {
namespace fixed {
namespace detail {
template<typename Random>
inline SPROUT_CONSTEXPR sprout::array<std::ptrdiff_t, 2> make_random_swap_indexes_2(
Random const& rnd,
std::ptrdiff_t i0
)
{
return sprout::array<std::ptrdiff_t, 2>{{i0, rnd.result()}};
}
template<typename Random>
inline SPROUT_CONSTEXPR sprout::array<std::ptrdiff_t, 2> make_random_swap_indexes_1(
Random const& rnd
)
{
return sprout::fixed::detail::make_random_swap_indexes_2(
rnd(),
rnd.result()
);
}
template<typename UniformRandomNumberGenerator>
inline SPROUT_CONSTEXPR sprout::array<std::ptrdiff_t, 2> make_random_swap_indexes(
std::ptrdiff_t n,
UniformRandomNumberGenerator&& g
)
{
return n > 1
? sprout::fixed::detail::make_random_swap_indexes_1(
sprout::random::uniform_int_distribution<std::ptrdiff_t>(0, n - 1)(sprout::forward<UniformRandomNumberGenerator>(g))
)
: sprout::array<std::ptrdiff_t, 2>{{}}
;
}
template<typename Container, typename RandomSwapped>
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Container>::type random_swap_impl_1(
Container const& cont,
RandomSwapped const& random_swapped
)
{
return random_swapped[0] == random_swapped[1]
? sprout::deep_copy(cont)
: sprout::fixed::swap_element(
cont,
sprout::next(sprout::begin(cont), random_swapped[0]),
sprout::next(sprout::begin(cont), random_swapped[1])
)
;
}
template<typename Container, typename UniformRandomNumberGenerator>
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Container>::type random_swap_impl(
Container const& cont,
UniformRandomNumberGenerator&& g,
typename sprout::container_traits<Container>::size_type size
)
{
return sprout::fixed::detail::random_swap_impl_1(
cont,
sprout::fixed::detail::make_random_swap_indexes(
size,
sprout::forward<UniformRandomNumberGenerator>(g)
)
);
}
} // namespace detail
//
// random_swap
//
template<typename Container, typename UniformRandomNumberGenerator>
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Container>::type random_swap(
Container const& cont,
UniformRandomNumberGenerator&& g
)
{
return sprout::fixed::detail::random_swap_impl(
cont,
sprout::forward<UniformRandomNumberGenerator>(g),
sprout::size(cont)
);
}
} // namespace fixed
using sprout::fixed::random_swap;
} // namespace sprout
#endif // #ifndef SPROUT_ALGORITHM_FIXED_RANDOM_SWAP_HPP

View file

@ -0,0 +1,144 @@
#ifndef SPROUT_ALGORITHM_FIXED_RANDOM_SWAP_RESULT_HPP
#define SPROUT_ALGORITHM_FIXED_RANDOM_SWAP_RESULT_HPP
#include <cstddef>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/array.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/iterator/operation.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/algorithm/fixed/result_of.hpp>
#include <sprout/algorithm/fixed/swap_element.hpp>
#include <sprout/random/uniform_int_distribution.hpp>
namespace sprout {
namespace fixed {
namespace detail {
template<typename UniformRandomNumberGenerator, typename Random>
inline SPROUT_CONSTEXPR sprout::tuples::tuple<
sprout::array<std::ptrdiff_t, 2>,
typename std::decay<UniformRandomNumberGenerator>::type
> make_random_swap_result_indexes_2(
Random const& rnd,
std::ptrdiff_t i0
)
{
typedef sprout::tuples::tuple<
sprout::array<std::ptrdiff_t, 2>,
typename std::decay<UniformRandomNumberGenerator>::type
> result_type;
return result_type(
sprout::array<std::ptrdiff_t, 2>{{i0, rnd.result()}},
rnd.engine()
);
}
template<typename UniformRandomNumberGenerator, typename Random>
inline SPROUT_CONSTEXPR sprout::tuples::tuple<
sprout::array<std::ptrdiff_t, 2>,
typename std::decay<UniformRandomNumberGenerator>::type
> make_random_swap_result_indexes_1(
Random const& rnd
)
{
return sprout::fixed::detail::make_random_swap_result_indexes_2<UniformRandomNumberGenerator>(
rnd(),
rnd.result()
);
}
template<typename UniformRandomNumberGenerator>
inline SPROUT_CONSTEXPR sprout::tuples::tuple<
sprout::array<std::ptrdiff_t, 2>,
typename std::decay<UniformRandomNumberGenerator>::type
> make_random_swap_result_indexes(
std::ptrdiff_t n,
UniformRandomNumberGenerator&& g
)
{
typedef sprout::tuples::tuple<
sprout::array<std::ptrdiff_t, 2>,
typename std::decay<UniformRandomNumberGenerator>::type
> result_type;
return n > 1
? sprout::fixed::detail::make_random_swap_result_indexes_1<UniformRandomNumberGenerator>(
sprout::random::uniform_int_distribution<std::ptrdiff_t>(0, n - 1)(sprout::forward<UniformRandomNumberGenerator>(g))
)
: result_type(
sprout::array<std::ptrdiff_t, 2>{{}},
sprout::forward<UniformRandomNumberGenerator>(g)
)
;
}
template<typename UniformRandomNumberGenerator, typename Container, typename RandomSwapped>
inline SPROUT_CONSTEXPR sprout::tuples::tuple<
typename sprout::fixed::result_of::algorithm<Container>::type,
typename std::decay<UniformRandomNumberGenerator>::type
> random_swap_result_impl_1(
Container const& cont,
RandomSwapped const& random_swapped
)
{
typedef sprout::tuples::tuple<
typename sprout::fixed::result_of::algorithm<Container>::type,
typename std::decay<UniformRandomNumberGenerator>::type
> result_type;
return sprout::tuples::get<0>(random_swapped)[0] == sprout::tuples::get<0>(random_swapped)[1]
? result_type(
sprout::deep_copy(cont),
sprout::tuples::get<1>(random_swapped)
)
: result_type(
sprout::fixed::swap_element(
cont,
sprout::next(sprout::begin(cont), sprout::tuples::get<0>(random_swapped)[0]),
sprout::next(sprout::begin(cont), sprout::tuples::get<0>(random_swapped)[1])
),
sprout::tuples::get<1>(random_swapped)
)
;
}
template<typename Container, typename UniformRandomNumberGenerator>
inline SPROUT_CONSTEXPR sprout::tuples::tuple<
typename sprout::fixed::result_of::algorithm<Container>::type,
typename std::decay<UniformRandomNumberGenerator>::type
> random_swap_result_impl(
Container const& cont,
UniformRandomNumberGenerator&& g,
typename sprout::container_traits<Container>::size_type size
)
{
return sprout::fixed::detail::random_swap_result_impl_1<UniformRandomNumberGenerator>(
cont,
sprout::fixed::detail::make_random_swap_result_indexes(
size,
sprout::forward<UniformRandomNumberGenerator>(g)
)
);
}
} // namespace detail
//
// random_swap_result
//
template<typename Container, typename UniformRandomNumberGenerator>
inline SPROUT_CONSTEXPR sprout::tuples::tuple<
typename sprout::fixed::result_of::algorithm<Container>::type,
typename std::decay<UniformRandomNumberGenerator>::type
> random_swap_result(
Container const& cont,
UniformRandomNumberGenerator&& g
)
{
return sprout::fixed::detail::random_swap_result_impl(
cont,
sprout::forward<UniformRandomNumberGenerator>(g),
sprout::size(cont)
);
}
} // namespace fixed
using sprout::fixed::random_swap_result;
} // namespace sprout
#endif // #ifndef SPROUT_ALGORITHM_FIXED_RANDOM_SWAP_RESULT_HPP

View file

@ -2,7 +2,6 @@
#define SPROUT_ALGORITHM_FIXED_SHUFFLE_HPP
#include <cstddef>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/index_tuple.hpp>
#include <sprout/array.hpp>
@ -43,7 +42,7 @@ namespace sprout {
UniformRandomNumberGenerator&& g
)
{
return n > 0
return n > 1
? sprout::fixed::detail::make_shuffle_indexes_1(
n,
sprout::random::uniform_int_distribution<std::ptrdiff_t>(0, n - 1)(sprout::forward<UniformRandomNumberGenerator>(g)),

View file

@ -61,7 +61,7 @@ namespace sprout {
sprout::array<std::ptrdiff_t, N>,
typename std::decay<UniformRandomNumberGenerator>::type
> result_type;
return n > 0
return n > 1
? sprout::fixed::detail::make_shuffle_result_indexes_1<UniformRandomNumberGenerator>(
n,
sprout::random::uniform_int_distribution<std::ptrdiff_t>(0, n - 1)(sprout::forward<UniformRandomNumberGenerator>(g)),

View file

@ -0,0 +1,8 @@
#ifndef SPROUT_ALGORITHM_RANDOM_SWAP_HPP
#define SPROUT_ALGORITHM_RANDOM_SWAP_HPP
#include <sprout/config.hpp>
#include <sprout/algorithm/fixed/random_swap.hpp>
#include <sprout/algorithm/fit/random_swap.hpp>
#endif // #ifndef SPROUT_ALGORITHM_RANDOM_SWAP_HPP

View file

@ -0,0 +1,8 @@
#ifndef SPROUT_ALGORITHM_RANDOM_SWAP_RESULT_HPP
#define SPROUT_ALGORITHM_RANDOM_SWAP_RESULT_HPP
#include <sprout/config.hpp>
#include <sprout/algorithm/fixed/random_swap_result.hpp>
#include <sprout/algorithm/fit/random_swap_result.hpp>
#endif // #ifndef SPROUT_ALGORITHM_RANDOM_SWAP_RESULT_HPP

View file

@ -24,7 +24,7 @@ namespace sprout {
struct private_type_ {
public:
SPROUT_CONSTEXPR private_type_ operator,(int) const; //!!!!
SPROUT_CONSTEXPR private_type_ operator,(int) const; //!!!
};
template<typename T>