3 // Copyright (C) 2005, 2006, 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 tree_split_join_test.hpp
34 * Contains a test for splitting and joining trees
37 #ifndef PB_DS_TREE_SPLIT_JOIN_TEST_HPP
38 #define PB_DS_TREE_SPLIT_JOIN_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 Cntnr, bool Support_Split_Join>
52 class split_join_functor
55 split_join_functor(Cntnr& r_container) : m_r_container(r_container)
59 operator()(std::size_t resolution)
61 for (std::size_t i = 0; i < resolution; ++i)
63 typename Cntnr::const_iterator mid_it = m_r_container.begin();
64 std::advance(mid_it, m_r_container.size() / 2);
66 m_r_container.split(*mid_it, other);
67 m_r_container.join(other);
75 template<typename Cntnr>
76 class split_join_functor<Cntnr, false>
79 split_join_functor(Cntnr& r_container) : m_r_container(r_container)
83 operator()(std::size_t resolution)
85 for (std::size_t i = 0; i < resolution; ++i)
87 typename Cntnr::iterator mid_it = m_r_container.begin();
88 std::advance(mid_it, m_r_container.size() / 2);
90 Cntnr other(mid_it, m_r_container.end());
91 m_r_container.erase(mid_it, m_r_container.end());
93 m_r_container.insert(other.begin(), other.end());
101 } // namespace detail
103 template<bool Support_Split_Join>
104 class tree_split_join_test : private __gnu_pbds::test::detail::timing_test_base
107 tree_split_join_test(size_t vn, size_t vs, size_t vm);
109 template<typename Cntnr>
114 tree_split_join_test(const tree_split_join_test& );
122 template<bool Support_Split_Join>
123 tree_split_join_test<Support_Split_Join>::
124 tree_split_join_test(size_t vn, size_t vs, size_t vm) :
130 template<bool Support_Split_Join>
131 template<typename Cntnr>
133 tree_split_join_test<Support_Split_Join>::
136 typedef xml_result_set_performance_formatter formatter_type;
137 formatter_type res_set_fmt(string_form<Cntnr>::name(),
138 string_form<Cntnr>::desc());
140 for (size_t v = m_vn; v < m_vm; v += m_vs)
143 for (size_t ins = 0; ins < v; ++ ins)
144 cntnr.insert((typename Cntnr::value_type)ins);
146 __gnu_pbds::test::detail::split_join_functor<Cntnr, Support_Split_Join>
150 __gnu_pbds::test::detail::timing_test_base::operator()(fn);
151 res_set_fmt.add_res(v, res);
155 } // namespace __gnu_pbds