]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/unordered/test/helpers/random_values.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / unordered / test / helpers / random_values.hpp
CommitLineData
7c673cae
FG
1
2// Copyright 2005-2009 Daniel James.
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6#if !defined(BOOST_UNORDERED_TEST_HELPERS_RANDOM_VALUES_HEADER)
7#define BOOST_UNORDERED_TEST_HELPERS_RANDOM_VALUES_HEADER
8
9#include "./list.hpp"
10#include <algorithm>
11#include <boost/detail/select_type.hpp>
12#include "./generators.hpp"
13#include "./metafunctions.hpp"
14
15namespace test
16{
17 template <class X>
18 struct unordered_generator_set
19 {
20 typedef BOOST_DEDUCED_TYPENAME X::value_type value_type;
21
22 random_generator type_;
23
24 unordered_generator_set(random_generator type)
25 : type_(type) {}
26
27 template <class T>
28 void fill(T& x, std::size_t len) {
29 value_type* value_ptr = 0;
30 len += x.size();
31
32 for (std::size_t i = 0; i < len; ++i) {
33 value_type value = generate(value_ptr, type_);
34
35 std::size_t count = type_ == generate_collisions ?
36 random_value(5) + 1 : 1;
37
38 for(std::size_t j = 0; j < count; ++j) {
39 x.push_back(value);
40 }
41 }
42 }
43 };
44
45 template <class X>
46 struct unordered_generator_map
47 {
48 typedef BOOST_DEDUCED_TYPENAME X::key_type key_type;
49 typedef BOOST_DEDUCED_TYPENAME X::mapped_type mapped_type;
50
51 random_generator type_;
52
53 unordered_generator_map(random_generator type)
54 : type_(type) {}
55
56 template <class T>
57 void fill(T& x, std::size_t len) {
58 key_type* key_ptr = 0;
59 mapped_type* mapped_ptr = 0;
60
61 for (std::size_t i = 0; i < len; ++i) {
62 key_type key = generate(key_ptr, type_);
63
64 std::size_t count = type_ == generate_collisions ?
65 random_value(5) + 1 : 1;
66
67 for(std::size_t j = 0; j < count; ++j) {
68 x.push_back(std::pair<key_type const, mapped_type>(
69 key, generate(mapped_ptr, type_)));
70 }
71 }
72 }
73 };
74
75 template <class X>
76 struct unordered_generator_base
77 : public boost::detail::if_true<
78 test::is_set<X>::value
79 >::BOOST_NESTED_TEMPLATE then<
80 test::unordered_generator_set<X>,
81 test::unordered_generator_map<X>
82 >
83 {
84 };
85
86 template <class X>
87 struct unordered_generator : public unordered_generator_base<X>::type
88 {
89 typedef BOOST_DEDUCED_TYPENAME unordered_generator_base<X>::type base;
90
91 unordered_generator(random_generator const& type = default_generator)
92 : base(type) {}
93 };
94
95 template <class X>
96 struct random_values
97 : public test::list<BOOST_DEDUCED_TYPENAME X::value_type>
98 {
99 random_values() {}
100
101 explicit random_values(std::size_t count, test::random_generator const& generator =
102 test::default_generator)
103 {
104 fill(count, generator);
105 }
106
107 void fill(std::size_t count, test::random_generator const& generator =
108 test::default_generator)
109 {
110 test::unordered_generator<X> gen(generator);
111 gen.fill(*this, count);
112 }
113 };
114}
115
116#endif