]>
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 | |
13 | #include <algorithm> //std::next_permutation | |
14 | #include <iostream> //std::cout | |
15 | ||
16 | #include <boost/config.hpp> | |
17 | ||
18 | #include <boost/move/unique_ptr.hpp> | |
19 | #include <boost/container/vector.hpp> | |
20 | #include <boost/timer/timer.hpp> | |
21 | ||
22 | using boost::timer::cpu_timer; | |
23 | using boost::timer::cpu_times; | |
24 | using boost::timer::nanosecond_type; | |
25 | ||
26 | #include "order_type.hpp" | |
27 | ||
28 | #include <boost/move/algo/adaptive_sort.hpp> | |
29 | #include <boost/move/core.hpp> | |
30 | ||
31 | template<class T> | |
32 | bool test_random_shuffled(std::size_t const element_count, std::size_t const num_keys, std::size_t const num_iter) | |
33 | { | |
34 | boost::movelib::unique_ptr<T[]> elements(new T[element_count]); | |
35 | boost::movelib::unique_ptr<std::size_t[]> key_reps(new std::size_t[num_keys ? num_keys : element_count]); | |
36 | std::cout << "- - N: " << element_count << ", Keys: " << num_keys << ", It: " << num_iter << " \n"; | |
37 | ||
38 | //Initialize keys | |
39 | for(std::size_t i=0; i < element_count; ++i){ | |
40 | std::size_t key = num_keys ? (i % num_keys) : i; | |
41 | elements[i].key=key; | |
42 | } | |
43 | ||
44 | std::srand(0); | |
45 | ||
46 | for (std::size_t i = 0; i != num_iter; ++i) | |
47 | { | |
48 | std::random_shuffle(elements.get(), elements.get() + element_count); | |
49 | for(std::size_t i = 0; i < (num_keys ? num_keys : element_count); ++i){ | |
50 | key_reps[i]=0; | |
51 | } | |
52 | for(std::size_t i = 0; i < element_count; ++i){ | |
53 | elements[i].val = key_reps[elements[i].key]++; | |
54 | } | |
55 | ||
56 | boost::container::vector<order_type> tmp(elements.get(), elements.get()+element_count); | |
57 | ||
58 | boost::movelib::adaptive_sort(tmp.data(), tmp.data()+element_count, order_type_less<order_type>()); | |
59 | ||
60 | if (!is_order_type_ordered(tmp.data(), element_count)) | |
61 | { | |
62 | std::cout << "\n ERROR\n"; | |
63 | throw int(0); | |
64 | } | |
65 | } | |
66 | return true; | |
67 | } | |
68 | ||
69 | int main() | |
70 | { | |
71 | #ifdef NDEBUG | |
72 | const std::size_t NIter = 100; | |
73 | #else | |
74 | const std::size_t NIter = 10; | |
75 | #endif | |
76 | test_random_shuffled<order_type>(10001, 65, NIter); | |
77 | test_random_shuffled<order_type>(10001, 101, NIter); | |
78 | test_random_shuffled<order_type>(10001, 1023, NIter); | |
79 | test_random_shuffled<order_type>(10001, 4095, NIter); | |
80 | test_random_shuffled<order_type>(10001, 0, NIter); | |
81 | ||
82 | return 0; | |
83 | } |