3 // Copyright (C) 2005, 2006 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 2, 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 COPYING. If not, write to
18 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19 // MA 02111-1307, USA.
21 // As a special exception, you may use this file as part of a free
22 // software library without restriction. Specifically, if other files
23 // instantiate templates or use macros or inline functions from this
24 // file, or you compile this file and link it with other files to
25 // produce an executable, this file does not by itself cause the
26 // resulting executable to be covered by the GNU General Public
27 // License. This exception does not however invalidate any other
28 // reasons why the executable file might be covered by the GNU General
31 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
33 // Permission to use, copy, modify, sell, and distribute this software
34 // is hereby granted without fee, provided that the above copyright
35 // notice appears in all copies, and that both that copyright notice
36 // and this permission notice appear in supporting documentation. None
37 // of the above authors, nor IBM Haifa Research Laboratories, make any
38 // representation about the suitability of this software for any
39 // purpose. It is provided "as is" without express or implied
43 * @file tree_split_join_test.hpp
44 * Contains a test for splitting and joining trees
47 #ifndef PB_DS_TREE_SPLIT_JOIN_TEST_HPP
48 #define PB_DS_TREE_SPLIT_JOIN_TEST_HPP
50 #include <performance/time/timing_test_base.hpp>
51 #include <performance/io/xml_formatter.hpp>
52 #include <common_type/assoc/string_form.hpp>
61 template<typename Cntnr
, bool Support_Split_Join
>
62 class split_join_functor
65 split_join_functor(Cntnr
& r_container
) : m_r_container(r_container
)
69 operator()(std::size_t resolution
)
71 for (std::size_t i
= 0; i
< resolution
; ++i
)
73 typename
Cntnr::const_iterator mid_it
= m_r_container
.begin();
74 std::advance(mid_it
, m_r_container
.size() / 2);
76 m_r_container
.split(*mid_it
, other
);
77 m_r_container
.join(other
);
85 template<typename Cntnr
>
86 class split_join_functor
<Cntnr
, false>
89 split_join_functor(Cntnr
& r_container
) : m_r_container(r_container
)
93 operator()(std::size_t resolution
)
95 for (std::size_t i
= 0; i
< resolution
; ++i
)
97 typename
Cntnr::iterator mid_it
= m_r_container
.begin();
98 std::advance(mid_it
, m_r_container
.size() / 2);
100 Cntnr
other(mid_it
, m_r_container
.end());
101 m_r_container
.erase(mid_it
, m_r_container
.end());
103 m_r_container
.insert(other
.begin(), other
.end());
109 Cntnr
& m_r_container
;
111 } // namespace detail
113 template<bool Support_Split_Join
>
114 class tree_split_join_test
: private __gnu_pbds::test::detail::timing_test_base
117 tree_split_join_test(size_t vn
, size_t vs
, size_t vm
);
119 template<typename Cntnr
>
124 tree_split_join_test(const tree_split_join_test
& );
132 template<bool Support_Split_Join
>
133 tree_split_join_test
<Support_Split_Join
>::
134 tree_split_join_test(size_t vn
, size_t vs
, size_t vm
) :
140 template<bool Support_Split_Join
>
141 template<typename Cntnr
>
143 tree_split_join_test
<Support_Split_Join
>::
146 typedef xml_result_set_performance_formatter formatter_type
;
147 formatter_type
res_set_fmt(string_form
<Cntnr
>::name(),
148 string_form
<Cntnr
>::desc());
150 for (size_t v
= m_vn
; v
< m_vm
; v
+= m_vs
)
153 for (size_t ins
= 0; ins
< v
; ++ ins
)
154 cntnr
.insert((typename
Cntnr::value_type
)ins
);
156 __gnu_pbds::test::detail::split_join_functor
<Cntnr
, Support_Split_Join
>
160 __gnu_pbds::test::detail::timing_test_base::operator()(fn
);
161 res_set_fmt
.add_res(v
, res
);
165 } // namespace __gnu_pbds