Commit 382a1351 by Benjamin Kosnik Committed by Benjamin Kosnik

native_pq_tag.hpp: Remove.

2006-10-03  Benjamin Kosnik  <bkoz@redhat.com>

	* 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.

From-SVN: r117397
parent c55cebda
2006-10-03 Benjamin Kosnik <bkoz@redhat.com>
* 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.
2006-10-02 Paolo Carlini <pcarlini@suse.de> 2006-10-02 Paolo Carlini <pcarlini@suse.de>
* include/ext/rc_string_base.h (_M_compare<wchar_t>): * include/ext/rc_string_base.h (_M_compare<wchar_t>):
......
...@@ -134,5 +134,5 @@ namespace pb_ds ...@@ -134,5 +134,5 @@ namespace pb_ds
} // namespace test } // namespace test
} // namespace pb_ds } // namespace pb_ds
#endif // #ifndef PB_DS_NATIVE_HASH_MAP_HPP #endif
...@@ -55,4 +55,4 @@ namespace pb_ds ...@@ -55,4 +55,4 @@ namespace pb_ds
} // namespace test } // namespace test
} // namespace pb_ds } // namespace pb_ds
#endif // #ifndef PB_DS_NATIVE_HASH_DS_TAG_HPP #endif
...@@ -56,4 +56,4 @@ namespace pb_ds ...@@ -56,4 +56,4 @@ namespace pb_ds
} // namespace test } // namespace test
} // namespace pb_ds } // namespace pb_ds
#endif // #ifndef PB_DS_NATIVE_TREE_DS_TAG_HPP #endif
// -*- 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
...@@ -47,87 +47,66 @@ ...@@ -47,87 +47,66 @@
#ifndef PB_DS_NATIVE_PRIORITY_QUEUE_HPP #ifndef PB_DS_NATIVE_PRIORITY_QUEUE_HPP
#define PB_DS_NATIVE_PRIORITY_QUEUE_HPP #define PB_DS_NATIVE_PRIORITY_QUEUE_HPP
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/detail/type_utils.hpp>
#include <native_type/priority_queue/native_pq_tag.hpp>
#include <io/xml.hpp>
#include <string> #include <string>
#include <vector> #include <vector>
#include <queue> #include <queue>
#include <deque> #include <deque>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/detail/type_utils.hpp>
#include <io/xml.hpp>
namespace pb_ds namespace pb_ds
{ {
namespace test namespace test
{ {
namespace detail namespace detail
{ {
template<typename Value_Type, bool Vector, typename Allocator>
template<typename Value_Type, bool Vector, class Allocator>
struct base_seq struct base_seq
{ {
typedef private:
std::vector< typedef typename Allocator::template rebind<Value_Type> value_rebind;
Value_Type,
typename Allocator::template rebind< public:
Value_Type>::other> typedef std::vector<Value_Type, typename value_rebind::other> type;
type;
}; };
template<typename Value_Type, class Allocator> template<typename Value_Type, typename Allocator>
struct base_seq< struct base_seq<Value_Type, false, Allocator>
Value_Type,
false,
Allocator>
{ {
typedef private:
std::deque< typedef typename Allocator::template rebind<Value_Type> value_rebind;
Value_Type,
typename Allocator::template rebind<
Value_Type>::other>
type;
};
public:
typedef std::deque<Value_Type, typename value_rebind::other> type;
};
} // namespace detail } // namespace detail
#define PB_DS_CLASS_C_DEC \ struct native_pq_tag
native_priority_queue< \ { };
Value_Type, \
Vector, \ #define PB_DS_CLASS_C_DEC \
Cmp_Fn, \ native_priority_queue<Value_Type, Vector, Cmp_Fn, Allocator>
Allocator>
#define PB_DS_BASE_C_DEC \ #define PB_DS_BASE_C_DEC \
std::priority_queue< \ std::priority_queue<Value_Type, typename detail::base_seq<Value_Type, Vector, Allocator>::type, Cmp_Fn>
Value_Type, \
typename detail::base_seq<Value_Type, Vector, Allocator>::type, \
Cmp_Fn>
template<typename Value_Type, template<typename Value_Type,
bool Vector, bool Vector,
class Cmp_Fn = typename Cmp_Fn = std::less<Value_Type>,
std::less<Value_Type>, typename Allocator = std::allocator<char> >
class Allocator = std::allocator<char> >
class native_priority_queue : public PB_DS_BASE_C_DEC class native_priority_queue : public PB_DS_BASE_C_DEC
{ {
private: private:
typedef PB_DS_BASE_C_DEC base_type; typedef PB_DS_BASE_C_DEC base_type;
typedef typename Allocator::template rebind<Value_Type> value_rebind;
public: public:
typedef Value_Type value_type; typedef Value_Type value_type;
typedef typename value_rebind::other::const_reference const_reference;
typedef
typename Allocator::template rebind<
value_type>::other::const_reference
const_reference;
typedef native_pq_tag container_category; typedef native_pq_tag container_category;
typedef Cmp_Fn cmp_fn; typedef Cmp_Fn cmp_fn;
public:
native_priority_queue() : base_type() native_priority_queue() : base_type()
{ } { }
...@@ -140,7 +119,6 @@ namespace pb_ds ...@@ -140,7 +119,6 @@ namespace pb_ds
{ {
if (Vector) if (Vector)
return ("n_pq_vector"); return ("n_pq_vector");
return ("n_pq_deque"); return ("n_pq_deque");
} }
...@@ -148,44 +126,36 @@ namespace pb_ds ...@@ -148,44 +126,36 @@ namespace pb_ds
desc() desc()
{ {
if (Vector) if (Vector)
return (make_xml_tag( "type", "value", "std::priority_queue_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_deque"));
} }
void void
clear() clear()
{ { *static_cast<base_type*>(this) = base_type(); }
* static_cast<base_type* >(this) = base_type();
}
void void
erase(const_reference r_val) erase(const_reference r_val)
{ {
base_type tmp; base_type tmp;
Cmp_Fn cmp; Cmp_Fn cmp;
while (cmp(base_type::top(), r_val) || cmp(r_val, base_type::top())) while (cmp(base_type::top(), r_val) || cmp(r_val, base_type::top()))
{ {
tmp.push(base_type::top()); tmp.push(base_type::top());
base_type::pop(); base_type::pop();
} }
if (!base_type::empty()) if (!base_type::empty())
{ {
base_type::pop(); base_type::pop();
while (!base_type::empty()) while (!base_type::empty())
{ {
tmp.push(base_type::top()); tmp.push(base_type::top());
base_type::pop(); base_type::pop();
} }
} }
*static_cast<base_type* >(this) = tmp;
* static_cast<base_type* >(this) = tmp;
} }
template<typename Pred> template<typename Pred>
...@@ -193,21 +163,17 @@ namespace pb_ds ...@@ -193,21 +163,17 @@ namespace pb_ds
erase_if(Pred pred) erase_if(Pred pred)
{ {
base_type tmp; base_type tmp;
std::size_t ersd = 0; std::size_t ersd = 0;
while (!base_type::empty()) while (!base_type::empty())
{ {
if (!pred(base_type::top())) if (!pred(base_type::top()))
tmp.push(base_type::top()); tmp.push(base_type::top());
else else
++ersd; ++ersd;
base_type::pop(); base_type::pop();
} }
* static_cast<base_type* >(this) = tmp; *static_cast<base_type*>(this) = tmp;
return ersd; return ersd;
} }
...@@ -216,27 +182,22 @@ namespace pb_ds ...@@ -216,27 +182,22 @@ namespace pb_ds
split(Pred pred, PB_DS_CLASS_C_DEC& other) split(Pred pred, PB_DS_CLASS_C_DEC& other)
{ {
base_type tmp; base_type tmp;
other.clear(); other.clear();
while (!base_type::empty()) while (!base_type::empty())
{ {
if (!pred(base_type::top())) if (!pred(base_type::top()))
tmp.push(base_type::top()); tmp.push(base_type::top());
else else
other.push(base_type::top()); other.push(base_type::top());
base_type::pop(); base_type::pop();
} }
*static_cast<base_type*>(this) = tmp;
* static_cast<base_type* >(this) = tmp;
} }
void void
modify(const_reference r_old, const_reference r_new) modify(const_reference r_old, const_reference r_new)
{ {
erase(r_old); erase(r_old);
push(r_new); push(r_new);
} }
...@@ -244,37 +205,30 @@ namespace pb_ds ...@@ -244,37 +205,30 @@ namespace pb_ds
join(PB_DS_CLASS_C_DEC& other) join(PB_DS_CLASS_C_DEC& other)
{ {
std::vector<value_type> a_tmp; std::vector<value_type> a_tmp;
while (!base_type::empty()) while (!base_type::empty())
{ {
a_tmp.push_back(base_type::top()); a_tmp.push_back(base_type::top());
base_type::pop(); base_type::pop();
} }
while (!other.empty()) while (!other.empty())
{ {
a_tmp.push_back(other.top()); a_tmp.push_back(other.top());
other.pop(); other.pop();
} }
* static_cast<base_type* >(this) = base_type(a_tmp.begin(), a_tmp.end()); *static_cast<base_type*>(this) = base_type(a_tmp.begin(), a_tmp.end());
} }
Cmp_Fn Cmp_Fn
get_cmp_fn() const get_cmp_fn() const
{ { return Cmp_Fn(); }
return Cmp_Fn();
}
}; };
#undef PB_DS_BASE_C_DEC #undef PB_DS_BASE_C_DEC
#undef PB_DS_CLASS_C_DEC #undef PB_DS_CLASS_C_DEC
} // namespace test } // namespace test
} // namespace pb_ds } // namespace pb_ds
#endif // #ifndef PB_DS_NATIVE_PRIORITY_QUEUE_HPP #endif
...@@ -50,7 +50,6 @@ ...@@ -50,7 +50,6 @@
#include <performance/time/timing_test_base.hpp> #include <performance/time/timing_test_base.hpp>
#include <performance/io/xml_formatter.hpp> #include <performance/io/xml_formatter.hpp>
#include <common_type/assoc/string_form.hpp> #include <common_type/assoc/string_form.hpp>
#include <statistic/res_recorder.hpp>
#include <iterator> #include <iterator>
namespace pb_ds namespace pb_ds
......
...@@ -128,6 +128,9 @@ namespace pb_ds ...@@ -128,6 +128,9 @@ namespace pb_ds
using pb_ds::test::detail::double_push_functor; using pb_ds::test::detail::double_push_functor;
using pb_ds::test::detail::double_push_join_functor; using pb_ds::test::detail::double_push_join_functor;
typedef pb_ds::test::detail::timing_test_base base_type; typedef pb_ds::test::detail::timing_test_base base_type;
typedef double_push_functor<It, Cntnr> psh_fnct;
typedef double_push_join_functor<It, Cntnr> psh_jn_fnct;
typedef xml_result_set_performance_formatter formatter_type; typedef xml_result_set_performance_formatter formatter_type;
formatter_type res(string_form<Cntnr>::name(), formatter_type res(string_form<Cntnr>::name(),
string_form<Cntnr>::desc()); string_form<Cntnr>::desc());
...@@ -139,12 +142,12 @@ namespace pb_ds ...@@ -139,12 +142,12 @@ namespace pb_ds
It e = m_ins_b; It e = m_ins_b;
std::advance(e, v); std::advance(e, v);
double_push_functor<It, Cntnr> double_push_fn(b, e); psh_fnct double_push_fn(b, e);
const double double_push_res = base_type::operator()(double_push_fn); const double dbl_psh_res = base_type::operator()(double_push_fn);
double_push_join_functor<It, Cntnr> double_push_join_fn(b, e); psh_jn_fnct dbl_psh_jn_fn(b, e);
const double double_push_join_res = base_type::operator()(double_push_join_fn); 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(double_push_join_res - double_push_res, base_type::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); res.add_res(v, effective_delta / v);
} }
} }
......
...@@ -59,6 +59,7 @@ namespace pb_ds ...@@ -59,6 +59,7 @@ namespace pb_ds
{ {
namespace detail namespace detail
{ {
// Primary templates.
template<typename It, class Cntnr, class Tag> template<typename It, class Cntnr, class Tag>
class push_functor class push_functor
{ {
...@@ -123,6 +124,7 @@ namespace pb_ds ...@@ -123,6 +124,7 @@ namespace pb_ds
const value_type m_mod_val; const value_type m_mod_val;
}; };
// Specializations.
template<typename It, class Cntnr> template<typename It, class Cntnr>
class push_functor<It, Cntnr, pb_ds::binary_heap_tag> class push_functor<It, Cntnr, pb_ds::binary_heap_tag>
{ {
...@@ -149,6 +151,33 @@ namespace pb_ds ...@@ -149,6 +151,33 @@ namespace pb_ds
}; };
template<typename It, class Cntnr> template<typename It, class Cntnr>
class push_functor<It, Cntnr, pb_ds::test::native_pq_tag>
{
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<typename It, class Cntnr>
class push_modify_functor<It, Cntnr, pb_ds::binary_heap_tag> class push_modify_functor<It, Cntnr, pb_ds::binary_heap_tag>
{ {
private: private:
...@@ -191,32 +220,6 @@ namespace pb_ds ...@@ -191,32 +220,6 @@ namespace pb_ds
}; };
template<typename It, class Cntnr> template<typename It, class Cntnr>
class push_functor<It, Cntnr, pb_ds::test::native_pq_tag>
{
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<typename It, class Cntnr>
class push_modify_functor<It, Cntnr, pb_ds::test::native_pq_tag> class push_modify_functor<It, Cntnr, pb_ds::test::native_pq_tag>
{ {
private: private:
...@@ -291,8 +294,9 @@ namespace pb_ds ...@@ -291,8 +294,9 @@ namespace pb_ds
typedef typename Cntnr::value_type value_type; typedef typename Cntnr::value_type value_type;
typedef typename Cntnr::container_category container_category; typedef typename Cntnr::container_category container_category;
typedef typename Cntnr::const_reference const_reference; 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<It, Cntnr, container_category> psh_fnct;
typedef detail::push_modify_functor<It, Cntnr, container_category> psh_mod_fnct;
typedef xml_result_set_performance_formatter formatter_type; typedef xml_result_set_performance_formatter formatter_type;
formatter_type res_set_fmt(string_form<Cntnr>::name(), formatter_type res_set_fmt(string_form<Cntnr>::name(),
string_form<Cntnr>::desc()); string_form<Cntnr>::desc());
...@@ -300,14 +304,12 @@ namespace pb_ds ...@@ -300,14 +304,12 @@ namespace pb_ds
for (size_t i = 0; m_ins_vn + i * m_ins_vs < m_ins_vm; ++i) 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; 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; It e = m_ins_b;
std::advance(e, v); std::advance(e, v);
pb_ds::test::detail::push_functor<It, Cntnr, container_category> psh_fnct psh_fn(b, e);
push_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; value_type val = b->first;
{ {
...@@ -320,13 +322,12 @@ namespace pb_ds ...@@ -320,13 +322,12 @@ namespace pb_ds
} }
} }
pb_ds::test::detail::push_modify_functor<It, Cntnr, container_category> psh_mod_fnct psh_mod_fn(b, e, val);
push_modify_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 effective_delta = std::max(push_modify_res - push_res, const double min_res = double(timing_test_base::min_time_res());
timing_test_base::min_time_res()); const double effective_delta = std::max(psh_mod_res - psh_res,
min_res);
res_set_fmt.add_res(v, effective_delta / v); res_set_fmt.add_res(v, effective_delta / v);
} }
......
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
#define PB_DS_TIMING_TEST_BASE_HPP #define PB_DS_TIMING_TEST_BASE_HPP
#include <performance/time/elapsed_timer.hpp> #include <performance/time/elapsed_timer.hpp>
#include <statistic/res_recorder.hpp> #include <statistic/result_recorder.hpp>
namespace pb_ds namespace pb_ds
{ {
...@@ -81,12 +81,12 @@ namespace pb_ds ...@@ -81,12 +81,12 @@ namespace pb_ds
timing_test_base::operator()(Functor& fn) timing_test_base::operator()(Functor& fn)
{ {
const std::size_t resolution = get_min_resolution(fn); const std::size_t resolution = get_min_resolution(fn);
pb_ds::test::detail::res_recorder<double> rec; pb_ds::test::detail::result_recorder<double> rec;
double res; double res;
do do
res = run_at_resolution(fn, resolution); res = run_at_resolution(fn, resolution);
while (rec.add_res(res) == false); while (rec.add_result(res) == false);
res = rec.sample_mean() / resolution; res = rec.get_sample_mean() / resolution;
return res; return res;
} }
......
...@@ -101,22 +101,15 @@ namespace detail ...@@ -101,22 +101,15 @@ namespace detail
{ {
private: private:
typedef PB_DS_NATIVE_TYPE_TRAITS_C_DEC native_type_traits_base; typedef PB_DS_NATIVE_TYPE_TRAITS_C_DEC native_type_traits_base;
typedef PB_DS_TYPE_TRAITS_C_DEC type_traits_base; typedef PB_DS_TYPE_TRAITS_C_DEC type_traits_base;
public: public:
typedef typename Cntnr::key_type key_type; typedef typename Cntnr::key_type key_type;
typedef typename Cntnr::const_key_reference const_key_reference; typedef typename Cntnr::const_key_reference const_key_reference;
typedef typename Cntnr::value_type value_type; typedef typename Cntnr::value_type value_type;
typedef typename Cntnr::const_reference const_reference; typedef typename Cntnr::const_reference const_reference;
typedef typename PB_DS_NATIVE_TYPE_TRAITS_C_DEC::type native_type; 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::key_type native_key_type;
typedef typename native_type::value_type native_value_type; typedef typename native_type::value_type native_value_type;
enum enum
...@@ -153,73 +146,49 @@ namespace detail ...@@ -153,73 +146,49 @@ namespace detail
static void static void
print_container(const Cntnr& r_c, std::ostream& r_os) 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<typename Gen> template<typename Gen>
static key_type static key_type
generate_key(Gen& r_gen, size_t max) 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<typename Gen> template<typename Gen>
static value_type static value_type
generate_value(Gen& r_gen, size_t max) 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 static const_key_reference
extract_key(const_reference r_val) 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 static native_key_type
native_key(const_key_reference r_key) 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 static native_value_type
native_value(const_reference r_val) 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& static const native_key_type&
extract_native_key(const native_value_type& r_val) 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 static bool
cmp(const_reference r_val, const native_value_type& r_native_val) 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 static std::string
val_to_string(const_reference r_val) val_to_string(const_reference r_val)
{ { return to_string(r_val); }
return to_string(r_val);
}
static std::string static std::string
key_to_string(const_key_reference r_key) key_to_string(const_key_reference r_key)
{ { return to_string(r_key); }
return to_string(r_key);
}
static std::string static std::string
native_val_to_string(const native_value_type& r_native_val) 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 static bool
prefix_match(const_key_reference r_key, const std::string& r_native_key) prefix_match(const_key_reference r_key, const std::string& r_native_key)
...@@ -232,7 +201,6 @@ namespace detail ...@@ -232,7 +201,6 @@ namespace detail
return native_substr == (const std::string&) r_key; return native_substr == (const std::string&) r_key;
} }
}; };
#undef PB_DS_TYPE_TRAITS_C_DEC #undef PB_DS_TYPE_TRAITS_C_DEC
......
...@@ -52,17 +52,13 @@ ...@@ -52,17 +52,13 @@
namespace pb_ds namespace pb_ds
{ {
namespace test namespace test
{ {
namespace detail namespace detail
{ {
template<typename T> template<typename T>
struct regression_test_erase_if_fn : public std::unary_function< struct regression_test_erase_if_fn
T, : public std::unary_function<T, bool>
bool>
{ {
private: private:
typedef const T& const_reference; typedef const T& const_reference;
...@@ -77,35 +73,23 @@ namespace pb_ds ...@@ -77,35 +73,23 @@ namespace pb_ds
}; };
template<typename Hd, class Tl> template<typename Hd, class Tl>
struct regression_test_erase_if_fn< struct regression_test_erase_if_fn<std::pair<Hd, Tl> >
std::pair< : public std::unary_function<std::pair<Hd, Tl>, bool>
Hd,
Tl> > : public std::unary_function<
std::pair<
Hd,
Tl>,
bool>
{ {
private: private:
typedef const std::pair<Hd, Tl>& const_reference; typedef const std::pair<Hd, Tl>& const_reference;
typedef regression_test_erase_if_fn<Hd> hd_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;
typedef regression_test_erase_if_fn< Tl> tl_erase_if_fn;
public: public:
bool bool
operator()(const_reference r_t) const operator()(const_reference r_t) const
{ {
return (hd_erase_if_fn()(r_t.first)&& return (hd_erase_if_fn()(r_t.first) && tl_erase_if_fn()(r_t.second));
tl_erase_if_fn()(r_t.second));
} }
}; };
} // namespace detail } // namespace detail
} // namespace test } // namespace test
} // namespace pb_ds } // namespace pb_ds
#endif // #ifndef PB_DS_REGRESSION_TEST_ERASE_IF_FN_HPP #endif
...@@ -52,82 +52,41 @@ ...@@ -52,82 +52,41 @@
namespace pb_ds namespace pb_ds
{ {
namespace test namespace test
{ {
namespace detail namespace detail
{ {
#define PB_DS_CLASS_T_DEC \
template<typename Cntnr>
#define PB_DS_CLASS_C_DEC \
regression_test_traits< \
Cntnr>
template<typename Cntnr> template<typename Cntnr>
struct regression_test_traits struct regression_test_traits
{ {
public:
typedef typename Cntnr::value_type value_type; typedef typename Cntnr::value_type value_type;
typedef typename Cntnr::const_reference const_reference; 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<
std::string,
true>
native_type;
typedef typename native_type::value_type native_value_type; typedef typename native_type::value_type native_value_type;
template<typename T> template<typename T>
struct erase_if_fn : public regression_test_erase_if_fn< struct erase_if_fn : public regression_test_erase_if_fn<T>
T> { };
{
};
public:
template<typename Gen> template<typename Gen>
static value_type static value_type
generate_value(Gen& r_gen, size_t max) generate_value(Gen& r_gen, size_t max)
{ { return basic_type(r_gen, max); }
return basic_type(r_gen, max);
}
static native_value_type static native_value_type
native_value(const_reference r_val) native_value(const_reference r_val)
{ { return native_value_type(r_val); }
return (native_value_type(r_val));
}
static bool static bool
cmp(const_reference r_val, const native_value_type& r_native_val) 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 static std::string
val_to_string(const_reference r_val) 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 detail
} // namespace test } // namespace test
} // namespace pb_ds } // namespace pb_ds
#endif // #ifndef PB_DS_REGRESSION_TEST_TRAIT_HPP #endif
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
// warranty. // warranty.
/** /**
* @file res_recorder.hpp * @file result_recorder.hpp
* Contains a class for recording results * Contains a class for recording results
*/ */
...@@ -48,96 +48,61 @@ ...@@ -48,96 +48,61 @@
#define PB_DS_RES_RECORDER_HPP #define PB_DS_RES_RECORDER_HPP
#include <statistic/sample_mean.hpp> #include <statistic/sample_mean.hpp>
#include <statistic/sample_var.hpp> #include <statistic/sample_variance.hpp>
#include <statistic/sample_mean_confidence_checker.hpp> #include <statistic/sample_mean_confidence_checker.hpp>
namespace pb_ds namespace pb_ds
{ {
namespace test namespace test
{ {
namespace detail namespace detail
{ {
#define PB_DS_CLASS_T_DEC \
template<typename Value_Type>
#define PB_DS_CLASS_C_DEC \
res_recorder< \
Value_Type>
/* /*
* Records results until the probability that the sample mean is 10% away * 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<typename Value_Type = double> template<typename Value_Type>
class res_recorder class result_recorder
{ {
public: public:
typedef Value_Type value_type; typedef Value_Type value_type;
public: result_recorder()
res_recorder(); : m_sample_mean(value_type()), m_sample_var(value_type())
{ }
bool bool
add_res(value_type res); add_result(value_type res);
inline value_type inline value_type
sample_mean() const; get_sample_mean() const
{ return m_sample_mean; }
private: private:
typedef std::list< value_type> list_t; typedef std::list<value_type> list_type;
private:
list_t m_l;
list_type m_l;
value_type m_sample_mean; value_type m_sample_mean;
value_type m_sample_var; 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 template<typename Value_Type>
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 bool
PB_DS_CLASS_C_DEC:: result_recorder<Value_Type>::
add_res(value_type res) add_result(value_type res)
{ {
m_l.push_back(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()); size_t dist = std::distance(m_l.begin(), m_l.end());
return sample_mean_confidence_checker(m_sample_mean, m_sample_var,
const value_type sample_var = dist, 0.1);
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 detail
} // namespace test } // namespace test
} // namespace pb_ds } // namespace pb_ds
#endif // #ifndef PB_DS_RES_RECORDER_HPP #endif
...@@ -54,16 +54,11 @@ ...@@ -54,16 +54,11 @@
namespace pb_ds namespace pb_ds
{ {
namespace test namespace test
{ {
namespace detail namespace detail
{ {
#define PB_DS_VTYPE typename std::iterator_traits<It>::value_type
#define PB_DS_VTYPE \
typename std::iterator_traits< \
It>::value_type
template<typename It> template<typename It>
PB_DS_VTYPE PB_DS_VTYPE
...@@ -71,17 +66,14 @@ namespace pb_ds ...@@ -71,17 +66,14 @@ namespace pb_ds
{ {
const PB_DS_VTYPE total = std::accumulate(b, e, PB_DS_VTYPE(0)); const PB_DS_VTYPE total = std::accumulate(b, e, PB_DS_VTYPE(0));
const size_t num = std::distance(b, e); const size_t num = std::distance(b, e);
return total / num;
return (total / num);
} }
#undef PB_DS_VTYPE #undef PB_DS_VTYPE
} // namespace detail } // namespace detail
} // namespace test } // namespace test
} // namespace pb_ds } // namespace pb_ds
#endif // #ifndef PB_DS_SAMPLE_MEAN_HPP #endif
...@@ -53,25 +53,24 @@ ...@@ -53,25 +53,24 @@
namespace pb_ds namespace pb_ds
{ {
namespace test namespace test
{ {
namespace detail namespace detail
{ {
/* /*
* Checks that a sample mean sm is in the relative interval * Checks that a sample mean sm is in the relative interval
* relative_interval of a true mean (assuming i.i.d. samples), * relative_interval of a true mean (assuming i.i.d. samples),
* given a sample variance sv taken over num_samples samples, * given a sample variance sv taken over num_samples samples,
* with confidence ~ 0.95. * with confidence ~ 0.95.
* *
* See "Probability, Random Variables, and Stochastic Processes" (Third edition) * See "Probability, Random Variables, and Stochastic Processes"
* Athanasios Papoulis, Chapter 9. * (Third edition) Athanasios Papoulis, Chapter 9.
*/ */
template<typename Value_Type> template<typename Value_Type>
bool 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 enum
{ {
...@@ -85,14 +84,11 @@ namespace pb_ds ...@@ -85,14 +84,11 @@ namespace pb_ds
// This is z_u (normal-dist percentile) for u = 0.975. // This is z_u (normal-dist percentile) for u = 0.975.
const Value_Type z = 1.976; 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 detail
} // namespace test } // namespace test
} // namespace pb_ds } // namespace pb_ds
#endif // #ifndef PB_DS_SAMPLE_MEAN_CONFIDENCE_CHECKER_HPP #endif
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
// warranty. // warranty.
/** /**
* @file sample_var.hpp * @file sample_variance.hpp
* Contains a function for calculating a sample variance * Contains a function for calculating a sample variance
*/ */
...@@ -54,49 +54,38 @@ ...@@ -54,49 +54,38 @@
namespace pb_ds namespace pb_ds
{ {
namespace test namespace test
{ {
namespace detail namespace detail
{ {
#define PB_DS_VTYPE typename std::iterator_traits<It>::value_type
#define PB_DS_VTYPE \
typename std::iterator_traits< \
It>::value_type
template<typename It> template<typename It>
PB_DS_VTYPE 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; PB_DS_VTYPE ss = 0;
size_t num_res = 0; size_t num_res = 0;
while (b != e) while (b != e)
{ {
const PB_DS_VTYPE d =* b - sm; const PB_DS_VTYPE d =* b - sm;
ss += d* d; ss += d* d;
++num_res; ++num_res;
++b; ++b;
} }
if (num_res == 1) if (num_res == 1)
return (0); return 0;
return (::sqrt(ss / (num_res - 1))); return ::sqrt(ss / (num_res - 1));
} }
#undef PB_DS_VTYPE #undef PB_DS_VTYPE
} // namespace detail } // namespace detail
} // namespace test } // namespace test
} // namespace pb_ds } // namespace pb_ds
#endif // #ifndef PB_DS_SAMPLE_VAR_HPP #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment