]>
Commit | Line | Data |
---|---|---|
4569a895 AT |
1 | // -*- C++ -*- |
2 | ||
a945c346 | 3 | // Copyright (C) 2005-2024 Free Software Foundation, Inc. |
4569a895 AT |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the terms | |
7 | // of the GNU General Public License as published by the Free Software | |
748086b7 | 8 | // Foundation; either version 3, or (at your option) any later |
4569a895 AT |
9 | // version. |
10 | ||
11 | // This library is distributed in the hope that it will be useful, but | |
12 | // WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | // General Public License for more details. | |
15 | ||
16 | // You should have received a copy of the GNU General Public License | |
748086b7 JJ |
17 | // along with this library; see the file COPYING3. If not see |
18 | // <http://www.gnu.org/licenses/>. | |
4569a895 | 19 | |
4569a895 AT |
20 | |
21 | // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. | |
22 | ||
23 | // Permission to use, copy, modify, sell, and distribute this software | |
24 | // is hereby granted without fee, provided that the above copyright | |
25 | // notice appears in all copies, and that both that copyright notice | |
26 | // and this permission notice appear in supporting documentation. None | |
27 | // of the above authors, nor IBM Haifa Research Laboratories, make any | |
28 | // representation about the suitability of this software for any | |
29 | // purpose. It is provided "as is" without express or implied | |
30 | // warranty. | |
31 | ||
32 | /** | |
33 | * @file multimap_find_test.hpp | |
34 | * Contains a generic multimap_find_test test. | |
35 | */ | |
36 | ||
37 | #ifndef PB_DS_MULTIMAP_INSERT_TEST_HPP | |
38 | #define PB_DS_MULTIMAP_INSERT_TEST_HPP | |
39 | ||
40 | #include <performance/time/timing_test_base.hpp> | |
41 | #include <performance/io/xml_formatter.hpp> | |
42 | #include <common_type/assoc/string_form.hpp> | |
43 | #include <iterator> | |
44 | ||
5e11f978 | 45 | namespace __gnu_pbds |
4569a895 | 46 | { |
4569a895 AT |
47 | namespace test |
48 | { | |
4569a895 AT |
49 | namespace detail |
50 | { | |
4569a895 AT |
51 | template<typename It, class Cntnr, bool Native> |
52 | class multimap_find_functor | |
53 | { | |
54 | public: | |
3441f106 BK |
55 | multimap_find_functor(const Cntnr& container, It fnd_it_b, It fnd_it_e) |
56 | : m_r_container(container), m_fnd_it_b(fnd_it_b), m_fnd_it_e(fnd_it_e) | |
4569a895 AT |
57 | { } |
58 | ||
59 | void | |
60 | operator()(std::size_t resolution) | |
61 | { | |
62 | size_t not_found_count = 0; | |
a345e45d | 63 | typedef typename Cntnr::point_const_iterator iterator_type; |
4569a895 AT |
64 | for (std::size_t i = 0; i < resolution; ++i) |
65 | { | |
3441f106 | 66 | iterator_type end = m_r_container.end(); |
4569a895 AT |
67 | for (It fnd_it = m_fnd_it_b; fnd_it != m_fnd_it_e; ++fnd_it) |
68 | { | |
3441f106 BK |
69 | iterator_type it = m_r_container.find(fnd_it->first); |
70 | if (it == end || | |
71 | it->second.find(fnd_it->second) == it->second.end()) | |
4569a895 AT |
72 | ++not_found_count; |
73 | } | |
74 | } | |
75 | ||
76 | if (not_found_count != 0) | |
4ba851b5 | 77 | std::abort(); |
4569a895 AT |
78 | } |
79 | ||
80 | private: | |
81 | const Cntnr& m_r_container; | |
4569a895 AT |
82 | const It m_fnd_it_b; |
83 | const It m_fnd_it_e; | |
84 | }; | |
85 | ||
86 | template<typename It, class Cntnr> | |
3441f106 | 87 | class multimap_find_functor<It, Cntnr, true> |
4569a895 AT |
88 | { |
89 | public: | |
3441f106 BK |
90 | multimap_find_functor(const Cntnr& container, It fnd_it_b, It fnd_it_e) |
91 | : m_r_container(container), m_fnd_it_b(fnd_it_b), m_fnd_it_e(fnd_it_e) | |
4569a895 AT |
92 | { } |
93 | ||
94 | void | |
95 | operator()(std::size_t resolution) | |
96 | { | |
3441f106 | 97 | typedef typename Cntnr::const_reference const_reference; |
4569a895 | 98 | size_t not_found_count = 0; |
4569a895 AT |
99 | for (std::size_t i = 0; i < resolution; ++i) |
100 | { | |
101 | Cntnr cntnr; | |
4569a895 | 102 | for (It fnd_it = m_fnd_it_b; fnd_it != m_fnd_it_e; ++fnd_it) |
f92ab29f | 103 | if (m_r_container.find(const_reference(*fnd_it)) |
3441f106 | 104 | == m_r_container.end()) |
4569a895 AT |
105 | ++not_found_count; |
106 | } | |
107 | ||
108 | if (not_found_count != 0) | |
4ba851b5 | 109 | std::abort(); |
4569a895 AT |
110 | } |
111 | ||
112 | private: | |
113 | const Cntnr& m_r_container; | |
4569a895 AT |
114 | const It m_fnd_it_b; |
115 | const It m_fnd_it_e; | |
116 | }; | |
4569a895 AT |
117 | } // namespace detail |
118 | ||
4569a895 AT |
119 | |
120 | template<typename It, bool Native> | |
f92ab29f | 121 | class multimap_find_test |
0c3de900 | 122 | : private __gnu_pbds::test::detail::timing_test_base |
4569a895 AT |
123 | { |
124 | public: | |
3441f106 BK |
125 | multimap_find_test(It ins_b, size_t ins_vn, size_t vs, size_t ins_vm) |
126 | : m_ins_b(ins_b), m_ins_vn(ins_vn), m_ins_vs(vs), m_ins_vm(ins_vm) | |
127 | { } | |
4569a895 AT |
128 | |
129 | template<typename Cntnr> | |
130 | void | |
3441f106 | 131 | operator()(Cntnr); |
4569a895 AT |
132 | |
133 | private: | |
3441f106 | 134 | multimap_find_test(const multimap_find_test&); |
4569a895 AT |
135 | |
136 | template<typename Cntnr> | |
137 | Cntnr | |
5e11f978 | 138 | init(It ins_b, It ins_e, Cntnr, __gnu_pbds::detail::true_type) |
3441f106 | 139 | { return Cntnr(ins_b, ins_e); } |
4569a895 AT |
140 | |
141 | template<typename Cntnr> | |
142 | Cntnr | |
5e11f978 | 143 | init(It ins_b, It ins_e, Cntnr, __gnu_pbds::detail::false_type) |
3441f106 BK |
144 | { |
145 | Cntnr ret; | |
146 | for (It it = ins_b; it != ins_e; ++it) | |
147 | ret[it->first].insert(it->second); | |
148 | return ret; | |
149 | } | |
4569a895 | 150 | |
4569a895 | 151 | const It m_ins_b; |
4569a895 AT |
152 | const size_t m_ins_vn; |
153 | const size_t m_ins_vs; | |
154 | const size_t m_ins_vm; | |
155 | }; | |
156 | ||
4569a895 | 157 | |
3441f106 | 158 | template<typename It, bool Native> |
4569a895 AT |
159 | template<typename Cntnr> |
160 | void | |
3441f106 BK |
161 | multimap_find_test<It, Native>:: |
162 | operator()(Cntnr) | |
4569a895 | 163 | { |
3441f106 BK |
164 | typedef xml_result_set_performance_formatter formatter_type; |
165 | formatter_type res_set_fmt(string_form<Cntnr>::name(), | |
166 | string_form<Cntnr>::desc()); | |
4569a895 | 167 | |
3441f106 | 168 | for (size_t i = 0; m_ins_vn + i * m_ins_vs < m_ins_vm; ++i) |
4569a895 | 169 | { |
3441f106 | 170 | const size_t v = m_ins_vn + i * m_ins_vs; |
4569a895 AT |
171 | It ins_it_b = m_ins_b; |
172 | It ins_it_e = m_ins_b; | |
173 | std::advance(ins_it_e, v); | |
174 | ||
3441f106 | 175 | Cntnr c = init(ins_it_b, ins_it_e, Cntnr(), |
5e11f978 | 176 | __gnu_pbds::detail::integral_constant<int,Native>()); |
4569a895 | 177 | |
5e11f978 | 178 | __gnu_pbds::test::detail::multimap_find_functor<It, Cntnr, Native> |
4569a895 AT |
179 | fn(c, ins_it_b, ins_it_e); |
180 | ||
181 | const double res = | |
5e11f978 | 182 | __gnu_pbds::test::detail::timing_test_base::operator()(fn); |
4569a895 AT |
183 | |
184 | res_set_fmt.add_res(v, res / v); | |
185 | } | |
186 | } | |
4569a895 | 187 | } // namespace test |
5e11f978 | 188 | } // namespace __gnu_pbds |
4569a895 | 189 | |
f92ab29f | 190 | #endif |
4569a895 | 191 |