2006-10-03 Benjamin Kosnik * testsuite/util/native_type/priority_queue/native_pq_tag.hpp: Remove. * testsuite/util/statistic/sample_var.hpp: Rename to... * testsuite/util/statistic/sample_variance.hpp: ... this. * testsuite/util/statistic/res_recorder.hpp: Rename to... * testsuite/util/statistic/result_recorder.hpp: ... this. * testsuite/util/statistic/sample_mean.hpp: Format. * testsuite/util/statistic/sample_mean_confidence_checker.hpp: Same. * testsuite/util/regression/trait/priority_queue/trait.hpp: Same. * testsuite/util/regression/trait/erase_if_fn.hpp: Same. * testsuite/util/regression/trait/assoc/trait.hpp: Same. * testsuite/util/native_type/priority_queue/ native_priority_queue.hpp: Same. * testsuite/util/native_type/assoc/native_tree_tag.hpp: Same. * testsuite/util/native_type/assoc/native_hash_tag.hpp: Same. * testsuite/util/native_type/assoc/native_hash_map.hpp: Same. * testsuite/util/performance/priority_queue/timing/join_test.hpp: Same. * testsuite/util/performance/priority_queue/timing/ modify_test.hpp: Same. * testsuite/util/performance/assoc/timing/ subscript_insert_test.hpp: Same. * testsuite/util/performance/time/timing_test_base.hpp: Same. Index: testsuite/util/regression/trait/priority_queue/trait.hpp =================================================================== --- testsuite/util/regression/trait/priority_queue/trait.hpp (revision 117392) +++ testsuite/util/regression/trait/priority_queue/trait.hpp (working copy) @@ -52,82 +52,41 @@ namespace pb_ds { - namespace test { - namespace detail { - -#define PB_DS_CLASS_T_DEC \ template - -#define PB_DS_CLASS_C_DEC \ - regression_test_traits< \ - Cntnr> - - template struct regression_test_traits { - - public: - typedef typename Cntnr::value_type value_type; - typedef typename Cntnr::const_reference const_reference; - - typedef - pb_ds::test::native_priority_queue< - std::string, - true> - native_type; - + typedef pb_ds::test::native_priority_queue native_type; typedef typename native_type::value_type native_value_type; template - struct erase_if_fn : public regression_test_erase_if_fn< - T> - { + struct erase_if_fn : public regression_test_erase_if_fn + { }; - }; - - public: - template static value_type generate_value(Gen& r_gen, size_t max) - { - return basic_type(r_gen, max); - } + { return basic_type(r_gen, max); } static native_value_type native_value(const_reference r_val) - { - return (native_value_type(r_val)); - } + { return native_value_type(r_val); } static bool cmp(const_reference r_val, const native_value_type& r_native_val) - { - return (val_to_string(r_val) == r_native_val); - } + { return val_to_string(r_val) == r_native_val; } static std::string val_to_string(const_reference r_val) - { - return (std::string(r_val)); - } - + { return std::string(r_val); } }; - -#undef PB_DS_CLASS_T_DEC - -#undef PB_DS_CLASS_C_DEC - } // namespace detail - } // namespace test - } // namespace pb_ds -#endif // #ifndef PB_DS_REGRESSION_TEST_TRAIT_HPP +#endif Index: testsuite/util/regression/trait/erase_if_fn.hpp =================================================================== --- testsuite/util/regression/trait/erase_if_fn.hpp (revision 117392) +++ testsuite/util/regression/trait/erase_if_fn.hpp (working copy) @@ -52,17 +52,13 @@ namespace pb_ds { - namespace test { - namespace detail { - template - struct regression_test_erase_if_fn : public std::unary_function< - T, - bool> + struct regression_test_erase_if_fn + : public std::unary_function { private: typedef const T& const_reference; @@ -77,35 +73,23 @@ }; template - struct regression_test_erase_if_fn< - std::pair< - Hd, - Tl> > : public std::unary_function< - std::pair< - Hd, - Tl>, - bool> + struct regression_test_erase_if_fn > + : public std::unary_function, bool> { private: typedef const std::pair& const_reference; + typedef regression_test_erase_if_fn hd_erase_if_fn; + typedef regression_test_erase_if_fn tl_erase_if_fn; - typedef regression_test_erase_if_fn< Hd> hd_erase_if_fn; - - typedef regression_test_erase_if_fn< Tl> tl_erase_if_fn; - public: bool operator()(const_reference r_t) const { - return (hd_erase_if_fn()(r_t.first)&& - tl_erase_if_fn()(r_t.second)); + return (hd_erase_if_fn()(r_t.first) && tl_erase_if_fn()(r_t.second)); } }; - } // namespace detail - } // namespace test - } // namespace pb_ds -#endif // #ifndef PB_DS_REGRESSION_TEST_ERASE_IF_FN_HPP +#endif Index: testsuite/util/regression/trait/assoc/trait.hpp =================================================================== --- testsuite/util/regression/trait/assoc/trait.hpp (revision 117392) +++ testsuite/util/regression/trait/assoc/trait.hpp (working copy) @@ -101,22 +101,15 @@ { private: typedef PB_DS_NATIVE_TYPE_TRAITS_C_DEC native_type_traits_base; - typedef PB_DS_TYPE_TRAITS_C_DEC type_traits_base; public: typedef typename Cntnr::key_type key_type; - typedef typename Cntnr::const_key_reference const_key_reference; - typedef typename Cntnr::value_type value_type; - typedef typename Cntnr::const_reference const_reference; - typedef typename PB_DS_NATIVE_TYPE_TRAITS_C_DEC::type native_type; - typedef typename native_type::key_type native_key_type; - typedef typename native_type::value_type native_value_type; enum @@ -153,73 +146,49 @@ static void print_container(const Cntnr& r_c, std::ostream& r_os) - { - PB_DS_TYPE_TRAITS_C_DEC::print_container(r_c, r_os); - } + { PB_DS_TYPE_TRAITS_C_DEC::print_container(r_c, r_os); } - public: - template static key_type generate_key(Gen& r_gen, size_t max) - { - return PB_DS_TYPE_TRAITS_C_DEC::generate_key(r_gen, max); - } + { return PB_DS_TYPE_TRAITS_C_DEC::generate_key(r_gen, max); } template static value_type generate_value(Gen& r_gen, size_t max) - { - return PB_DS_TYPE_TRAITS_C_DEC::generate_value(r_gen, max); - } + { return PB_DS_TYPE_TRAITS_C_DEC::generate_value(r_gen, max); } static const_key_reference extract_key(const_reference r_val) - { - return type_traits_base::extract_key(r_val); - } + { return type_traits_base::extract_key(r_val); } static native_key_type native_key(const_key_reference r_key) - { - return native_type_traits_base::native_key(r_key); - } + { return native_type_traits_base::native_key(r_key); } static native_value_type native_value(const_reference r_val) - { - return native_type_traits_base::native_value(r_val); - } + { return native_type_traits_base::native_value(r_val); } static const native_key_type& extract_native_key(const native_value_type& r_val) - { - return native_type_traits_base::extract_key(r_val); - } + { return native_type_traits_base::extract_key(r_val); } static bool cmp(const_reference r_val, const native_value_type& r_native_val) - { - return val_to_string(r_val) == native_val_to_string(r_native_val); - } + { return val_to_string(r_val) == native_val_to_string(r_native_val); } static std::string val_to_string(const_reference r_val) - { - return to_string(r_val); - } + { return to_string(r_val); } static std::string key_to_string(const_key_reference r_key) - { - return to_string(r_key); - } + { return to_string(r_key); } static std::string native_val_to_string(const native_value_type& r_native_val) - { - return to_string(r_native_val); - } + { return to_string(r_native_val); } static bool prefix_match(const_key_reference r_key, const std::string& r_native_key) @@ -232,7 +201,6 @@ return native_substr == (const std::string&) r_key; } - }; #undef PB_DS_TYPE_TRAITS_C_DEC Index: testsuite/util/native_type/priority_queue/native_priority_queue.hpp =================================================================== --- testsuite/util/native_type/priority_queue/native_priority_queue.hpp (revision 117392) +++ testsuite/util/native_type/priority_queue/native_priority_queue.hpp (working copy) @@ -47,87 +47,66 @@ #ifndef PB_DS_NATIVE_PRIORITY_QUEUE_HPP #define PB_DS_NATIVE_PRIORITY_QUEUE_HPP -#include -#include -#include -#include #include #include #include #include +#include +#include +#include namespace pb_ds { - namespace test { - namespace detail { - - template + template struct base_seq { - typedef - std::vector< - Value_Type, - typename Allocator::template rebind< - Value_Type>::other> - type; + private: + typedef typename Allocator::template rebind value_rebind; + + public: + typedef std::vector type; }; - template - struct base_seq< - Value_Type, - false, - Allocator> + template + struct base_seq { - typedef - std::deque< - Value_Type, - typename Allocator::template rebind< - Value_Type>::other> - type; - }; + private: + typedef typename Allocator::template rebind value_rebind; + public: + typedef std::deque type; + }; } // namespace detail -#define PB_DS_CLASS_C_DEC \ - native_priority_queue< \ - Value_Type, \ - Vector, \ - Cmp_Fn, \ - Allocator> + struct native_pq_tag + { }; -#define PB_DS_BASE_C_DEC \ - std::priority_queue< \ - Value_Type, \ - typename detail::base_seq::type, \ - Cmp_Fn> +#define PB_DS_CLASS_C_DEC \ + native_priority_queue +#define PB_DS_BASE_C_DEC \ + std::priority_queue::type, Cmp_Fn> + template, - class Allocator = std::allocator > + typename Cmp_Fn = std::less, + typename Allocator = std::allocator > class native_priority_queue : public PB_DS_BASE_C_DEC { private: typedef PB_DS_BASE_C_DEC base_type; + typedef typename Allocator::template rebind value_rebind; public: typedef Value_Type value_type; - - typedef - typename Allocator::template rebind< - value_type>::other::const_reference - const_reference; - + typedef typename value_rebind::other::const_reference const_reference; typedef native_pq_tag container_category; - typedef Cmp_Fn cmp_fn; - public: native_priority_queue() : base_type() { } @@ -140,7 +119,6 @@ { if (Vector) return ("n_pq_vector"); - return ("n_pq_deque"); } @@ -148,44 +126,36 @@ desc() { if (Vector) - return (make_xml_tag( "type", "value", "std::priority_queue_vector")); - - return (make_xml_tag( "type", "value", "std::priority_queue_deque")); + return make_xml_tag("type", "value", "std::priority_queue_vector"); + return make_xml_tag("type", "value", "std::priority_queue_deque"); } void clear() - { - * static_cast(this) = base_type(); - } + { *static_cast(this) = base_type(); } void erase(const_reference r_val) { base_type tmp; - Cmp_Fn cmp; while (cmp(base_type::top(), r_val) || cmp(r_val, base_type::top())) { tmp.push(base_type::top()); - base_type::pop(); } if (!base_type::empty()) { base_type::pop(); - while (!base_type::empty()) { tmp.push(base_type::top()); - base_type::pop(); } } - - * static_cast(this) = tmp; + *static_cast(this) = tmp; } template @@ -193,21 +163,17 @@ erase_if(Pred pred) { base_type tmp; - std::size_t ersd = 0; - while (!base_type::empty()) { if (!pred(base_type::top())) tmp.push(base_type::top()); else ++ersd; - base_type::pop(); } - * static_cast(this) = tmp; - + *static_cast(this) = tmp; return ersd; } @@ -216,27 +182,22 @@ split(Pred pred, PB_DS_CLASS_C_DEC& other) { base_type tmp; - other.clear(); - while (!base_type::empty()) { if (!pred(base_type::top())) tmp.push(base_type::top()); else other.push(base_type::top()); - base_type::pop(); } - - * static_cast(this) = tmp; + *static_cast(this) = tmp; } void modify(const_reference r_old, const_reference r_new) { erase(r_old); - push(r_new); } @@ -244,37 +205,30 @@ join(PB_DS_CLASS_C_DEC& other) { std::vector a_tmp; - while (!base_type::empty()) { a_tmp.push_back(base_type::top()); - base_type::pop(); } while (!other.empty()) { a_tmp.push_back(other.top()); - other.pop(); } - * static_cast(this) = base_type(a_tmp.begin(), a_tmp.end()); + *static_cast(this) = base_type(a_tmp.begin(), a_tmp.end()); } Cmp_Fn get_cmp_fn() const - { - return Cmp_Fn(); - } + { return Cmp_Fn(); } }; #undef PB_DS_BASE_C_DEC - #undef PB_DS_CLASS_C_DEC } // namespace test - } // namespace pb_ds -#endif // #ifndef PB_DS_NATIVE_PRIORITY_QUEUE_HPP +#endif Index: testsuite/util/native_type/priority_queue/native_pq_tag.hpp =================================================================== --- testsuite/util/native_type/priority_queue/native_pq_tag.hpp (revision 117392) +++ testsuite/util/native_type/priority_queue/native_pq_tag.hpp (working copy) @@ -1,63 +0,0 @@ -// -*- C++ -*- - -// Copyright (C) 2005, 2006 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the terms -// of the GNU General Public License as published by the Free Software -// Foundation; either version 2, or (at your option) any later -// version. - -// This library is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this library; see the file COPYING. If not, write to -// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, -// MA 02111-1307, USA. - -// As a special exception, you may use this file as part of a free -// software library without restriction. Specifically, if other files -// instantiate templates or use macros or inline functions from this -// file, or you compile this file and link it with other files to -// produce an executable, this file does not by itself cause the -// resulting executable to be covered by the GNU General Public -// License. This exception does not however invalidate any other -// reasons why the executable file might be covered by the GNU General -// Public License. - -// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. - -// Permission to use, copy, modify, sell, and distribute this software -// is hereby granted without fee, provided that the above copyright -// notice appears in all copies, and that both that copyright notice -// and this permission notice appear in supporting documentation. None -// of the above authors, nor IBM Haifa Research Laboratories, make any -// representation about the suitability of this software for any -// purpose. It is provided "as is" without express or implied -// warranty. - -/** - * @file native_tree_tag.hpp - * Contains a tag for native tree-based containers - */ - -#ifndef PB_DS_NATIVE_PQ_DS_TAG_HPP -#define PB_DS_NATIVE_PQ_DS_TAG_HPP - -namespace pb_ds -{ - - namespace test - { - - struct native_pq_tag - { }; - - } // namespace test - -} // namespace pb_ds - -#endif // #ifndef PB_DS_NATIVE_PQ_DS_TAG_HPP Index: testsuite/util/native_type/assoc/native_tree_tag.hpp =================================================================== --- testsuite/util/native_type/assoc/native_tree_tag.hpp (revision 117392) +++ testsuite/util/native_type/assoc/native_tree_tag.hpp (working copy) @@ -56,4 +56,4 @@ } // namespace test } // namespace pb_ds -#endif // #ifndef PB_DS_NATIVE_TREE_DS_TAG_HPP +#endif Index: testsuite/util/native_type/assoc/native_hash_tag.hpp =================================================================== --- testsuite/util/native_type/assoc/native_hash_tag.hpp (revision 117392) +++ testsuite/util/native_type/assoc/native_hash_tag.hpp (working copy) @@ -55,4 +55,4 @@ } // namespace test } // namespace pb_ds -#endif // #ifndef PB_DS_NATIVE_HASH_DS_TAG_HPP +#endif Index: testsuite/util/native_type/assoc/native_hash_map.hpp =================================================================== --- testsuite/util/native_type/assoc/native_hash_map.hpp (revision 117392) +++ testsuite/util/native_type/assoc/native_hash_map.hpp (working copy) @@ -134,5 +134,5 @@ } // namespace test } // namespace pb_ds -#endif // #ifndef PB_DS_NATIVE_HASH_MAP_HPP +#endif Index: testsuite/util/performance/priority_queue/timing/join_test.hpp =================================================================== --- testsuite/util/performance/priority_queue/timing/join_test.hpp (revision 117392) +++ testsuite/util/performance/priority_queue/timing/join_test.hpp (working copy) @@ -128,6 +128,9 @@ using pb_ds::test::detail::double_push_functor; using pb_ds::test::detail::double_push_join_functor; typedef pb_ds::test::detail::timing_test_base base_type; + typedef double_push_functor psh_fnct; + typedef double_push_join_functor psh_jn_fnct; + typedef xml_result_set_performance_formatter formatter_type; formatter_type res(string_form::name(), string_form::desc()); @@ -139,12 +142,12 @@ It e = m_ins_b; std::advance(e, v); - double_push_functor double_push_fn(b, e); - const double double_push_res = base_type::operator()(double_push_fn); - double_push_join_functor double_push_join_fn(b, e); - const double double_push_join_res = base_type::operator()(double_push_join_fn); - - const double effective_delta = std::max(double_push_join_res - double_push_res, base_type::min_time_res()); + psh_fnct double_push_fn(b, e); + const double dbl_psh_res = base_type::operator()(double_push_fn); + psh_jn_fnct dbl_psh_jn_fn(b, e); + const double dbl_psh_jn_res = base_type::operator()(dbl_psh_jn_fn); + const double min_res = double(timing_test_base::min_time_res()); + const double effective_delta = std::max(dbl_psh_jn_res - dbl_psh_res, min_res); res.add_res(v, effective_delta / v); } } Index: testsuite/util/performance/priority_queue/timing/modify_test.hpp =================================================================== --- testsuite/util/performance/priority_queue/timing/modify_test.hpp (revision 117392) +++ testsuite/util/performance/priority_queue/timing/modify_test.hpp (working copy) @@ -59,6 +59,7 @@ { namespace detail { + // Primary templates. template class push_functor { @@ -123,6 +124,7 @@ const value_type m_mod_val; }; + // Specializations. template class push_functor { @@ -149,6 +151,33 @@ }; template + class push_functor + { + public: + push_functor(It ins_it_b, It ins_it_e) + : m_ins_it_b(ins_it_b), m_ins_it_e(ins_it_e) + { } + + void + operator()(std::size_t resolution) + { + typedef typename Cntnr::const_reference const_reference; + for (std::size_t i = 0; i < resolution; ++i) + { + Cntnr c; + + for (It ins_it = m_ins_it_b; ins_it != m_ins_it_e; ++ins_it) + c.push(const_reference(ins_it->first)); + } + } + + private: + const It m_ins_it_b; + const It m_ins_it_e; + }; + + + template class push_modify_functor { private: @@ -191,32 +220,6 @@ }; template - class push_functor - { - public: - push_functor(It ins_it_b, It ins_it_e) - : m_ins_it_b(ins_it_b), m_ins_it_e(ins_it_e) - { } - - void - operator()(std::size_t resolution) - { - typedef typename Cntnr::const_reference const_reference; - for (std::size_t i = 0; i < resolution; ++i) - { - Cntnr c; - - for (It ins_it = m_ins_it_b; ins_it != m_ins_it_e; ++ins_it) - c.push(const_reference(ins_it->first)); - } - } - - private: - const It m_ins_it_b; - const It m_ins_it_e; - }; - - template class push_modify_functor { private: @@ -291,8 +294,9 @@ typedef typename Cntnr::value_type value_type; typedef typename Cntnr::container_category container_category; typedef typename Cntnr::const_reference const_reference; - typedef pb_ds::test::detail::timing_test_base timing_test_base; - + typedef detail::timing_test_base timing_test_base; + typedef detail::push_functor psh_fnct; + typedef detail::push_modify_functor psh_mod_fnct; typedef xml_result_set_performance_formatter formatter_type; formatter_type res_set_fmt(string_form::name(), string_form::desc()); @@ -300,15 +304,13 @@ for (size_t i = 0; m_ins_vn + i * m_ins_vs < m_ins_vm; ++i) { const size_t v = m_ins_vn + i * m_ins_vs; - It b = m_ins_b; + It b = m_ins_b; It e = m_ins_b; std::advance(e, v); - pb_ds::test::detail::push_functor - push_fn( b, e); + psh_fnct psh_fn(b, e); + const double psh_res = timing_test_base::operator()(psh_fn); - const double push_res = timing_test_base::operator()(push_fn); - value_type val = b->first; { Cntnr mod_val_container; @@ -320,14 +322,13 @@ } } - pb_ds::test::detail::push_modify_functor - push_modify_fn(b, e, val); + psh_mod_fnct psh_mod_fn(b, e, val); + const double psh_mod_res = timing_test_base::operator()(psh_mod_fn); - const double push_modify_res = timing_test_base::operator()(push_modify_fn); + const double min_res = double(timing_test_base::min_time_res()); + const double effective_delta = std::max(psh_mod_res - psh_res, + min_res); - const double effective_delta = std::max(push_modify_res - push_res, - timing_test_base::min_time_res()); - res_set_fmt.add_res(v, effective_delta / v); } } Index: testsuite/util/performance/assoc/timing/subscript_insert_test.hpp =================================================================== --- testsuite/util/performance/assoc/timing/subscript_insert_test.hpp (revision 117392) +++ testsuite/util/performance/assoc/timing/subscript_insert_test.hpp (working copy) @@ -50,7 +50,6 @@ #include #include #include -#include #include namespace pb_ds Index: testsuite/util/performance/time/timing_test_base.hpp =================================================================== --- testsuite/util/performance/time/timing_test_base.hpp (revision 117392) +++ testsuite/util/performance/time/timing_test_base.hpp (working copy) @@ -48,7 +48,7 @@ #define PB_DS_TIMING_TEST_BASE_HPP #include -#include +#include namespace pb_ds { @@ -81,12 +81,12 @@ timing_test_base::operator()(Functor& fn) { const std::size_t resolution = get_min_resolution(fn); - pb_ds::test::detail::res_recorder rec; + pb_ds::test::detail::result_recorder rec; double res; do res = run_at_resolution(fn, resolution); - while (rec.add_res(res) == false); - res = rec.sample_mean() / resolution; + while (rec.add_result(res) == false); + res = rec.get_sample_mean() / resolution; return res; } Index: testsuite/util/statistic/sample_var.hpp =================================================================== --- testsuite/util/statistic/sample_var.hpp (revision 117392) +++ testsuite/util/statistic/sample_var.hpp (working copy) @@ -1,102 +0,0 @@ -// -*- C++ -*- - -// Copyright (C) 2005, 2006 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the terms -// of the GNU General Public License as published by the Free Software -// Foundation; either version 2, or (at your option) any later -// version. - -// This library is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this library; see the file COPYING. If not, write to -// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, -// MA 02111-1307, USA. - -// As a special exception, you may use this file as part of a free -// software library without restriction. Specifically, if other files -// instantiate templates or use macros or inline functions from this -// file, or you compile this file and link it with other files to -// produce an executable, this file does not by itself cause the -// resulting executable to be covered by the GNU General Public -// License. This exception does not however invalidate any other -// reasons why the executable file might be covered by the GNU General -// Public License. - -// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. - -// Permission to use, copy, modify, sell, and distribute this software -// is hereby granted without fee, provided that the above copyright -// notice appears in all copies, and that both that copyright notice -// and this permission notice appear in supporting documentation. None -// of the above authors, nor IBM Haifa Research Laboratories, make any -// representation about the suitability of this software for any -// purpose. It is provided "as is" without express or implied -// warranty. - -/** - * @file sample_var.hpp - * Contains a function for calculating a sample variance - */ - -#ifndef PB_DS_SAMPLE_VAR_HPP -#define PB_DS_SAMPLE_VAR_HPP - -#include -#include -#include -#include - -namespace pb_ds -{ - - namespace test - { - - namespace detail - { - -#define PB_DS_VTYPE \ - typename std::iterator_traits< \ - It>::value_type - - template - PB_DS_VTYPE - sample_var(It b, It e, PB_DS_VTYPE sm) - { - PB_DS_VTYPE ss = 0; - - size_t num_res = 0; - - while (b != e) - { - const PB_DS_VTYPE d =* b - sm; - - ss += d* d; - - ++num_res; - - ++b; - } - - if (num_res == 1) - return (0); - - return (::sqrt(ss / (num_res - 1))); - } - -#undef PB_DS_VTYPE - - } // namespace detail - - } // namespace test - -} // namespace pb_ds - -#endif // #ifndef PB_DS_SAMPLE_VAR_HPP - Index: testsuite/util/statistic/sample_variance.hpp =================================================================== --- testsuite/util/statistic/sample_variance.hpp (revision 117374) +++ testsuite/util/statistic/sample_variance.hpp (working copy) @@ -40,7 +40,7 @@ // warranty. /** - * @file sample_var.hpp + * @file sample_variance.hpp * Contains a function for calculating a sample variance */ @@ -54,49 +54,38 @@ namespace pb_ds { - namespace test { - namespace detail { +#define PB_DS_VTYPE typename std::iterator_traits::value_type -#define PB_DS_VTYPE \ - typename std::iterator_traits< \ - It>::value_type - template PB_DS_VTYPE - sample_var(It b, It e, PB_DS_VTYPE sm) + sample_variance(It b, It e, PB_DS_VTYPE sm) { PB_DS_VTYPE ss = 0; - size_t num_res = 0; while (b != e) { const PB_DS_VTYPE d =* b - sm; - ss += d* d; - ++num_res; - ++b; } if (num_res == 1) - return (0); + return 0; - return (::sqrt(ss / (num_res - 1))); + return ::sqrt(ss / (num_res - 1)); } #undef PB_DS_VTYPE } // namespace detail - } // namespace test - } // namespace pb_ds -#endif // #ifndef PB_DS_SAMPLE_VAR_HPP +#endif Index: testsuite/util/statistic/res_recorder.hpp =================================================================== --- testsuite/util/statistic/res_recorder.hpp (revision 117392) +++ testsuite/util/statistic/res_recorder.hpp (working copy) @@ -1,143 +0,0 @@ -// -*- C++ -*- - -// Copyright (C) 2005, 2006 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the terms -// of the GNU General Public License as published by the Free Software -// Foundation; either version 2, or (at your option) any later -// version. - -// This library is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this library; see the file COPYING. If not, write to -// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, -// MA 02111-1307, USA. - -// As a special exception, you may use this file as part of a free -// software library without restriction. Specifically, if other files -// instantiate templates or use macros or inline functions from this -// file, or you compile this file and link it with other files to -// produce an executable, this file does not by itself cause the -// resulting executable to be covered by the GNU General Public -// License. This exception does not however invalidate any other -// reasons why the executable file might be covered by the GNU General -// Public License. - -// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. - -// Permission to use, copy, modify, sell, and distribute this software -// is hereby granted without fee, provided that the above copyright -// notice appears in all copies, and that both that copyright notice -// and this permission notice appear in supporting documentation. None -// of the above authors, nor IBM Haifa Research Laboratories, make any -// representation about the suitability of this software for any -// purpose. It is provided "as is" without express or implied -// warranty. - -/** - * @file res_recorder.hpp - * Contains a class for recording results - */ - -#ifndef PB_DS_RES_RECORDER_HPP -#define PB_DS_RES_RECORDER_HPP - -#include -#include -#include - -namespace pb_ds -{ - - namespace test - { - - namespace detail - { - -#define PB_DS_CLASS_T_DEC \ - template - -#define PB_DS_CLASS_C_DEC \ - res_recorder< \ - Value_Type> - - /* - * Records results until the probability that the sample mean is 10% away - * from the true mean is ~ 0.05. - */ - template - class res_recorder - { - public: - typedef Value_Type value_type; - - public: - res_recorder(); - - bool - add_res(value_type res); - - inline value_type - sample_mean() const; - - private: - typedef std::list< value_type> list_t; - - private: - list_t m_l; - - value_type m_sample_mean; - - value_type m_sample_var; - }; - - PB_DS_CLASS_T_DEC - PB_DS_CLASS_C_DEC:: - res_recorder() : - m_sample_mean(0) - { } - - PB_DS_CLASS_T_DEC - inline typename PB_DS_CLASS_C_DEC::value_type - PB_DS_CLASS_C_DEC:: - sample_mean() const - { - return (m_sample_mean); - } - - PB_DS_CLASS_T_DEC - bool - PB_DS_CLASS_C_DEC:: - add_res(value_type res) - { - m_l.push_back(res); - - m_sample_mean = pb_ds::test::detail::sample_mean(m_l.begin(), m_l.end()); - - const value_type sample_var = - pb_ds::test::detail::sample_var(m_l.begin(), m_l.end(), m_sample_mean); - - return (pb_ds::test::detail::sample_mean_confidence_checker(m_sample_mean, - sample_var, - std::distance(m_l.begin(), m_l.end()), - 0.1)); - } - -#undef PB_DS_CLASS_T_DEC - -#undef PB_DS_CLASS_C_DEC - - } // namespace detail - - } // namespace test - -} // namespace pb_ds - -#endif // #ifndef PB_DS_RES_RECORDER_HPP - Index: testsuite/util/statistic/sample_mean.hpp =================================================================== --- testsuite/util/statistic/sample_mean.hpp (revision 117392) +++ testsuite/util/statistic/sample_mean.hpp (working copy) @@ -54,34 +54,26 @@ namespace pb_ds { - namespace test { - namespace detail { +#define PB_DS_VTYPE typename std::iterator_traits::value_type -#define PB_DS_VTYPE \ - typename std::iterator_traits< \ - It>::value_type - template PB_DS_VTYPE sample_mean(It b, It e) { const PB_DS_VTYPE total = std::accumulate(b, e, PB_DS_VTYPE(0)); const size_t num = std::distance(b, e); - - return (total / num); + return total / num; } #undef PB_DS_VTYPE } // namespace detail - } // namespace test - } // namespace pb_ds -#endif // #ifndef PB_DS_SAMPLE_MEAN_HPP +#endif Index: testsuite/util/statistic/sample_mean_confidence_checker.hpp =================================================================== --- testsuite/util/statistic/sample_mean_confidence_checker.hpp (revision 117392) +++ testsuite/util/statistic/sample_mean_confidence_checker.hpp (working copy) @@ -53,25 +53,24 @@ namespace pb_ds { - namespace test { - namespace detail { - /* * Checks that a sample mean sm is in the relative interval - * relative_interval of a true mean (assuming i.i.d. samples), - * given a sample variance sv taken over num_samples samples, - * with confidence ~ 0.95. + * relative_interval of a true mean (assuming i.i.d. samples), + * given a sample variance sv taken over num_samples samples, + * with confidence ~ 0.95. * - * See "Probability, Random Variables, and Stochastic Processes" (Third edition) - * Athanasios Papoulis, Chapter 9. + * See "Probability, Random Variables, and Stochastic Processes" + * (Third edition) Athanasios Papoulis, Chapter 9. */ template bool - sample_mean_confidence_checker(Value_Type sm, Value_Type sv, std::size_t num_samples, double relative_interval) + sample_mean_confidence_checker(Value_Type sm, Value_Type sv, + std::size_t num_samples, + double relative_interval) { enum { @@ -85,14 +84,11 @@ // This is z_u (normal-dist percentile) for u = 0.975. const Value_Type z = 1.976; - return (sv / ::sqrt(double(num_samples)) <= relative_interval* sm / z); + return (sv / ::sqrt(double(num_samples)) <= relative_interval * sm / z); } - } // namespace detail - } // namespace test - } // namespace pb_ds -#endif // #ifndef PB_DS_SAMPLE_MEAN_CONFIDENCE_CHECKER_HPP +#endif Index: testsuite/util/statistic/result_recorder.hpp =================================================================== --- testsuite/util/statistic/result_recorder.hpp (revision 117374) +++ testsuite/util/statistic/result_recorder.hpp (working copy) @@ -40,7 +40,7 @@ // warranty. /** - * @file res_recorder.hpp + * @file result_recorder.hpp * Contains a class for recording results */ @@ -48,96 +48,61 @@ #define PB_DS_RES_RECORDER_HPP #include -#include +#include #include namespace pb_ds { - namespace test { - namespace detail { - -#define PB_DS_CLASS_T_DEC \ - template - -#define PB_DS_CLASS_C_DEC \ - res_recorder< \ - Value_Type> - /* * Records results until the probability that the sample mean is 10% away - * from the true mean is ~ 0.05. + * from the true mean is ~ 0.05. */ - template - class res_recorder + template + class result_recorder { public: typedef Value_Type value_type; - public: - res_recorder(); + result_recorder() + : m_sample_mean(value_type()), m_sample_var(value_type()) + { } bool - add_res(value_type res); + add_result(value_type res); inline value_type - sample_mean() const; + get_sample_mean() const + { return m_sample_mean; } private: - typedef std::list< value_type> list_t; + typedef std::list list_type; - private: - list_t m_l; - + list_type m_l; value_type m_sample_mean; - value_type m_sample_var; }; - PB_DS_CLASS_T_DEC - PB_DS_CLASS_C_DEC:: - res_recorder() : - m_sample_mean(0) - { } - PB_DS_CLASS_T_DEC - inline typename PB_DS_CLASS_C_DEC::value_type - PB_DS_CLASS_C_DEC:: - sample_mean() const - { - return (m_sample_mean); - } - - PB_DS_CLASS_T_DEC + template bool - PB_DS_CLASS_C_DEC:: - add_res(value_type res) + result_recorder:: + add_result(value_type res) { m_l.push_back(res); + m_sample_mean = sample_mean(m_l.begin(), m_l.end()); + m_sample_var = sample_variance(m_l.begin(), m_l.end(), m_sample_mean); - m_sample_mean = pb_ds::test::detail::sample_mean(m_l.begin(), m_l.end()); - - const value_type sample_var = - pb_ds::test::detail::sample_var(m_l.begin(), m_l.end(), m_sample_mean); - - return (pb_ds::test::detail::sample_mean_confidence_checker(m_sample_mean, - sample_var, - std::distance(m_l.begin(), m_l.end()), - 0.1)); + size_t dist = std::distance(m_l.begin(), m_l.end()); + return sample_mean_confidence_checker(m_sample_mean, m_sample_var, + dist, 0.1); } - -#undef PB_DS_CLASS_T_DEC - -#undef PB_DS_CLASS_C_DEC - } // namespace detail - } // namespace test - } // namespace pb_ds -#endif // #ifndef PB_DS_RES_RECORDER_HPP +#endif