]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | ////////////////////////////////////////////////////////////////////////////// |
2 | // | |
3 | // (C) Copyright Ion Gaztanaga 2015-2016. | |
4 | // Distributed under the Boost Software License, Version 1.0. | |
5 | // (See accompanying file LICENSE_1_0.txt or copy at | |
6 | // http://www.boost.org/LICENSE_1_0.txt) | |
7 | // | |
8 | // See http://www.boost.org/libs/move for documentation. | |
9 | // | |
10 | ////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #include <cstdlib> //std::srand | |
7c673cae FG |
13 | #include <iostream> //std::cout |
14 | ||
15 | #include <boost/config.hpp> | |
16 | ||
17 | #include <boost/move/unique_ptr.hpp> | |
18 | #include <boost/container/vector.hpp> | |
7c673cae FG |
19 | |
20 | #include "order_type.hpp" | |
b32b8144 | 21 | #include "random_shuffle.hpp" |
7c673cae FG |
22 | |
23 | #include <boost/move/algo/adaptive_sort.hpp> | |
24 | #include <boost/move/core.hpp> | |
25 | ||
26 | template<class T> | |
27 | bool test_random_shuffled(std::size_t const element_count, std::size_t const num_keys, std::size_t const num_iter) | |
28 | { | |
29 | boost::movelib::unique_ptr<T[]> elements(new T[element_count]); | |
30 | boost::movelib::unique_ptr<std::size_t[]> key_reps(new std::size_t[num_keys ? num_keys : element_count]); | |
31 | std::cout << "- - N: " << element_count << ", Keys: " << num_keys << ", It: " << num_iter << " \n"; | |
32 | ||
33 | //Initialize keys | |
34 | for(std::size_t i=0; i < element_count; ++i){ | |
35 | std::size_t key = num_keys ? (i % num_keys) : i; | |
36 | elements[i].key=key; | |
37 | } | |
38 | ||
39 | std::srand(0); | |
40 | ||
41 | for (std::size_t i = 0; i != num_iter; ++i) | |
42 | { | |
b32b8144 | 43 | ::random_shuffle(elements.get(), elements.get() + element_count); |
7c673cae FG |
44 | for(std::size_t i = 0; i < (num_keys ? num_keys : element_count); ++i){ |
45 | key_reps[i]=0; | |
46 | } | |
47 | for(std::size_t i = 0; i < element_count; ++i){ | |
48 | elements[i].val = key_reps[elements[i].key]++; | |
49 | } | |
50 | ||
b32b8144 | 51 | boost::movelib::adaptive_sort(elements.get(), elements.get()+element_count, order_type_less()); |
7c673cae | 52 | |
b32b8144 | 53 | if (!is_order_type_ordered(elements.get(), element_count)) |
7c673cae FG |
54 | { |
55 | std::cout << "\n ERROR\n"; | |
56 | throw int(0); | |
57 | } | |
58 | } | |
59 | return true; | |
60 | } | |
61 | ||
62 | int main() | |
63 | { | |
7c673cae | 64 | const std::size_t NIter = 100; |
b32b8144 FG |
65 | test_random_shuffled<order_move_type>(10001, 3, NIter); |
66 | test_random_shuffled<order_move_type>(10001, 65, NIter); | |
67 | test_random_shuffled<order_move_type>(10001, 101, NIter); | |
68 | test_random_shuffled<order_move_type>(10001, 1023, NIter); | |
69 | test_random_shuffled<order_move_type>(10001, 4095, NIter); | |
70 | test_random_shuffled<order_move_type>(10001, 0, NIter); | |
7c673cae FG |
71 | |
72 | return 0; | |
73 | } |