3 // Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
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
8 // Foundation; either version 3, or (at your option) any later
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.
16 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
21 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
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
33 * @file multimap_find_test.hpp
34 * Contains a generic multimap_find_test test.
37 #ifndef PB_DS_MULTIMAP_INSERT_TEST_HPP
38 #define PB_DS_MULTIMAP_INSERT_TEST_HPP
40 #include <performance/time/timing_test_base.hpp>
41 #include <performance/io/xml_formatter.hpp>
42 #include <common_type/assoc/string_form.hpp>
51 template<typename It, class Cntnr, bool Native>
52 class multimap_find_functor
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)
60 operator()(std::size_t resolution)
62 size_t not_found_count = 0;
63 typedef typename Cntnr::point_const_iterator iterator_type;
64 for (std::size_t i = 0; i < resolution; ++i)
66 iterator_type end = m_r_container.end();
67 for (It fnd_it = m_fnd_it_b; fnd_it != m_fnd_it_e; ++fnd_it)
69 iterator_type it = m_r_container.find(fnd_it->first);
71 it->second.find(fnd_it->second) == it->second.end())
76 if (not_found_count != 0)
81 const Cntnr& m_r_container;
86 template<typename It, class Cntnr>
87 class multimap_find_functor<It, Cntnr, true>
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)
95 operator()(std::size_t resolution)
97 typedef typename Cntnr::const_reference const_reference;
98 size_t not_found_count = 0;
99 for (std::size_t i = 0; i < resolution; ++i)
102 for (It fnd_it = m_fnd_it_b; fnd_it != m_fnd_it_e; ++fnd_it)
103 if (m_r_container.find(const_reference(*fnd_it))
104 == m_r_container.end())
108 if (not_found_count != 0)
113 const Cntnr& m_r_container;
117 } // namespace detail
120 template<typename It, bool Native>
121 class multimap_find_test
122 : private __gnu_pbds::test::detail::timing_test_base
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)
129 template<typename Cntnr>
134 multimap_find_test(const multimap_find_test&);
136 template<typename Cntnr>
138 init(It ins_b, It ins_e, Cntnr, __gnu_pbds::detail::true_type)
139 { return Cntnr(ins_b, ins_e); }
141 template<typename Cntnr>
143 init(It ins_b, It ins_e, Cntnr, __gnu_pbds::detail::false_type)
146 for (It it = ins_b; it != ins_e; ++it)
147 ret[it->first].insert(it->second);
152 const size_t m_ins_vn;
153 const size_t m_ins_vs;
154 const size_t m_ins_vm;
158 template<typename It, bool Native>
159 template<typename Cntnr>
161 multimap_find_test<It, Native>::
164 typedef xml_result_set_performance_formatter formatter_type;
165 formatter_type res_set_fmt(string_form<Cntnr>::name(),
166 string_form<Cntnr>::desc());
168 for (size_t i = 0; m_ins_vn + i * m_ins_vs < m_ins_vm; ++i)
170 const size_t v = m_ins_vn + i * m_ins_vs;
171 It ins_it_b = m_ins_b;
172 It ins_it_e = m_ins_b;
173 std::advance(ins_it_e, v);
175 Cntnr c = init(ins_it_b, ins_it_e, Cntnr(),
176 __gnu_pbds::detail::integral_constant<int,Native>());
178 __gnu_pbds::test::detail::multimap_find_functor<It, Cntnr, Native>
179 fn(c, ins_it_b, ins_it_e);
182 __gnu_pbds::test::detail::timing_test_base::operator()(fn);
184 res_set_fmt.add_res(v, res / v);
188 } // namespace __gnu_pbds