]>
Commit | Line | Data |
---|---|---|
36fed23c | 1 | // -*- C++ -*- |
2 | ||
f1717362 | 3 | // Copyright (C) 2005-2016 Free Software Foundation, Inc. |
36fed23c | 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 | |
6bc9506f | 8 | // Foundation; either version 3, or (at your option) any later |
36fed23c | 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 | |
6bc9506f | 17 | // along with this library; see the file COPYING3. If not see |
18 | // <http://www.gnu.org/licenses/>. | |
36fed23c | 19 | |
36fed23c | 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 tree_split_join_test.hpp | |
34 | * Contains a test for splitting and joining trees | |
35 | */ | |
36 | ||
37 | #ifndef PB_DS_TREE_SPLIT_JOIN_TEST_HPP | |
38 | #define PB_DS_TREE_SPLIT_JOIN_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 | ||
b34535d7 | 45 | namespace __gnu_pbds |
36fed23c | 46 | { |
36fed23c | 47 | namespace test |
48 | { | |
36fed23c | 49 | namespace detail |
50 | { | |
36fed23c | 51 | template<typename Cntnr, bool Support_Split_Join> |
52 | class split_join_functor | |
53 | { | |
54 | public: | |
55 | split_join_functor(Cntnr& r_container) : m_r_container(r_container) | |
56 | { } | |
57 | ||
58 | void | |
59 | operator()(std::size_t resolution) | |
60 | { | |
61 | for (std::size_t i = 0; i < resolution; ++i) | |
62 | { | |
63 | typename Cntnr::const_iterator mid_it = m_r_container.begin(); | |
64 | std::advance(mid_it, m_r_container.size() / 2); | |
36fed23c | 65 | Cntnr other; |
36fed23c | 66 | m_r_container.split(*mid_it, other); |
36fed23c | 67 | m_r_container.join(other); |
68 | } | |
69 | } | |
70 | ||
71 | private: | |
72 | Cntnr& m_r_container; | |
73 | }; | |
74 | ||
75 | template<typename Cntnr> | |
ce8b0a77 | 76 | class split_join_functor<Cntnr, false> |
36fed23c | 77 | { |
78 | public: | |
79 | split_join_functor(Cntnr& r_container) : m_r_container(r_container) | |
80 | { } | |
81 | ||
82 | void | |
83 | operator()(std::size_t resolution) | |
84 | { | |
85 | for (std::size_t i = 0; i < resolution; ++i) | |
86 | { | |
87 | typename Cntnr::iterator mid_it = m_r_container.begin(); | |
88 | std::advance(mid_it, m_r_container.size() / 2); | |
89 | ||
90 | Cntnr other(mid_it, m_r_container.end()); | |
91 | m_r_container.erase(mid_it, m_r_container.end()); | |
92 | ||
93 | m_r_container.insert(other.begin(), other.end()); | |
94 | other.clear(); | |
95 | } | |
96 | } | |
97 | ||
98 | private: | |
99 | Cntnr& m_r_container; | |
100 | }; | |
36fed23c | 101 | } // namespace detail |
102 | ||
36fed23c | 103 | template<bool Support_Split_Join> |
b34535d7 | 104 | class tree_split_join_test : private __gnu_pbds::test::detail::timing_test_base |
36fed23c | 105 | { |
106 | public: | |
107 | tree_split_join_test(size_t vn, size_t vs, size_t vm); | |
108 | ||
109 | template<typename Cntnr> | |
110 | void | |
ce8b0a77 | 111 | operator()(Cntnr); |
36fed23c | 112 | |
113 | private: | |
114 | tree_split_join_test(const tree_split_join_test& ); | |
115 | ||
116 | private: | |
117 | const size_t m_vn; | |
118 | const size_t m_vs; | |
119 | const size_t m_vm; | |
120 | }; | |
121 | ||
ce8b0a77 | 122 | template<bool Support_Split_Join> |
123 | tree_split_join_test<Support_Split_Join>:: | |
36fed23c | 124 | tree_split_join_test(size_t vn, size_t vs, size_t vm) : |
125 | m_vn(vn), | |
126 | m_vs(vs), | |
127 | m_vm(vm) | |
128 | { } | |
129 | ||
ce8b0a77 | 130 | template<bool Support_Split_Join> |
36fed23c | 131 | template<typename Cntnr> |
132 | void | |
ce8b0a77 | 133 | tree_split_join_test<Support_Split_Join>:: |
134 | operator()(Cntnr) | |
36fed23c | 135 | { |
ce8b0a77 | 136 | typedef xml_result_set_performance_formatter formatter_type; |
137 | formatter_type res_set_fmt(string_form<Cntnr>::name(), | |
138 | string_form<Cntnr>::desc()); | |
36fed23c | 139 | |
140 | for (size_t v = m_vn; v < m_vm; v += m_vs) | |
141 | { | |
142 | Cntnr cntnr; | |
36fed23c | 143 | for (size_t ins = 0; ins < v; ++ ins) |
144 | cntnr.insert((typename Cntnr::value_type)ins); | |
145 | ||
b34535d7 | 146 | __gnu_pbds::test::detail::split_join_functor<Cntnr, Support_Split_Join> |
36fed23c | 147 | fn(cntnr); |
148 | ||
149 | const double res = | |
b34535d7 | 150 | __gnu_pbds::test::detail::timing_test_base::operator()(fn); |
36fed23c | 151 | res_set_fmt.add_res(v, res); |
152 | } | |
153 | } | |
36fed23c | 154 | } // namespace test |
b34535d7 | 155 | } // namespace __gnu_pbds |
36fed23c | 156 | |
ce8b0a77 | 157 | #endif |
36fed23c | 158 |