+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.
{
_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;
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();)
}
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())
}
else
++it;
- alloc.set_throw_prob(orig_throw_prob);
+ alloc.set_probability(orig_throw_prob);
}
PB_DS_CLASS_T_DEC
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())
{
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
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)
_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;
_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);
{
_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)));
#include <ostream>
#include <stdexcept>
#include <utility>
-#include <tr1/random>
#include <bits/functexcept.h>
#include <bits/move.h>
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+# include <functional>
+# include <random>
+#else
+# include <tr1/functional>
+# include <tr1/random>
+#endif
_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
- class twister_rand_gen
- {
- private:
- std::tr1::mt19937 _M_generator;
-
- public:
- twister_rand_gen(unsigned int s = static_cast<unsigned int>(std::time(0)));
-
- void
- init(unsigned int);
-
- double
- get_prob();
- };
-
- /**
+ /**
* @brief Thown by throw_allocator.
* @ingroup exceptions
*/
#endif
}
- /// Base class.
- class throw_allocator_base
+ // Base class for checking address and label information about
+ // allocations. Create a std::map between the allocated address
+ // (void*) and a datum for annotations, which are a pair of numbers
+ // corresponding to label and allocated size.
+ struct annotate_base
{
- public:
+ annotate_base()
+ {
+ label();
+ map();
+ }
+
+ static void
+ set_label(size_t l)
+ { label() = l; }
+
+ static size_t
+ get_label()
+ { return label(); }
+
void
- init(unsigned long seed);
+ insert(void* p, size_t size)
+ {
+ if (p == NULL)
+ {
+ std::string error("throw_allocator_base::insert null insert!\n");
+ log_to_string(error, make_entry(p, size));
+ std::__throw_logic_error(error.c_str());
+ }
- static void
- set_throw_prob(double throw_prob);
+ const_iterator found = map().find(p);
+ if (found != map().end())
+ {
+ std::string error("throw_allocator_base::insert double insert!\n");
+ log_to_string(error, make_entry(p, size));
+ log_to_string(error, *found);
+ std::__throw_logic_error(error.c_str());
+ }
- static double
- get_throw_prob();
+ map().insert(make_entry(p, size));
+ }
- static void
- set_label(size_t l);
+ void
+ erase(void* p, size_t size)
+ {
+ check_allocated(p, size);
+ map().erase(p);
+ }
- static bool
- empty();
+ // See if a particular address and size has been allocated.
+ inline void
+ check_allocated(void* p, size_t size)
+ {
+ const_iterator found = map().find(p);
+ if (found == map().end())
+ {
+ std::string error("annotate_base::check_allocated by value "
+ "null erase!\n");
+ log_to_string(error, make_entry(p, size));
+ std::__throw_logic_error(error.c_str());
+ }
+
+ if (found->second.second != size)
+ {
+ std::string error("annotate_base::check_allocated by value "
+ "wrong-size erase!\n");
+ log_to_string(error, make_entry(p, size));
+ log_to_string(error, *found);
+ std::__throw_logic_error(error.c_str());
+ }
+ }
- struct group_throw_prob_adjustor
+ // See if a given label has been allocated.
+ inline void
+ check_allocated(size_t label)
{
- group_throw_prob_adjustor(size_t size) : _M_throw_prob_orig(_S_throw_prob)
- {
- _S_throw_prob =
- 1 - std::pow(double(1 - _S_throw_prob), double(0.5 / (size + 1)));
- }
+ const_iterator beg = map().begin();
+ const_iterator end = map().end();
+ std::string found;
+ while (beg != end)
+ {
+ if (beg->second.first == label)
+ log_to_string(found, *beg);
+ ++beg;
+ }
+
+ if (!found.empty())
+ {
+ std::string error("annotate_base::check_allocated by label\n");
+ error += found;
+ std::__throw_logic_error(error.c_str());
+ }
+ }
+
+ private:
+ typedef std::pair<size_t, size_t> data_type;
+ typedef std::map<void*, data_type> map_type;
+ typedef map_type::value_type entry_type;
+ typedef map_type::const_iterator const_iterator;
+ typedef map_type::const_reference const_reference;
- ~group_throw_prob_adjustor()
- { _S_throw_prob = _M_throw_prob_orig; }
+ friend std::ostream&
+ operator<<(std::ostream&, const annotate_base&);
+ entry_type
+ make_entry(void* p, size_t size)
+ { return std::make_pair(p, data_type(get_label(), size)); }
+
+ void
+ log_to_string(std::string& s, const_reference ref) const
+ {
+ char buf[40];
+ const char tab('\t');
+ s += "label: ";
+ unsigned long l = static_cast<unsigned long>(ref.second.first);
+ __builtin_sprintf(buf, "%lu", l);
+ s += buf;
+ s += tab;
+ s += "size: ";
+ l = static_cast<unsigned long>(ref.second.second);
+ __builtin_sprintf(buf, "%lu", l);
+ s += buf;
+ s += tab;
+ s += "address: ";
+ __builtin_sprintf(buf, "%p", ref.first);
+ s += buf;
+ s += '\n';
+ }
+
+ static size_t&
+ label()
+ {
+ static size_t ll;
+ return ll;
+ }
+
+ static map_type&
+ map()
+ {
+ static map_type mp;
+ return mp;
+ }
+ };
+
+ inline std::ostream&
+ operator<<(std::ostream& os, const annotate_base& __b)
+ {
+ std::string error;
+ typedef annotate_base base_type;
+ base_type::const_iterator beg = __b.map().begin();
+ base_type::const_iterator end = __b.map().end();
+ for (; beg != end; ++beg)
+ __b.log_to_string(error, *beg);
+ return os << error;
+ }
+
+ /// Base class for probability control and throw.
+ struct probability_base
+ {
+ // Scope-level probability adjustor objects: set probability for
+ // throw at the beginning of a scope block, and restores to
+ // previous probability when object is destroyed on exiting the
+ // block.
+ struct adjustor_base
+ {
private:
- const double _M_throw_prob_orig;
+ const double _M_prob;
+
+ public:
+ adjustor_base() : _M_prob(get_probability()) { }
+
+ virtual ~adjustor_base()
+ { set_probability(_M_prob); }
};
- struct zero_throw_prob_adjustor
+ // Group condition.
+ struct group_adjustor : public adjustor_base
{
- zero_throw_prob_adjustor() : _M_throw_prob_orig(_S_throw_prob)
- { _S_throw_prob = 0; }
+ group_adjustor(size_t size)
+ { set_probability(1 - std::pow(double(1 - get_probability()),
+ double(0.5 / (size + 1))));
+ }
+ };
- ~zero_throw_prob_adjustor()
- { _S_throw_prob = _M_throw_prob_orig; }
+ // Never enter the condition.
+ struct never_adjustor : public adjustor_base
+ {
+ never_adjustor() { set_probability(0); }
+ };
- private:
- const double _M_throw_prob_orig;
+ // Always enter the condition.
+ struct always_adjustor : public adjustor_base
+ {
+ always_adjustor() { set_probability(1); }
};
- protected:
- static void
- insert(void*, size_t);
+ probability_base()
+ {
+ probability();
+ engine();
+ }
static void
- erase(void*, size_t);
+ set_probability(double __p)
+ { probability() = __p; }
- static void
- throw_conditionally();
+ static double&
+ get_probability()
+ { return probability(); }
- // See if a particular address and size has been allocated by this
- // allocator.
- static void
- check_allocated(void*, size_t);
+ void
+ throw_conditionally()
+ {
+ if (generate() < get_probability())
+ __throw_forced_exception_error();
+ }
- // See if a given label has been allocated by this allocator.
- static void
- check_allocated(size_t);
+ void
+ seed(unsigned long __s)
+ { engine().seed(__s); }
private:
- typedef std::pair<size_t, size_t> alloc_data_type;
- typedef std::map<void*, alloc_data_type> map_type;
- typedef map_type::value_type entry_type;
- typedef map_type::const_iterator const_iterator;
- typedef map_type::const_reference const_reference;
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ typedef std::uniform_real_distribution<double> distribution_type;
+ typedef std::mt19937 engine_type;
+#else
+ typedef std::tr1::uniform_real<double> distribution_type;
+ typedef std::tr1::mt19937 engine_type;
+#endif
- friend std::ostream&
- operator<<(std::ostream&, const throw_allocator_base&);
+ double
+ generate()
+ {
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ const distribution_type distribution(0, 1);
+ static auto generator = std::bind(distribution, engine());
+#else
+ // Use variate_generator to get normalized results.
+ typedef std::tr1::variate_generator<engine_type, distribution_type> gen_t;
+ distribution_type distribution(0, 1);
+ static gen_t generator(engine(), distribution);
+#endif
- static entry_type
- make_entry(void*, size_t);
+ double random = generator();
+ if (random < distribution.min() || random > distribution.max())
+ {
+ std::string __s("throw_allocator::throw_conditionally");
+ __s += "\n";
+ __s += "random number generated is: ";
+ char buf[40];
+ __builtin_sprintf(buf, "%f", random);
+ __s += buf;
+ std::__throw_out_of_range(__s.c_str());
+ }
- static void
- print_to_string(std::string&);
+ return random;
+ }
- static void
- print_to_string(std::string&, const_reference);
+ static double&
+ probability()
+ {
+ static double __p;
+ return __p;
+ }
- static twister_rand_gen _S_g;
- static map_type _S_map;
- static double _S_throw_prob;
- static size_t _S_label;
+ static engine_type&
+ engine()
+ {
+ static engine_type __e;
+ return __e;
+ }
};
- /**
+ /**
* @brief Allocator class with logging and exception control.
* @ingroup allocators
*/
template<typename T>
- class throw_allocator : public throw_allocator_base
+ class throw_allocator
+ : public probability_base, public annotate_base
{
public:
typedef size_t size_type;
typedef value_type& reference;
typedef const value_type& const_reference;
+ private:
+ std::allocator<value_type> _M_allocator;
+ public:
template<typename U>
struct rebind
{
- typedef throw_allocator<U> other;
+ typedef throw_allocator<U> other;
};
throw_allocator() throw() { }
throw_allocator(const throw_allocator&) throw() { }
template<typename U>
- throw_allocator(const throw_allocator<U>&) throw() { }
+ throw_allocator(const throw_allocator<U>&) throw() { }
~throw_allocator() throw() { }
size_type
max_size() const throw()
- { return std::allocator<value_type>().max_size(); }
+ { return _M_allocator.max_size(); }
pointer
allocate(size_type __n, std::allocator<void>::const_pointer hint = 0)
std::__throw_bad_alloc();
throw_conditionally();
- value_type* const a = std::allocator<value_type>().allocate(__n, hint);
+ pointer const a = _M_allocator.allocate(__n, hint);
insert(a, sizeof(value_type) * __n);
return a;
}
void
construct(pointer __p, const T& val)
- { return std::allocator<value_type>().construct(__p, val); }
+ { return _M_allocator.construct(__p, val); }
#ifdef __GXX_EXPERIMENTAL_CXX0X__
template<typename... _Args>
- void
- construct(pointer __p, _Args&&... __args)
- {
- return std::allocator<value_type>().
- construct(__p, std::forward<_Args>(__args)...);
- }
+ void
+ construct(pointer __p, _Args&&... __args)
+ { return _M_allocator.construct(__p, std::forward<_Args>(__args)...); }
#endif
void
destroy(pointer __p)
- { std::allocator<value_type>().destroy(__p); }
+ { _M_allocator.destroy(__p); }
void
deallocate(pointer __p, size_type __n)
{
erase(__p, sizeof(value_type) * __n);
- std::allocator<value_type>().deallocate(__p, __n);
+ _M_allocator.deallocate(__p, __n);
}
void
check_allocated(pointer __p, size_type __n)
- { throw_allocator_base::check_allocated(__p, sizeof(value_type) * __n); }
+ {
+ size_type __t = sizeof(value_type) * __n;
+ annotate_base::check_allocated(__p, __t);
+ }
- void
- check_allocated(size_type label)
- { throw_allocator_base::check_allocated(label); }
+ using annotate_base::check_allocated;
};
template<typename T>
operator!=(const throw_allocator<T>&, const throw_allocator<T>&)
{ return false; }
- std::ostream&
- operator<<(std::ostream& os, const throw_allocator_base& alloc)
- {
- std::string error;
- throw_allocator_base::print_to_string(error);
- os << error;
- return os;
- }
-
- // XXX Should be in .cc.
- twister_rand_gen::
- twister_rand_gen(unsigned int seed) : _M_generator(seed) { }
-
- void
- twister_rand_gen::
- init(unsigned int seed)
- { _M_generator.seed(seed); }
-
- double
- twister_rand_gen::
- get_prob()
- {
- const double min = _M_generator.min();
- const double res = static_cast<const double>(_M_generator() - min);
- const double range = static_cast<const double>(_M_generator.max() - min);
- const double ret = res / range;
- _GLIBCXX_DEBUG_ASSERT(ret >= 0 && ret <= 1);
- return ret;
- }
-
- twister_rand_gen throw_allocator_base::_S_g;
-
- throw_allocator_base::map_type
- throw_allocator_base::_S_map;
-
- double throw_allocator_base::_S_throw_prob;
-
- size_t throw_allocator_base::_S_label = 0;
-
- throw_allocator_base::entry_type
- throw_allocator_base::make_entry(void* p, size_t size)
- { return std::make_pair(p, alloc_data_type(_S_label, size)); }
-
- void
- throw_allocator_base::init(unsigned long seed)
- { _S_g.init(seed); }
-
- void
- throw_allocator_base::set_throw_prob(double throw_prob)
- { _S_throw_prob = throw_prob; }
-
- double
- throw_allocator_base::get_throw_prob()
- { return _S_throw_prob; }
-
- void
- throw_allocator_base::set_label(size_t l)
- { _S_label = l; }
-
- void
- throw_allocator_base::insert(void* p, size_t size)
- {
- const_iterator found_it = _S_map.find(p);
- if (found_it != _S_map.end())
- {
- std::string error("throw_allocator_base::insert");
- error += "double insert!";
- error += '\n';
- print_to_string(error, make_entry(p, size));
- print_to_string(error, *found_it);
- std::__throw_logic_error(error.c_str());
- }
- _S_map.insert(make_entry(p, size));
- }
-
- bool
- throw_allocator_base::empty()
- { return _S_map.empty(); }
-
- void
- throw_allocator_base::erase(void* p, size_t size)
- {
- check_allocated(p, size);
- _S_map.erase(p);
- }
-
- void
- throw_allocator_base::check_allocated(void* p, size_t size)
- {
- const_iterator found_it = _S_map.find(p);
- if (found_it == _S_map.end())
- {
- std::string error("throw_allocator_base::check_allocated by value ");
- error += "null erase!";
- error += '\n';
- print_to_string(error, make_entry(p, size));
- std::__throw_logic_error(error.c_str());
- }
-
- if (found_it->second.second != size)
- {
- std::string error("throw_allocator_base::check_allocated by value ");
- error += "wrong-size erase!";
- error += '\n';
- print_to_string(error, make_entry(p, size));
- print_to_string(error, *found_it);
- std::__throw_logic_error(error.c_str());
- }
- }
-
- void
- throw_allocator_base::check_allocated(size_t label)
- {
- std::string found;
- const_iterator it = _S_map.begin();
- while (it != _S_map.end())
- {
- if (it->second.first == label)
- {
- print_to_string(found, *it);
- }
- ++it;
- }
-
- if (!found.empty())
- {
- std::string error("throw_allocator_base::check_allocated by label ");
- error += '\n';
- error += found;
- std::__throw_logic_error(error.c_str());
- }
- }
-
- void
- throw_allocator_base::throw_conditionally()
- {
- if (_S_g.get_prob() < _S_throw_prob)
- __throw_forced_exception_error();
- }
-
- void
- throw_allocator_base::print_to_string(std::string& s)
- {
- const_iterator begin = throw_allocator_base::_S_map.begin();
- const_iterator end = throw_allocator_base::_S_map.end();
- for (; begin != end; ++begin)
- print_to_string(s, *begin);
- }
-
- void
- throw_allocator_base::print_to_string(std::string& s, const_reference ref)
- {
- char buf[40];
- const char tab('\t');
- s += "address: ";
- __builtin_sprintf(buf, "%p", ref.first);
- s += buf;
- s += tab;
- s += "label: ";
- unsigned long l = static_cast<unsigned long>(ref.second.first);
- __builtin_sprintf(buf, "%lu", l);
- s += buf;
- s += tab;
- s += "size: ";
- l = static_cast<unsigned long>(ref.second.second);
- __builtin_sprintf(buf, "%lu", l);
- s += buf;
- s += '\n';
- }
-
_GLIBCXX_END_NAMESPACE
-#endif
+#endif
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)
try
{
- alloc1.set_throw_prob(1);
+ typename allocator_type::always_adjustor adjust2;
list1.insert(list1.begin(), 10, 99);
VERIFY( false );
}
}
catch (...)
{
- VERIFY( false );
+ __throw_exception_again;
}
VERIFY( list1.size() == size_type(j) );
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 };
try
{
- alloc2.set_throw_prob(1);
+ typename allocator_type::always_adjustor adjust3;
list2.insert(list2.begin(), data, data + 10);
VERIFY( false );
}
{
PB_DS_TRACE("default_constructor");
bool done = true;
- m_alloc.set_throw_prob(m_tp);
+ m_alloc.set_probability(m_tp);
try
{
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;
PB_DS_TRACE("copy_constructor");
bool done = true;
Cntnr* p_c = NULL;
- m_alloc.set_throw_prob(m_tp);
- typename alloc_t::group_throw_prob_adjustor adjust(m_p_c->size());
+ m_alloc.set_probability(m_tp);
+ typename alloc_t::group_adjustor adjust(m_p_c->size());
try
{
PB_DS_TRACE("assignment operator");
bool done = true;
Cntnr* p_c = NULL;
- m_alloc.set_throw_prob(m_tp);
- typename alloc_t::group_throw_prob_adjustor adjust(m_p_c->size());
+ m_alloc.set_probability(m_tp);
+ typename alloc_t::group_adjustor adjust(m_p_c->size());
try
{
{
bool done = true;
Cntnr* p_c = NULL;
- m_alloc.set_throw_prob(m_tp);
- typename alloc_t::group_throw_prob_adjustor adjust(m_p_c->size());
+ m_alloc.set_probability(m_tp);
+ typename alloc_t::group_adjustor adjust(m_p_c->size());
try
{
{
bool done = true;
Cntnr* p_c = NULL;
- m_alloc.set_throw_prob(m_tp);
- typename alloc_t::group_throw_prob_adjustor adjust(m_p_c->size());
+ m_alloc.set_probability(m_tp);
+ typename alloc_t::group_adjustor adjust(m_p_c->size());
try
{
{
bool done = true;
Cntnr* p_c = NULL;
- m_alloc.set_throw_prob(m_tp);
- typename alloc_t::group_throw_prob_adjustor adjust(m_p_c->size());
+ m_alloc.set_probability(m_tp);
+ typename alloc_t::group_adjustor adjust(m_p_c->size());
try
{
{
bool done = true;
Cntnr* p_c = NULL;
- m_alloc.set_throw_prob(m_tp);
- typename alloc_t::group_throw_prob_adjustor adjust(m_p_c->size());
+ m_alloc.set_probability(m_tp);
+ typename alloc_t::group_adjustor adjust(m_p_c->size());
try
{
{
bool done = true;
Cntnr* p_c = NULL;
- m_alloc.set_throw_prob(m_tp);
- typename alloc_t::group_throw_prob_adjustor adjust(m_p_c->size());
+ m_alloc.set_probability(m_tp);
+ typename alloc_t::group_adjustor adjust(m_p_c->size());
try
{
cmp(const Cntnr& r_c, const native_type& r_native_c,
const std::string& r_call_fn)
{
- m_alloc.set_throw_prob(1);
+ m_alloc.set_probability(1);
const size_t size = r_c.size();
const size_t native_size = r_native_c.size();
PB_DS_THROW_IF_FAILED(size == native_size,
{
typename native_type::key_type native_key = test_traits::extract_native_key(*it);
- m_alloc.set_throw_prob(0);
+ m_alloc.set_probability(0);
const key_type k = native_key;
- m_alloc.set_throw_prob(1);
+ m_alloc.set_probability(1);
typename cntnr::const_point_iterator found_it = r_c.find(k);
PB_DS_THROW_IF_FAILED(found_it != r_c.end(),
test_traits::native_val_to_string(*it),
order_statistics_cmp_imp(const Cntnr& r_c, const native_type& r_native_c, __gnu_pbds::detail::true_type)
{
{
- m_alloc.set_throw_prob(0);
+ m_alloc.set_probability(0);
const key_type k = test_traits::generate_key(m_g, m_m);
- m_alloc.set_throw_prob(1);
+ m_alloc.set_probability(1);
const size_type order = r_c.order_of_key(k);
const size_type native_order = std::distance(r_native_c.begin(),
r_native_c.lower_bound(test_traits::native_key(k)));
prefix_search_cmp_imp(const Cntnr& r_c, const native_type& r_native_c, __gnu_pbds::detail::true_type)
{
PB_DS_SET_DESTRUCT_PRINT
- m_alloc.set_throw_prob(0);
+ m_alloc.set_probability(0);
const key_type k = test_traits::generate_key(m_g, m_m);
- m_alloc.set_throw_prob(1);
+ m_alloc.set_probability(1);
try
{
typedef
lower_bound_cmp_imp(const Cntnr& r_c, const native_type& r_native_c, __gnu_pbds::detail::true_type)
{
PB_DS_SET_DESTRUCT_PRINT
- m_alloc.set_throw_prob(0);
+ m_alloc.set_probability(0);
const key_type k = test_traits::generate_key(m_g, m_m);
- m_alloc.set_throw_prob(1);
+ m_alloc.set_probability(1);
typename cntnr::const_iterator it = r_c.lower_bound(k);
typename native_type::key_type native_k = test_traits::native_key(k);
typename native_type::const_iterator native_it = r_native_c.lower_bound(native_k);
upper_bound_cmp_imp(const Cntnr& r_c, const native_type& r_native_c, __gnu_pbds::detail::true_type)
{
PB_DS_SET_DESTRUCT_PRINT
- m_alloc.set_throw_prob(0);
+ m_alloc.set_probability(0);
const key_type k = test_traits::generate_key(m_g, m_m);
- m_alloc.set_throw_prob(1);
+ m_alloc.set_probability(1);
typename cntnr::const_iterator it = r_c.upper_bound(k);
typename native_type::key_type native_k = test_traits::native_key(k);
typename native_type::const_iterator native_it = r_native_c.upper_bound(native_k);
// Track allocation from this point only.
const size_t memory_label = 775;
- m_alloc.init(m_seed);
+ m_alloc.seed(m_seed);
m_alloc.set_label(memory_label);
prog_bar pb(m_n, std::cout, m_disp);
}
// Reset throw probability.
- m_alloc.set_throw_prob(0);
+ m_alloc.set_probability(0);
if (m_disp)
{
PB_DS_SET_DESTRUCT_PRINT
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_key_reference r_k = test_traits::extract_key(v);
typename cntnr::const_point_iterator found_it = m_p_c->find(r_k);
const bool existed = (found_it != m_p_c->end());
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);
(*m_p_c)[v.first] = v.second;
m_native_c[test_traits::native_value(v).first] =
PB_DS_SET_DESTRUCT_PRINT
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);
(*m_p_c)[v] = __gnu_pbds::null_mapped_type();
m_native_c.insert(test_traits::native_value(v));
}
PB_DS_TRACE("erase");
bool done = true;
PB_DS_SET_DESTRUCT_PRINT
- m_alloc.set_throw_prob(0);
+ m_alloc.set_probability(0);
const key_type k = test_traits::generate_key(m_g, m_m);
- m_alloc.set_throw_prob(m_tp);
+ m_alloc.set_probability(m_tp);
try
{
typename test_traits::template erase_if_fn<value_type>
erase_if_fn_t;
- m_alloc.set_throw_prob(m_tp);
+ m_alloc.set_probability(m_tp);
const size_t ersd = m_p_c->erase_if(erase_if_fn_t());
const size_t native_ersd = test_traits::erase_if(m_native_c);
try
{
- m_alloc.set_throw_prob(0);
+ m_alloc.set_probability(0);
const key_type k = test_traits::generate_key(m_g, m_m);
- m_alloc.set_throw_prob(m_tp);
+ m_alloc.set_probability(m_tp);
typename cntnr::iterator found_it = m_p_c->find(k);
try
{
- m_alloc.set_throw_prob(0);
+ m_alloc.set_probability(0);
const key_type k = test_traits::generate_key(m_g, m_m);
- m_alloc.set_throw_prob(m_tp);
+ m_alloc.set_probability(m_tp);
typename cntnr::iterator found_it = m_p_c->find(k);
typename native_type::iterator native_it = m_native_c.find(test_traits::native_key(k));
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);
native_type native_rhs;
const key_type k = test_traits::generate_key(m_g, m_m);
- m_alloc.set_throw_prob(m_tp);
+ m_alloc.set_probability(m_tp);
lhs.split(k, rhs);
typename native_type::const_iterator it =
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);
max_new_size = 2000
};
- m_alloc.set_throw_prob(m_tp);
- typename alloc_t::group_throw_prob_adjustor adjust(m_p_c->size());
+ m_alloc.set_probability(m_tp);
+ typename alloc_t::group_adjustor adjust(m_p_c->size());
const size_t new_size = m_g.get_unsigned_long(min_new_size, max_new_size);
m_p_c->resize(new_size);
const size_t actual_new_size = m_p_c->get_actual_size();
PB_DS_TRACE("get_set_load");
PB_DS_SET_DESTRUCT_PRINT
m_p_c->get_load();
- m_alloc.set_throw_prob(1);
- typename alloc_t::group_throw_prob_adjustor adjust(m_p_c->size());
+ m_alloc.set_probability(1);
+ typename alloc_t::group_adjustor adjust(m_p_c->size());
const float min_load = static_cast<float>(0.05);
const float max_load = static_cast<float>(0.9);
try
{
- m_alloc.set_throw_prob(m_tp);
+ m_alloc.set_probability(m_tp);
- typename alloc_t::group_throw_prob_adjustor adjust(m_p_c->size());
+ typename alloc_t::group_adjustor adjust(m_p_c->size());
const float min_min_load = static_cast<float>(0.05);
const float max_min_load = static_cast<float>(0.2);
PB_DS_CLASS_C_DEC::
print_container(const native_type& r_cnt, std::ostream& r_os) const
{
- m_alloc.set_throw_prob(0);
+ m_alloc.set_probability(0);
typename native_type::const_iterator it = r_cnt.begin();
while (it != r_cnt.end())
{
PB_DS_CLASS_C_DEC::
print_container(const cntnr& r_cnt, std::ostream& r_os) const
{
- m_alloc.set_throw_prob(0);
+ m_alloc.set_probability(0);
typename cntnr::const_iterator it = r_cnt.begin();
while (it != r_cnt.end())
{
namespace detail
{
- void
+ inline void
usage(const std::string& name)
{
using namespace std;
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)
{
PB_DS_TRACE("default_constructor");
bool done = true;
- m_alloc.set_throw_prob(m_tp);
+ m_alloc.set_probability(m_tp);
try
{
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;
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
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
{
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
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();
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.
}
// Reset throw probability.
- m_alloc.set_throw_prob(0);
+ m_alloc.set_probability(0);
if (m_disp)
{
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);
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())
bool done = true;
try
{
- m_alloc.set_throw_prob(1);
+ m_alloc.set_probability(1);
if (!m_p_c->empty())
{
m_p_c->pop();
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>
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()));
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);
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);
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())
{
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;
}
namespace detail
{
- void
+ inline void
usage(const std::string& name)
{
using namespace std;
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)