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