Commit 5580c6e7 by Benjamin Kosnik Committed by Benjamin Kosnik

throw_allocator.h: Rework.

2009-06-04  Benjamin Kosnik  <bkoz@redhat.com>

	* include/ext/throw_allocator.h: Rework.
	* include/ext/pb_ds/detail/debug_map_base.hpp: Adjust usage.
	* include/ext/pb_ds/detail/gp_hash_table_map_/resize_fn_imps.hpp: Same.
	* include/ext/pb_ds/detail/ov_tree_map_/erase_fn_imps.hpp: Same.
	* include/ext/pb_ds/detail/ov_tree_map_/ov_tree_map_.hpp: Same.
	* testsuite/23_containers/list/modifiers/insert/25288.cc: Same.
	* testsuite/util/regression/rand/priority_queue/
	container_rand_regression_test.tcc: Inline functions.
	* testsuite/util/regression/rand/assoc/
	container_rand_regression_test.tcc: Same.

From-SVN: r148204
parent 2771246a
2009-06-04 Benjamin Kosnik <bkoz@redhat.com>
* include/ext/throw_allocator.h: Rework.
* include/ext/pb_ds/detail/debug_map_base.hpp: Adjust usage.
* include/ext/pb_ds/detail/gp_hash_table_map_/resize_fn_imps.hpp: Same.
* include/ext/pb_ds/detail/ov_tree_map_/erase_fn_imps.hpp: Same.
* include/ext/pb_ds/detail/ov_tree_map_/ov_tree_map_.hpp: Same.
* testsuite/23_containers/list/modifiers/insert/25288.cc: Same.
* testsuite/util/regression/rand/priority_queue/
container_rand_regression_test.tcc: Inline functions.
* testsuite/util/regression/rand/assoc/
container_rand_regression_test.tcc: Same.
2009-06-03 Benjamin Kosnik <bkoz@redhat.com> 2009-06-03 Benjamin Kosnik <bkoz@redhat.com>
* testsuite/23_containers/list/cons/6.cc: Adjust test name. * testsuite/23_containers/list/cons/6.cc: Adjust test name.
......
...@@ -154,8 +154,8 @@ namespace __gnu_pbds ...@@ -154,8 +154,8 @@ namespace __gnu_pbds
{ {
_GLIBCXX_DEBUG_ONLY(assert_valid();) _GLIBCXX_DEBUG_ONLY(assert_valid();)
__gnu_cxx::throw_allocator<char> alloc; __gnu_cxx::throw_allocator<char> alloc;
const double orig_throw_prob = alloc.get_throw_prob(); const double orig_throw_prob = alloc.get_probability();
alloc.set_throw_prob(0); alloc.set_probability(0);
if (find(r_key) != m_key_set.end()) if (find(r_key) != m_key_set.end())
{ {
std::cerr << "insert_new" << r_key << std::endl; std::cerr << "insert_new" << r_key << std::endl;
...@@ -171,7 +171,7 @@ namespace __gnu_pbds ...@@ -171,7 +171,7 @@ namespace __gnu_pbds
std::cerr << "insert_new" << r_key << std::endl; std::cerr << "insert_new" << r_key << std::endl;
std::abort(); std::abort();
} }
alloc.set_throw_prob(orig_throw_prob); alloc.set_probability(orig_throw_prob);
_GLIBCXX_DEBUG_ONLY(assert_valid();) _GLIBCXX_DEBUG_ONLY(assert_valid();)
} }
...@@ -315,8 +315,8 @@ namespace __gnu_pbds ...@@ -315,8 +315,8 @@ namespace __gnu_pbds
split(const_key_reference r_key, Cmp_Fn cmp_fn, PB_DS_CLASS_C_DEC& other) split(const_key_reference r_key, Cmp_Fn cmp_fn, PB_DS_CLASS_C_DEC& other)
{ {
__gnu_cxx::throw_allocator<char> alloc; __gnu_cxx::throw_allocator<char> alloc;
const double orig_throw_prob = alloc.get_throw_prob(); const double orig_throw_prob = alloc.get_probability();
alloc.set_throw_prob(0); alloc.set_probability(0);
other.clear(); other.clear();
key_set_iterator it = m_key_set.begin(); key_set_iterator it = m_key_set.begin();
while (it != m_key_set.end()) while (it != m_key_set.end())
...@@ -327,7 +327,7 @@ namespace __gnu_pbds ...@@ -327,7 +327,7 @@ namespace __gnu_pbds
} }
else else
++it; ++it;
alloc.set_throw_prob(orig_throw_prob); alloc.set_probability(orig_throw_prob);
} }
PB_DS_CLASS_T_DEC PB_DS_CLASS_T_DEC
...@@ -336,8 +336,8 @@ namespace __gnu_pbds ...@@ -336,8 +336,8 @@ namespace __gnu_pbds
join(PB_DS_CLASS_C_DEC& other) join(PB_DS_CLASS_C_DEC& other)
{ {
__gnu_cxx::throw_allocator<char> alloc; __gnu_cxx::throw_allocator<char> alloc;
const double orig_throw_prob = alloc.get_throw_prob(); const double orig_throw_prob = alloc.get_probability();
alloc.set_throw_prob(0); alloc.set_probability(0);
key_set_iterator it = other.m_key_set.begin(); key_set_iterator it = other.m_key_set.begin();
while (it != other.m_key_set.end()) while (it != other.m_key_set.end())
{ {
...@@ -345,7 +345,7 @@ namespace __gnu_pbds ...@@ -345,7 +345,7 @@ namespace __gnu_pbds
it = other.m_key_set.erase(it); it = other.m_key_set.erase(it);
} }
_GLIBCXX_DEBUG_ASSERT(other.m_key_set.empty()); _GLIBCXX_DEBUG_ASSERT(other.m_key_set.empty());
alloc.set_throw_prob(orig_throw_prob); alloc.set_probability(orig_throw_prob);
} }
#undef PB_DS_CLASS_T_DEC #undef PB_DS_CLASS_T_DEC
......
...@@ -79,7 +79,7 @@ PB_DS_CLASS_C_DEC:: ...@@ -79,7 +79,7 @@ PB_DS_CLASS_C_DEC::
resize_imp(size_type new_size) resize_imp(size_type new_size)
{ {
#ifdef PB_DS_REGRESSION #ifdef PB_DS_REGRESSION
typename Allocator::group_throw_prob_adjustor adjust(m_num_e); typename Allocator::group_adjustor adjust(m_num_e);
#endif #endif
if (new_size == m_num_e) if (new_size == m_num_e)
......
...@@ -71,7 +71,7 @@ erase_if(Pred pred) ...@@ -71,7 +71,7 @@ erase_if(Pred pred)
_GLIBCXX_DEBUG_ONLY(assert_valid();) _GLIBCXX_DEBUG_ONLY(assert_valid();)
#ifdef PB_DS_REGRESSION #ifdef PB_DS_REGRESSION
typename Allocator::group_throw_prob_adjustor adjust(m_size); typename Allocator::group_adjustor adjust(m_size);
#endif #endif
size_type new_size = 0; size_type new_size = 0;
...@@ -133,7 +133,7 @@ erase_imp(It it) ...@@ -133,7 +133,7 @@ erase_imp(It it)
_GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::check_key_exists(PB_DS_V2F(*it));) _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::check_key_exists(PB_DS_V2F(*it));)
#ifdef PB_DS_REGRESSION #ifdef PB_DS_REGRESSION
typename Allocator::group_throw_prob_adjustor adjust(m_size); typename Allocator::group_adjustor adjust(m_size);
#endif #endif
_GLIBCXX_DEBUG_ASSERT(m_size > 0); _GLIBCXX_DEBUG_ASSERT(m_size > 0);
......
...@@ -414,7 +414,7 @@ namespace __gnu_pbds ...@@ -414,7 +414,7 @@ namespace __gnu_pbds
{ {
_GLIBCXX_DEBUG_ONLY(assert_valid();) _GLIBCXX_DEBUG_ONLY(assert_valid();)
#ifdef PB_DS_REGRESSION #ifdef PB_DS_REGRESSION
typename Allocator::group_throw_prob_adjustor adjust(m_size); typename Allocator::group_adjustor adjust(m_size);
#endif #endif
_GLIBCXX_DEBUG_ONLY(debug_base::check_key_does_not_exist(PB_DS_V2F(r_value))); _GLIBCXX_DEBUG_ONLY(debug_base::check_key_does_not_exist(PB_DS_V2F(r_value)));
......
...@@ -38,7 +38,7 @@ void insert1() ...@@ -38,7 +38,7 @@ void insert1()
for (int i = 0; i < 10; ++i) for (int i = 0; i < 10; ++i)
{ {
allocator_type alloc1; allocator_type alloc1;
typename allocator_type::zero_throw_prob_adjustor adjust1; typename allocator_type::never_adjustor adjust1;
list_type list1(alloc1); list_type list1(alloc1);
for (int k = 0; k < j; ++k) for (int k = 0; k < j; ++k)
...@@ -46,7 +46,7 @@ void insert1() ...@@ -46,7 +46,7 @@ void insert1()
try try
{ {
alloc1.set_throw_prob(1); typename allocator_type::always_adjustor adjust2;
list1.insert(list1.begin(), 10, 99); list1.insert(list1.begin(), 10, 99);
VERIFY( false ); VERIFY( false );
} }
...@@ -56,7 +56,7 @@ void insert1() ...@@ -56,7 +56,7 @@ void insert1()
} }
catch (...) catch (...)
{ {
VERIFY( false ); __throw_exception_again;
} }
VERIFY( list1.size() == size_type(j) ); VERIFY( list1.size() == size_type(j) );
...@@ -64,7 +64,6 @@ void insert1() ...@@ -64,7 +64,6 @@ void insert1()
VERIFY( list1.size() == 0 || list1.front() == -1 ); VERIFY( list1.size() == 0 || list1.front() == -1 );
allocator_type alloc2; allocator_type alloc2;
typename allocator_type::zero_throw_prob_adjustor adjust2;
list_type list2(alloc2); list_type list2(alloc2);
const int data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; const int data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
...@@ -74,7 +73,7 @@ void insert1() ...@@ -74,7 +73,7 @@ void insert1()
try try
{ {
alloc2.set_throw_prob(1); typename allocator_type::always_adjustor adjust3;
list2.insert(list2.begin(), data, data + 10); list2.insert(list2.begin(), data, data + 10);
VERIFY( false ); VERIFY( false );
} }
......
...@@ -148,7 +148,7 @@ namespace detail ...@@ -148,7 +148,7 @@ namespace detail
namespace detail namespace detail
{ {
void inline void
usage(const std::string& name) usage(const std::string& name)
{ {
using namespace std; using namespace std;
...@@ -179,7 +179,7 @@ namespace detail ...@@ -179,7 +179,7 @@ namespace detail
cerr << "'t' or 'f' determine whether progress will be displayed" << endl; cerr << "'t' or 'f' determine whether progress will be displayed" << endl;
} }
void inline void
verify_params(size_t& r_seed, size_t& r_n, verify_params(size_t& r_seed, size_t& r_n,
size_t& r_m, double& r_tp, double& r_ip, double& r_ep, size_t& r_m, double& r_tp, double& r_ip, double& r_ep,
double& r_cp, double& r_mp, bool& r_d) double& r_cp, double& r_mp, bool& r_d)
......
...@@ -60,7 +60,7 @@ default_constructor() ...@@ -60,7 +60,7 @@ default_constructor()
{ {
PB_DS_TRACE("default_constructor"); PB_DS_TRACE("default_constructor");
bool done = true; bool done = true;
m_alloc.set_throw_prob(m_tp); m_alloc.set_probability(m_tp);
try try
{ {
...@@ -83,9 +83,9 @@ PB_DS_CLASS_C_DEC:: ...@@ -83,9 +83,9 @@ PB_DS_CLASS_C_DEC::
swap() swap()
{ {
PB_DS_TRACE("swap"); PB_DS_TRACE("swap");
m_alloc.set_throw_prob(0); m_alloc.set_probability(0);
Cntnr* p_c = new Cntnr; Cntnr* p_c = new Cntnr;
m_alloc.set_throw_prob(1); m_alloc.set_probability(1);
p_c->swap(*m_p_c); p_c->swap(*m_p_c);
std::swap(p_c, m_p_c); std::swap(p_c, m_p_c);
delete p_c; delete p_c;
...@@ -100,9 +100,9 @@ copy_constructor() ...@@ -100,9 +100,9 @@ copy_constructor()
PB_DS_TRACE("copy_constructor"); PB_DS_TRACE("copy_constructor");
bool done = true; bool done = true;
Cntnr* p_c = NULL; Cntnr* p_c = NULL;
m_alloc.set_throw_prob(m_tp); m_alloc.set_probability(m_tp);
typedef typename allocator_type::group_throw_prob_adjustor adjustor; typedef typename allocator_type::group_adjustor adjustor;
adjustor adjust(m_p_c->size()); adjustor adjust(m_p_c->size());
try try
...@@ -128,9 +128,9 @@ assignment_operator() ...@@ -128,9 +128,9 @@ assignment_operator()
PB_DS_TRACE("assignment operator"); PB_DS_TRACE("assignment operator");
bool done = true; bool done = true;
Cntnr* p_c = NULL; Cntnr* p_c = NULL;
m_alloc.set_throw_prob(m_tp); m_alloc.set_probability(m_tp);
typedef typename allocator_type::group_throw_prob_adjustor adjustor; typedef typename allocator_type::group_adjustor adjustor;
adjustor adjust(m_p_c->size()); adjustor adjust(m_p_c->size());
try try
...@@ -156,8 +156,8 @@ it_constructor() ...@@ -156,8 +156,8 @@ it_constructor()
{ {
bool done = true; bool done = true;
Cntnr* p_c = NULL; Cntnr* p_c = NULL;
m_alloc.set_throw_prob(m_tp); m_alloc.set_probability(m_tp);
typedef typename allocator_type::group_throw_prob_adjustor adjustor; typedef typename allocator_type::group_adjustor adjustor;
adjustor adjust(m_p_c->size()); adjustor adjust(m_p_c->size());
try try
...@@ -201,7 +201,7 @@ cmp(const Cntnr& c, const native_type& native, const std::string& callfn) ...@@ -201,7 +201,7 @@ cmp(const Cntnr& c, const native_type& native, const std::string& callfn)
try try
{ {
m_alloc.set_throw_prob(1); m_alloc.set_probability(1);
const size_t size = c.size(); const size_t size = c.size();
const size_t native_size = native.size(); const size_t native_size = native.size();
...@@ -248,7 +248,7 @@ operator()() ...@@ -248,7 +248,7 @@ operator()()
string_form<Cntnr>::desc()); string_form<Cntnr>::desc());
m_g.init(m_seed); m_g.init(m_seed);
m_alloc.init(m_seed); m_alloc.seed(m_seed);
// The __throw_allocator::_S_label defaults to 0, so to make things // The __throw_allocator::_S_label defaults to 0, so to make things
// easier and more precise when debugging, start at 1. // easier and more precise when debugging, start at 1.
...@@ -363,7 +363,7 @@ operator()() ...@@ -363,7 +363,7 @@ operator()()
} }
// Reset throw probability. // Reset throw probability.
m_alloc.set_throw_prob(0); m_alloc.set_probability(0);
if (m_disp) if (m_disp)
{ {
...@@ -425,9 +425,9 @@ push() ...@@ -425,9 +425,9 @@ push()
try try
{ {
m_alloc.set_throw_prob(0); m_alloc.set_probability(0);
value_type v = test_traits::generate_value(m_g, m_m); value_type v = test_traits::generate_value(m_g, m_m);
m_alloc.set_throw_prob(m_tp); m_alloc.set_probability(m_tp);
const typename cntnr::size_type sz = m_p_c->size(); const typename cntnr::size_type sz = m_p_c->size();
m_p_c->push(v); m_p_c->push(v);
_GLIBCXX_THROW_IF(sz != m_p_c->size() - 1, sz, m_p_c, &m_native_c); _GLIBCXX_THROW_IF(sz != m_p_c->size() - 1, sz, m_p_c, &m_native_c);
...@@ -460,10 +460,10 @@ modify() ...@@ -460,10 +460,10 @@ modify()
bool done = true; bool done = true;
try try
{ {
m_alloc.set_throw_prob(0); m_alloc.set_probability(0);
value_type v = test_traits::generate_value(m_g, m_m); value_type v = test_traits::generate_value(m_g, m_m);
m_alloc.set_throw_prob(m_tp); m_alloc.set_probability(m_tp);
typename cntnr::iterator it = m_p_c->begin(); typename cntnr::iterator it = m_p_c->begin();
std::advance(it, m_g.get_unsigned_long(0, m_p_c->size())); std::advance(it, m_g.get_unsigned_long(0, m_p_c->size()));
if (it != m_p_c->end()) if (it != m_p_c->end())
...@@ -510,7 +510,7 @@ pop() ...@@ -510,7 +510,7 @@ pop()
bool done = true; bool done = true;
try try
{ {
m_alloc.set_throw_prob(1); m_alloc.set_probability(1);
if (!m_p_c->empty()) if (!m_p_c->empty())
{ {
m_p_c->pop(); m_p_c->pop();
...@@ -543,7 +543,7 @@ erase_if() ...@@ -543,7 +543,7 @@ erase_if()
typename std::iterator_traits<typename cntnr::iterator>::reference typename std::iterator_traits<typename cntnr::iterator>::reference
it_const_reference; it_const_reference;
m_alloc.set_throw_prob(1); m_alloc.set_probability(1);
typedef typedef
typename test_traits::template erase_if_fn<value_type> typename test_traits::template erase_if_fn<value_type>
...@@ -582,7 +582,7 @@ erase_it() ...@@ -582,7 +582,7 @@ erase_it()
bool done = true; bool done = true;
try try
{ {
m_alloc.set_throw_prob(1); m_alloc.set_probability(1);
typename cntnr::iterator it = m_p_c->begin(); typename cntnr::iterator it = m_p_c->begin();
std::advance(it, m_g.get_unsigned_long(0, m_p_c->size())); std::advance(it, m_g.get_unsigned_long(0, m_p_c->size()));
...@@ -689,11 +689,11 @@ split_join() ...@@ -689,11 +689,11 @@ split_join()
bool done = true; bool done = true;
try try
{ {
m_alloc.set_throw_prob(0); m_alloc.set_probability(0);
Cntnr lhs(*m_p_c); Cntnr lhs(*m_p_c);
Cntnr rhs; Cntnr rhs;
native_type native_lhs(m_native_c); native_type native_lhs(m_native_c);
m_alloc.set_throw_prob(m_tp); m_alloc.set_probability(m_tp);
typedef typename test_traits::template erase_if_fn<value_type> split_fn_t; typedef typename test_traits::template erase_if_fn<value_type> split_fn_t;
lhs.split(split_fn_t(), rhs); lhs.split(split_fn_t(), rhs);
...@@ -706,7 +706,7 @@ split_join() ...@@ -706,7 +706,7 @@ split_join()
PB_DS_COND_COMPARE(lhs, native_lhs); PB_DS_COND_COMPARE(lhs, native_lhs);
PB_DS_COND_COMPARE(rhs, native_rhs); PB_DS_COND_COMPARE(rhs, native_rhs);
m_alloc.set_throw_prob(m_tp); m_alloc.set_probability(m_tp);
if (m_g.get_prob() < 0.5) if (m_g.get_prob() < 0.5)
lhs.swap(rhs); lhs.swap(rhs);
...@@ -815,7 +815,7 @@ void ...@@ -815,7 +815,7 @@ void
PB_DS_CLASS_C_DEC:: PB_DS_CLASS_C_DEC::
print_container(const native_type& cnt, std::ostream& os) const print_container(const native_type& cnt, std::ostream& os) const
{ {
m_alloc.set_throw_prob(0); m_alloc.set_probability(0);
native_type cpy(cnt); native_type cpy(cnt);
while (!cpy.empty()) while (!cpy.empty())
{ {
...@@ -830,7 +830,7 @@ PB_DS_CLASS_C_DEC:: ...@@ -830,7 +830,7 @@ PB_DS_CLASS_C_DEC::
print_container(const cntnr& cnt, std::ostream& os) const print_container(const cntnr& cnt, std::ostream& os) const
{ {
typedef typename cntnr::const_iterator const_iterator; typedef typename cntnr::const_iterator const_iterator;
m_alloc.set_throw_prob(0); m_alloc.set_probability(0);
for (const_iterator it = cnt.begin(); it != cnt.end(); ++it) for (const_iterator it = cnt.begin(); it != cnt.end(); ++it)
os << *it << std::endl; os << *it << std::endl;
} }
......
...@@ -150,7 +150,7 @@ namespace detail ...@@ -150,7 +150,7 @@ namespace detail
namespace detail namespace detail
{ {
void inline void
usage(const std::string& name) usage(const std::string& name)
{ {
using namespace std; using namespace std;
...@@ -182,7 +182,7 @@ namespace detail ...@@ -182,7 +182,7 @@ namespace detail
cerr << "'t' or 'f' determine whether progress will be displayed" << endl; cerr << "'t' or 'f' determine whether progress will be displayed" << endl;
} }
void inline void
verify_params(size_t& r_seed, size_t& r_n, verify_params(size_t& r_seed, size_t& r_n,
size_t& r_m, double& r_tp, double& r_ip, double& r_dp, size_t& r_m, double& r_tp, double& r_ip, double& r_dp,
double& r_ep, double& r_cp, double& r_mp, bool& r_d) double& r_ep, double& r_cp, double& r_mp, bool& r_d)
......
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