Commit 191e7a30 by Benjamin Kosnik Committed by Benjamin Kosnik

hash_load_check_resize_trigger_imp.hpp: Adjust assert condition.

2011-01-20  Benjamin Kosnik  <bkoz@redhat.com>

	* include/ext/pb_ds/detail/resize_policy/
	hash_load_check_resize_trigger_imp.hpp: Adjust assert condition.
	* include/ext/pb_ds/detail/pat_trie_/
	constructors_destructor_fn_imps.hpp: Same.
	* include/ext/pb_ds/detail/binary_heap_/erase_fn_imps.hpp: Format.
	* include/ext/pb_ds/detail/ov_tree_map_/debug_fn_imps.hpp: Same.
	* include/ext/pb_ds/detail/debug_map_base.hpp: Use never_adjustor.

	* testsuite/ext/pb_ds/regression/hash_data_map_rand.cc: Adjust
	iterations downward when testing in debug mode.
	* testsuite/ext/pb_ds/regression/trie_data_map_rand.cc: Same.
	* testsuite/ext/pb_ds/regression/tree_no_data_map_rand.cc: Same.
	* testsuite/ext/pb_ds/regression/hash_no_data_map_rand.cc: Same.
	* testsuite/ext/pb_ds/regression/tree_data_map_rand.cc: Same.
	* testsuite/ext/pb_ds/regression/trie_no_data_map_rand.cc: Same.
	* testsuite/ext/pb_ds/example/hash_illegal_resize.cc: Use SIZE,
	reduce in debug mode.

From-SVN: r169061
parent a1a79768
2011-01-20 Benjamin Kosnik <bkoz@redhat.com>
* include/ext/pb_ds/detail/resize_policy/
hash_load_check_resize_trigger_imp.hpp: Adjust assert condition.
* include/ext/pb_ds/detail/pat_trie_/
constructors_destructor_fn_imps.hpp: Same.
* include/ext/pb_ds/detail/binary_heap_/erase_fn_imps.hpp: Format.
* include/ext/pb_ds/detail/ov_tree_map_/debug_fn_imps.hpp: Same.
* include/ext/pb_ds/detail/debug_map_base.hpp: Use never_adjustor.
* testsuite/ext/pb_ds/regression/hash_data_map_rand.cc: Adjust
iterations downward when testing in debug mode.
* testsuite/ext/pb_ds/regression/trie_data_map_rand.cc: Same.
* testsuite/ext/pb_ds/regression/tree_no_data_map_rand.cc: Same.
* testsuite/ext/pb_ds/regression/hash_no_data_map_rand.cc: Same.
* testsuite/ext/pb_ds/regression/tree_data_map_rand.cc: Same.
* testsuite/ext/pb_ds/regression/trie_no_data_map_rand.cc: Same.
* testsuite/ext/pb_ds/example/hash_illegal_resize.cc: Use SIZE,
reduce in debug mode.
2011-01-19 Benjamin Kosnik <bkoz@redhat.com> 2011-01-19 Benjamin Kosnik <bkoz@redhat.com>
PR libstdc++/36104 part two PR libstdc++/36104 part two
......
// -*- C++ -*- // -*- C++ -*-
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2011
// Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the terms
...@@ -66,7 +67,7 @@ clear() ...@@ -66,7 +67,7 @@ clear()
m_size = 0; m_size = 0;
_GLIBCXX_DEBUG_ONLY(assert_valid();) _GLIBCXX_DEBUG_ONLY(assert_valid();)
} }
PB_DS_CLASS_T_DEC PB_DS_CLASS_T_DEC
void void
...@@ -74,7 +75,6 @@ PB_DS_CLASS_C_DEC:: ...@@ -74,7 +75,6 @@ PB_DS_CLASS_C_DEC::
erase_at(entry_pointer a_entries, size_type i, false_type) erase_at(entry_pointer a_entries, size_type i, false_type)
{ {
a_entries[i]->~value_type(); a_entries[i]->~value_type();
s_value_allocator.deallocate(a_entries[i], 1); s_value_allocator.deallocate(a_entries[i], 1);
} }
...@@ -90,11 +90,12 @@ PB_DS_CLASS_C_DEC:: ...@@ -90,11 +90,12 @@ PB_DS_CLASS_C_DEC::
pop() pop()
{ {
_GLIBCXX_DEBUG_ONLY(assert_valid();) _GLIBCXX_DEBUG_ONLY(assert_valid();)
_GLIBCXX_DEBUG_ASSERT(!empty()); _GLIBCXX_DEBUG_ASSERT(!empty());
erase_at(m_a_entries, 0, s_no_throw_copies_ind); erase_at(m_a_entries, 0, s_no_throw_copies_ind);
std::pop_heap(m_a_entries, m_a_entries + m_size, static_cast<entry_cmp& >(*this)); std::pop_heap(m_a_entries, m_a_entries + m_size,
static_cast<entry_cmp& >(*this));
resize_for_erase_if_needed(); resize_for_erase_if_needed();
...@@ -102,7 +103,7 @@ pop() ...@@ -102,7 +103,7 @@ pop()
--m_size; --m_size;
_GLIBCXX_DEBUG_ONLY(assert_valid();) _GLIBCXX_DEBUG_ONLY(assert_valid();)
} }
PB_DS_CLASS_T_DEC PB_DS_CLASS_T_DEC
template<typename Pred> template<typename Pred>
...@@ -112,12 +113,7 @@ erase_if(Pred pred) ...@@ -112,12 +113,7 @@ erase_if(Pred pred)
{ {
_GLIBCXX_DEBUG_ONLY(assert_valid();) _GLIBCXX_DEBUG_ONLY(assert_valid();)
typedef typedef typename entry_pred<value_type, Pred, simple_value, Allocator>::type
typename entry_pred<
value_type,
Pred,
simple_value,
Allocator>::type
pred_t; pred_t;
const size_type left = partition(pred_t(pred)); const size_type left = partition(pred_t(pred));
...@@ -149,11 +145,12 @@ erase_if(Pred pred) ...@@ -149,11 +145,12 @@ erase_if(Pred pred)
m_size = left; m_size = left;
std::make_heap(m_a_entries, m_a_entries + m_size, static_cast<entry_cmp& >(*this)); std::make_heap(m_a_entries, m_a_entries + m_size,
static_cast<entry_cmp& >(*this));
_GLIBCXX_DEBUG_ONLY(assert_valid();) _GLIBCXX_DEBUG_ONLY(assert_valid();)
return ersd; return ersd;
} }
PB_DS_CLASS_T_DEC PB_DS_CLASS_T_DEC
...@@ -162,7 +159,7 @@ PB_DS_CLASS_C_DEC:: ...@@ -162,7 +159,7 @@ PB_DS_CLASS_C_DEC::
erase(point_iterator it) erase(point_iterator it)
{ {
_GLIBCXX_DEBUG_ONLY(assert_valid();) _GLIBCXX_DEBUG_ONLY(assert_valid();)
_GLIBCXX_DEBUG_ASSERT(!empty()); _GLIBCXX_DEBUG_ASSERT(!empty());
const size_type fix_pos = it.m_p_e - m_a_entries; const size_type fix_pos = it.m_p_e - m_a_entries;
...@@ -181,7 +178,7 @@ erase(point_iterator it) ...@@ -181,7 +178,7 @@ erase(point_iterator it)
fix(m_a_entries + fix_pos); fix(m_a_entries + fix_pos);
_GLIBCXX_DEBUG_ONLY(assert_valid();) _GLIBCXX_DEBUG_ONLY(assert_valid();)
} }
PB_DS_CLASS_T_DEC PB_DS_CLASS_T_DEC
inline void inline void
...@@ -231,16 +228,15 @@ partition(Pred pred) ...@@ -231,16 +228,15 @@ partition(Pred pred)
else if (pred(m_a_entries[right])) else if (pred(m_a_entries[right]))
--right; --right;
else else
{ {
_GLIBCXX_DEBUG_ASSERT(left < right); _GLIBCXX_DEBUG_ASSERT(left < right);
std::swap(m_a_entries[left], m_a_entries[right]); std::swap(m_a_entries[left], m_a_entries[right]);
++left; ++left;
--right; --right;
} }
} }
return left; return left;
} }
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
// representation about the suitability of this software for any // representation about the suitability of this software for any
// purpose. It is provided "as is" without express or implied // purpose. It is provided "as is" without express or implied
// warranty. // warranty.
/** /**
* @file debug_map_base.hpp * @file debug_map_base.hpp
* Contains a debug-mode base for all maps. * Contains a debug-mode base for all maps.
...@@ -58,7 +58,7 @@ namespace __gnu_pbds ...@@ -58,7 +58,7 @@ namespace __gnu_pbds
// Need std::pair ostream extractor. // Need std::pair ostream extractor.
template<typename _CharT, typename _Traits, typename _Tp1, typename _Tp2> template<typename _CharT, typename _Traits, typename _Tp1, typename _Tp2>
inline std::basic_ostream<_CharT, _Traits>& inline std::basic_ostream<_CharT, _Traits>&
operator<<(std::basic_ostream<_CharT, _Traits>& __out, operator<<(std::basic_ostream<_CharT, _Traits>& __out,
const std::pair<_Tp1, _Tp2>& p) const std::pair<_Tp1, _Tp2>& p)
{ return (__out << '(' << p.first << ',' << p.second << ')'); } { return (__out << '(' << p.first << ',' << p.second << ')'); }
...@@ -72,11 +72,14 @@ namespace __gnu_pbds ...@@ -72,11 +72,14 @@ namespace __gnu_pbds
class debug_map_base class debug_map_base
{ {
private: private:
typedef typename std::allocator< Key> key_allocator; typedef typename std::allocator<Key> key_allocator;
typedef typename key_allocator::size_type size_type;
typedef typename key_allocator::size_type size_type; typedef Const_Key_Reference const_key_reference;
typedef std::__norm::list<Key> key_set;
typedef Const_Key_Reference const_key_reference; typedef typename key_set::iterator key_set_iterator;
typedef typename key_set::const_iterator const_key_set_iterator;
typedef __gnu_cxx::throw_allocator_random<Key> key_db_allocator;
typedef typename key_db_allocator::never_adjustor never_adjustor;
protected: protected:
debug_map_base(); debug_map_base();
...@@ -114,14 +117,8 @@ namespace __gnu_pbds ...@@ -114,14 +117,8 @@ namespace __gnu_pbds
join(PB_DS_CLASS_C_DEC& other); join(PB_DS_CLASS_C_DEC& other);
private: private:
typedef std::list< Key> key_set;
typedef typename key_set::iterator key_set_iterator;
typedef typename key_set::const_iterator const_key_set_iterator;
#ifdef _GLIBCXX_DEBUG
void void
assert_valid() const; assert_valid() const;
#endif
const_key_set_iterator const_key_set_iterator
find(const_key_reference r_key) const; find(const_key_reference r_key) const;
...@@ -154,26 +151,24 @@ namespace __gnu_pbds ...@@ -154,26 +151,24 @@ namespace __gnu_pbds
insert_new(const_key_reference r_key) insert_new(const_key_reference r_key)
{ {
_GLIBCXX_DEBUG_ONLY(assert_valid();) _GLIBCXX_DEBUG_ONLY(assert_valid();)
// XXX FIXME: Adapt for __gnu_cxx::throw_allocator_random.
//__gnu_cxx::throw_allocator<char> alloc;
// const double orig_throw_prob = alloc.get_probability();
// 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 key already present " << r_key << std::endl;
std::abort(); std::abort;
} }
never_adjustor never;
__try __try
{ {
m_key_set.push_back(r_key); m_key_set.push_back(r_key);
} }
__catch(...) __catch(...)
{ {
std::cerr << "insert_new" << r_key << std::endl; std::cerr << "insert_new " << r_key << std::endl;
std::abort(); std::abort();
} }
// alloc.set_probability(orig_throw_prob);
_GLIBCXX_DEBUG_ONLY(assert_valid();) _GLIBCXX_DEBUG_ONLY(assert_valid();)
} }
...@@ -210,10 +205,10 @@ namespace __gnu_pbds ...@@ -210,10 +205,10 @@ namespace __gnu_pbds
{ {
_GLIBCXX_DEBUG_ONLY(assert_valid();) _GLIBCXX_DEBUG_ONLY(assert_valid();)
if (find(r_key) == m_key_set.end()) if (find(r_key) == m_key_set.end())
{ {
std::cerr << "check_key_exists" << r_key << std::endl; std::cerr << "check_key_exists " << r_key << std::endl;
std::abort(); std::abort();
} }
_GLIBCXX_DEBUG_ONLY(assert_valid();) _GLIBCXX_DEBUG_ONLY(assert_valid();)
} }
...@@ -224,12 +219,12 @@ namespace __gnu_pbds ...@@ -224,12 +219,12 @@ namespace __gnu_pbds
{ {
_GLIBCXX_DEBUG_ONLY(assert_valid();) _GLIBCXX_DEBUG_ONLY(assert_valid();)
if (find(r_key) != m_key_set.end()) if (find(r_key) != m_key_set.end())
{ {
using std::cerr; using std::cerr;
using std::endl; using std::endl;
cerr << "check_key_does_not_exist" << r_key << endl; cerr << "check_key_does_not_exist " << r_key << endl;
std::abort(); std::abort();
} }
} }
PB_DS_CLASS_T_DEC PB_DS_CLASS_T_DEC
...@@ -241,7 +236,7 @@ namespace __gnu_pbds ...@@ -241,7 +236,7 @@ namespace __gnu_pbds
const size_type key_set_size = m_key_set.size(); const size_type key_set_size = m_key_set.size();
if (size != key_set_size) if (size != key_set_size)
{ {
std::cerr << "check_size " << size std::cerr << "check_size " << size
<< " " << key_set_size << std::endl; << " " << key_set_size << std::endl;
std::abort(); std::abort();
} }
...@@ -267,7 +262,7 @@ namespace __gnu_pbds ...@@ -267,7 +262,7 @@ namespace __gnu_pbds
typedef const_key_set_iterator iterator_type; typedef const_key_set_iterator iterator_type;
for (iterator_type it = m_key_set.begin(); it != m_key_set.end(); ++it) for (iterator_type it = m_key_set.begin(); it != m_key_set.end(); ++it)
if (m_eq(*it, r_key)) if (m_eq(*it, r_key))
return it; return it;
return m_key_set.end(); return m_key_set.end();
} }
...@@ -281,14 +276,13 @@ namespace __gnu_pbds ...@@ -281,14 +276,13 @@ namespace __gnu_pbds
while (it != m_key_set.end()) while (it != m_key_set.end())
{ {
if (m_eq(*it, r_key)) if (m_eq(*it, r_key))
return it; return it;
++it; ++it;
} }
return it; return it;
_GLIBCXX_DEBUG_ONLY(assert_valid();) _GLIBCXX_DEBUG_ONLY(assert_valid();)
} }
#ifdef _GLIBCXX_DEBUG
PB_DS_CLASS_T_DEC PB_DS_CLASS_T_DEC
void void
PB_DS_CLASS_C_DEC:: PB_DS_CLASS_C_DEC::
...@@ -308,7 +302,6 @@ namespace __gnu_pbds ...@@ -308,7 +302,6 @@ namespace __gnu_pbds
++prime_it; ++prime_it;
} }
} }
#endif
PB_DS_CLASS_T_DEC PB_DS_CLASS_T_DEC
template<typename Cmp_Fn> template<typename Cmp_Fn>
...@@ -316,21 +309,16 @@ namespace __gnu_pbds ...@@ -316,21 +309,16 @@ namespace __gnu_pbds
PB_DS_CLASS_C_DEC:: PB_DS_CLASS_C_DEC::
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)
{ {
// XXX FIXME: Adapt for __gnu_cxx::throw_allocator_random.
// __gnu_cxx::throw_allocator<char> alloc;
// const double orig_throw_prob = alloc.get_probability();
// 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())
if (cmp_fn(r_key, * it)) if (cmp_fn(r_key, * it))
{ {
other.insert_new(*it); other.insert_new(*it);
it = m_key_set.erase(it); it = m_key_set.erase(it);
} }
else else
++it; ++it;
// alloc.set_probability(orig_throw_prob);
} }
PB_DS_CLASS_T_DEC PB_DS_CLASS_T_DEC
...@@ -338,10 +326,6 @@ namespace __gnu_pbds ...@@ -338,10 +326,6 @@ namespace __gnu_pbds
PB_DS_CLASS_C_DEC:: PB_DS_CLASS_C_DEC::
join(PB_DS_CLASS_C_DEC& other) join(PB_DS_CLASS_C_DEC& other)
{ {
// XXX FIXME: Adapt for __gnu_cxx::throw_allocator_random.
// __gnu_cxx::throw_allocator<char> alloc;
// const double orig_throw_prob = alloc.get_probability();
// 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())
{ {
...@@ -349,7 +333,6 @@ namespace __gnu_pbds ...@@ -349,7 +333,6 @@ 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_probability(orig_throw_prob);
} }
#undef PB_DS_CLASS_T_DEC #undef PB_DS_CLASS_T_DEC
...@@ -358,7 +341,6 @@ namespace __gnu_pbds ...@@ -358,7 +341,6 @@ namespace __gnu_pbds
} // namespace detail } // namespace detail
} // namespace __gnu_pbds } // namespace __gnu_pbds
#endif #endif
#endif
#endif
// -*- C++ -*- // -*- C++ -*-
// Copyright (C) 2005, 2006, 2009, 2010 Free Software Foundation, Inc. // Copyright (C) 2005, 2006, 2009, 2010, 2011 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the terms
...@@ -46,7 +46,6 @@ PB_DS_CLASS_C_DEC:: ...@@ -46,7 +46,6 @@ PB_DS_CLASS_C_DEC::
assert_valid() const assert_valid() const
{ {
std::cout << "av1" << std::endl; std::cout << "av1" << std::endl;
if (m_a_values == 0 || m_end_it == 0 || m_size == 0) if (m_a_values == 0 || m_end_it == 0 || m_size == 0)
_GLIBCXX_DEBUG_ASSERT(m_a_values == 0 && m_end_it == 0 && m_size == 0); _GLIBCXX_DEBUG_ASSERT(m_a_values == 0 && m_end_it == 0 && m_size == 0);
...@@ -63,7 +62,7 @@ assert_iterators() const ...@@ -63,7 +62,7 @@ assert_iterators() const
debug_base::check_size(m_size); debug_base::check_size(m_size);
size_type iterated_num = 0; size_type iterated_num = 0;
const_iterator prev_it = end(); const_iterator prev_it = end();
_GLIBCXX_DEBUG_ASSERT( m_end_it == m_a_values + m_size); _GLIBCXX_DEBUG_ASSERT(m_end_it == m_a_values + m_size);
for (const_iterator it = begin(); it != end(); ++it) for (const_iterator it = begin(); it != end(); ++it)
{ {
++iterated_num; ++iterated_num;
......
...@@ -77,7 +77,7 @@ PB_DS_CLASS_C_DEC:: ...@@ -77,7 +77,7 @@ PB_DS_CLASS_C_DEC::
PB_DS_CLASS_NAME(const PB_DS_CLASS_C_DEC& other) : PB_DS_CLASS_NAME(const PB_DS_CLASS_C_DEC& other) :
#ifdef _GLIBCXX_DEBUG #ifdef _GLIBCXX_DEBUG
debug_base(other), debug_base(other),
#endif #endif
synth_e_access_traits(other), synth_e_access_traits(other),
node_update(other), node_update(other),
m_p_head(s_head_allocator.allocate(1)), m_p_head(s_head_allocator.allocate(1)),
...@@ -88,8 +88,8 @@ PB_DS_CLASS_NAME(const PB_DS_CLASS_C_DEC& other) : ...@@ -88,8 +88,8 @@ PB_DS_CLASS_NAME(const PB_DS_CLASS_C_DEC& other) :
_GLIBCXX_DEBUG_ONLY(other.assert_valid();) _GLIBCXX_DEBUG_ONLY(other.assert_valid();)
if (other.m_p_head->m_p_parent == 0) if (other.m_p_head->m_p_parent == 0)
{ {
_GLIBCXX_DEBUG_ONLY(assert_valid();) _GLIBCXX_DEBUG_ONLY(assert_valid();)
return; return;
} }
__try __try
{ {
...@@ -205,7 +205,7 @@ recursive_copy_node(const_node_pointer p_other_nd) ...@@ -205,7 +205,7 @@ recursive_copy_node(const_node_pointer p_other_nd)
pref_begin(a_p_children[0])); pref_begin(a_p_children[0]));
--child_i; --child_i;
_GLIBCXX_DEBUG_ASSERT(child_i > 1); _GLIBCXX_DEBUG_ASSERT(child_i >= 1);
do do
p_ret->add_child(a_p_children[child_i], pref_begin(a_p_children[child_i]), p_ret->add_child(a_p_children[child_i], pref_begin(a_p_children[child_i]),
pref_end(a_p_children[child_i]), this); pref_end(a_p_children[child_i]), this);
......
// -*- C++ -*- // -*- C++ -*-
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2011
// Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the terms
...@@ -40,7 +41,7 @@ ...@@ -40,7 +41,7 @@
PB_DS_CLASS_T_DEC PB_DS_CLASS_T_DEC
PB_DS_CLASS_C_DEC:: PB_DS_CLASS_C_DEC::
hash_load_check_resize_trigger(float load_min, float load_max) hash_load_check_resize_trigger(float load_min, float load_max)
: m_load_min(load_min), m_load_max(load_max), m_next_shrink_size(0), : m_load_min(load_min), m_load_max(load_max), m_next_shrink_size(0),
m_next_grow_size(0), m_resize_needed(false) m_next_grow_size(0), m_resize_needed(false)
{ _GLIBCXX_DEBUG_ONLY(assert_valid();) } { _GLIBCXX_DEBUG_ONLY(assert_valid();) }
...@@ -151,13 +152,13 @@ notify_resized(size_type new_size) ...@@ -151,13 +152,13 @@ notify_resized(size_type new_size)
m_next_shrink_size = size_type(m_load_min * new_size); m_next_shrink_size = size_type(m_load_min * new_size);
#ifdef PB_DS_HT_MAP_RESIZE_TRACE_ #ifdef PB_DS_HT_MAP_RESIZE_TRACE_
std::cerr << "hlcrt::notify_resized " << std::cerr << "hlcrt::notify_resized " << std::endl
static_cast<unsigned long>(new_size) << " " << << "1 " << new_size << std::endl
static_cast<unsigned long>(m_load_min) << " " << << "2 " << m_load_min << std::endl
static_cast<unsigned long>(m_load_max) << " " << << "3 " << m_load_max << std::endl
static_cast<unsigned long>(m_next_shrink_size) << " " << << "4 " << m_next_shrink_size << std::endl
static_cast<unsigned long>(m_next_grow_size) << " " << std::endl; << "5 " << m_next_grow_size << std::endl;
#endif #endif
_GLIBCXX_DEBUG_ONLY(assert_valid();) _GLIBCXX_DEBUG_ONLY(assert_valid();)
} }
...@@ -170,34 +171,28 @@ notify_externally_resized(size_type new_size) ...@@ -170,34 +171,28 @@ notify_externally_resized(size_type new_size)
m_resize_needed = false; m_resize_needed = false;
size_type new_grow_size = size_type(m_load_max * new_size - 1); size_type new_grow_size = size_type(m_load_max * new_size - 1);
size_type new_shrink_size = size_type(m_load_min * new_size); size_type new_shrink_size = size_type(m_load_min * new_size);
#ifdef PB_DS_HT_MAP_RESIZE_TRACE_
std::cerr << "hlcrt::notify_externally_resized " << std::endl
<< "1 " << new_size << std::endl
<< "2 " << m_load_min << std::endl
<< "3 " << m_load_max << std::endl
<< "4 " << m_next_shrink_size << std::endl
<< "5 " << m_next_grow_size << std::endl
<< "6 " << new_shrink_size << std::endl
<< "7 " << new_grow_size << std::endl;
#endif
if (new_grow_size >= m_next_grow_size) if (new_grow_size >= m_next_grow_size)
{ {
_GLIBCXX_DEBUG_ASSERT(new_shrink_size > m_next_shrink_size); _GLIBCXX_DEBUG_ASSERT(new_shrink_size >= m_next_shrink_size);
m_next_grow_size = new_grow_size; m_next_grow_size = new_grow_size;
_GLIBCXX_DEBUG_ONLY(assert_valid();)
#ifdef PB_DS_HT_MAP_RESIZE_TRACE_
std::cerr << "hlcrt::notify_externally_resized1 " <<
static_cast<unsigned long>(new_size) << " " <<
static_cast<unsigned long>(m_load_min) << " " <<
static_cast<unsigned long>(m_load_max) << " " <<
static_cast<unsigned long>(m_next_shrink_size) << " " <<
static_cast<unsigned long>(m_next_grow_size) << " " << std::endl;
#endif
return;
} }
else
_GLIBCXX_DEBUG_ASSERT(new_shrink_size <= m_next_shrink_size); {
m_next_shrink_size = new_shrink_size; _GLIBCXX_DEBUG_ASSERT(new_shrink_size <= m_next_shrink_size);
m_next_shrink_size = new_shrink_size;
#ifdef PB_DS_HT_MAP_RESIZE_TRACE_ }
std::cerr << "hlcrt::notify_externally_resized2 " <<
static_cast<unsigned long>(new_size) << " " <<
static_cast<unsigned long>(m_load_min) << " " <<
static_cast<unsigned long>(m_load_max) << " " <<
static_cast<unsigned long>(m_next_shrink_size) << " " <<
static_cast<unsigned long>(m_next_grow_size) << " " << std::endl;
#endif
_GLIBCXX_DEBUG_ONLY(assert_valid();) _GLIBCXX_DEBUG_ONLY(assert_valid();)
} }
...@@ -220,7 +215,7 @@ swap(PB_DS_CLASS_C_DEC& other) ...@@ -220,7 +215,7 @@ swap(PB_DS_CLASS_C_DEC& other)
{ {
_GLIBCXX_DEBUG_ONLY(assert_valid();) _GLIBCXX_DEBUG_ONLY(assert_valid();)
_GLIBCXX_DEBUG_ONLY(other.assert_valid();) _GLIBCXX_DEBUG_ONLY(other.assert_valid();)
size_base::swap(other); size_base::swap(other);
std::swap(m_load_min, other.m_load_min); std::swap(m_load_min, other.m_load_min);
std::swap(m_load_max, other.m_load_max); std::swap(m_load_max, other.m_load_max);
...@@ -285,5 +280,4 @@ assert_valid() const ...@@ -285,5 +280,4 @@ assert_valid() const
_GLIBCXX_DEBUG_ASSERT(m_load_max > m_load_min); _GLIBCXX_DEBUG_ASSERT(m_load_max > m_load_min);
_GLIBCXX_DEBUG_ASSERT(m_next_grow_size >= m_next_shrink_size); _GLIBCXX_DEBUG_ASSERT(m_next_grow_size >= m_next_shrink_size);
} }
#endif #endif
// { dg-timeout-factor 2.0 }
// -*- C++ -*- // -*- C++ -*-
// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. // Copyright (C) 2005, 2006, 2009, 2011 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the terms
...@@ -31,8 +33,7 @@ ...@@ -31,8 +33,7 @@
/** /**
* @file hash_illegal_resize_example.cpp * @file hash_illegal_resize_example.cpp
* An example of illegally * An example of illegally externally resizing a hash-based container object.
* externally resizing a hash-based container object.
*/ */
/** /**
...@@ -46,6 +47,15 @@ ...@@ -46,6 +47,15 @@
#include <ext/pb_ds/exception.hpp> #include <ext/pb_ds/exception.hpp>
#include <cassert> #include <cassert>
// size of test containers
#ifdef _GLIBCXX_DEBUG
# define SIZE 100
# define RESIZE 20
#else
# define SIZE 1000
# define RESIZE 200
#endif
using namespace std; using namespace std;
using namespace __gnu_pbds; using namespace __gnu_pbds;
...@@ -68,8 +78,7 @@ int main() ...@@ -68,8 +78,7 @@ int main()
int, int,
int, int,
int_hash, int_hash,
equal_to< equal_to<int>,
int>,
// Combining function. // Combining function.
direct_mod_range_hashing<>, direct_mod_range_hashing<>,
// Probe function. // Probe function.
...@@ -90,20 +99,20 @@ int main() ...@@ -90,20 +99,20 @@ int main()
// Insert some elements. // Insert some elements.
int i; int i;
for (i = 0; i < 1000; ++i) for (i = 0; i < SIZE; ++i)
g[i] = 2* i; g[i] = 2* i;
// Check all ok. // Check all ok.
assert(g.size() == 1000); assert(g.size() == SIZE);
for (i = 0; i < 1000; ++i) for (i = 0; i < SIZE; ++i)
assert(g.find(i) != g.end()&& g.find(i)->second == 2* i); assert(g.find(i) != g.end() && g.find(i)->second == 2 * i);
// Now attempt to resize the table to 200 (impossible). // Now attempt to resize the table to 200 (impossible).
bool ex_thrown = false; bool ex_thrown = false;
try try
{ {
g.resize(200); g.resize(RESIZE);
} }
catch(__gnu_pbds::resize_error& ) catch(__gnu_pbds::resize_error& )
{ {
...@@ -118,10 +127,9 @@ int main() ...@@ -118,10 +127,9 @@ int main()
// container object should still be in a valid state; the following // container object should still be in a valid state; the following
// checks this. // checks this.
// Check all ok. // Check all ok.
assert(g.size() == 1000); assert(g.size() == SIZE);
for (i = 0; i < 1000; ++i) for (i = 0; i < SIZE; ++i)
assert(g.find(i) != g.end()&& g.find(i)->second == 2* i); assert(g.find(i) != g.end() && g.find(i)->second == 2 * i);
return 0; return 0;
} }
...@@ -45,11 +45,21 @@ ...@@ -45,11 +45,21 @@
#include <regression/common_type.hpp> #include <regression/common_type.hpp>
#ifndef ITERATIONS #ifndef ITERATIONS
#define ITERATIONS 5000 # ifdef _GLIBCXX_DEBUG
# define ITERATIONS 100
# else
# define ITERATIONS 5000
#endif #endif
#endif
#ifndef KEYS #ifndef KEYS
#define KEYS 10000 # ifdef _GLIBCXX_DEBUG
# define KEYS 200
# else
# define KEYS 10000
# endif
#endif #endif
int int
main(int argc, char* a_p_argv[]) main(int argc, char* a_p_argv[])
{ {
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
// -*- C++ -*- // -*- C++ -*-
// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. // Copyright (C) 2005, 2006, 2009, 2011 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the terms
...@@ -45,11 +45,21 @@ ...@@ -45,11 +45,21 @@
#include <regression/common_type.hpp> #include <regression/common_type.hpp>
#ifndef ITERATIONS #ifndef ITERATIONS
#define ITERATIONS 5000 # ifdef _GLIBCXX_DEBUG
# define ITERATIONS 100
# else
# define ITERATIONS 5000
#endif #endif
#endif
#ifndef KEYS #ifndef KEYS
#define KEYS 10000 # ifdef _GLIBCXX_DEBUG
# define KEYS 200
# else
# define KEYS 10000
# endif
#endif #endif
int int
main(int argc, char* a_p_argv[]) main(int argc, char* a_p_argv[])
{ {
...@@ -60,4 +70,3 @@ main(int argc, char* a_p_argv[]) ...@@ -60,4 +70,3 @@ main(int argc, char* a_p_argv[])
"hash_no_data_map_rand_regression_test", "hash_no_data_map_rand_regression_test",
map_tl_t()); map_tl_t());
} }
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
// -*- C++ -*- // -*- C++ -*-
// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. // Copyright (C) 2005, 2006, 2009, 2011 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the terms
...@@ -45,11 +45,21 @@ ...@@ -45,11 +45,21 @@
#include <regression/common_type.hpp> #include <regression/common_type.hpp>
#ifndef ITERATIONS #ifndef ITERATIONS
#define ITERATIONS 5000 # ifdef _GLIBCXX_DEBUG
# define ITERATIONS 100
# else
# define ITERATIONS 5000
#endif #endif
#endif
#ifndef KEYS #ifndef KEYS
#define KEYS 10000 # ifdef _GLIBCXX_DEBUG
# define KEYS 200
# else
# define KEYS 10000
# endif
#endif #endif
int int
main(int argc, char* a_p_argv[]) main(int argc, char* a_p_argv[])
{ {
...@@ -60,4 +70,3 @@ main(int argc, char* a_p_argv[]) ...@@ -60,4 +70,3 @@ main(int argc, char* a_p_argv[])
"tree_data_map_rand_regression_test", "tree_data_map_rand_regression_test",
map_tl_t()); map_tl_t());
} }
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
// -*- C++ -*- // -*- C++ -*-
// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. // Copyright (C) 2005, 2006, 2009, 2011 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the terms
...@@ -44,12 +44,23 @@ ...@@ -44,12 +44,23 @@
#include <regression/rand/assoc/rand_regression_test.hpp> #include <regression/rand/assoc/rand_regression_test.hpp>
#include <regression/common_type.hpp> #include <regression/common_type.hpp>
#ifndef ITERATIONS #ifndef ITERATIONS
#define ITERATIONS 5000 # ifdef _GLIBCXX_DEBUG
# define ITERATIONS 100
# else
# define ITERATIONS 5000
#endif
#endif #endif
#ifndef KEYS #ifndef KEYS
#define KEYS 10000 # ifdef _GLIBCXX_DEBUG
# define KEYS 200
# else
# define KEYS 10000
# endif
#endif #endif
int int
main(int argc, char* a_p_argv[]) main(int argc, char* a_p_argv[])
{ {
...@@ -60,4 +71,3 @@ main(int argc, char* a_p_argv[]) ...@@ -60,4 +71,3 @@ main(int argc, char* a_p_argv[])
"tree_no_data_map_rand_regression_test", "tree_no_data_map_rand_regression_test",
map_tl_t()); map_tl_t());
} }
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
// -*- C++ -*- // -*- C++ -*-
// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. // Copyright (C) 2005, 2006, 2009, 2011 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the terms
...@@ -45,11 +45,21 @@ ...@@ -45,11 +45,21 @@
#include <regression/common_type.hpp> #include <regression/common_type.hpp>
#ifndef ITERATIONS #ifndef ITERATIONS
#define ITERATIONS 5000 # ifdef _GLIBCXX_DEBUG
# define ITERATIONS 100
# else
# define ITERATIONS 5000
#endif #endif
#endif
#ifndef KEYS #ifndef KEYS
#define KEYS 10000 # ifdef _GLIBCXX_DEBUG
# define KEYS 200
# else
# define KEYS 10000
# endif
#endif #endif
int int
main(int argc, char* a_p_argv[]) main(int argc, char* a_p_argv[])
{ {
...@@ -60,4 +70,3 @@ main(int argc, char* a_p_argv[]) ...@@ -60,4 +70,3 @@ main(int argc, char* a_p_argv[])
"trie_data_map_rand_regression_test", "trie_data_map_rand_regression_test",
map_tl_t()); map_tl_t());
} }
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
// -*- C++ -*- // -*- C++ -*-
// Copyright (C) 2005, 2006, 2009, 2010 Free Software Foundation, Inc. // Copyright (C) 2005, 2006, 2009, 2010, 2011 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the terms
...@@ -45,11 +45,21 @@ ...@@ -45,11 +45,21 @@
#include <regression/common_type.hpp> #include <regression/common_type.hpp>
#ifndef ITERATIONS #ifndef ITERATIONS
#define ITERATIONS 5000 # ifdef _GLIBCXX_DEBUG
# define ITERATIONS 100
# else
# define ITERATIONS 5000
#endif #endif
#endif
#ifndef KEYS #ifndef KEYS
#define KEYS 10000 # ifdef _GLIBCXX_DEBUG
# define KEYS 200
# else
# define KEYS 10000
# endif
#endif #endif
int int
main(int argc, char* a_p_argv[]) main(int argc, char* a_p_argv[])
{ {
...@@ -57,7 +67,6 @@ main(int argc, char* a_p_argv[]) ...@@ -57,7 +67,6 @@ main(int argc, char* a_p_argv[])
typedef trie_set_tl_t map_tl_t; typedef trie_set_tl_t map_tl_t;
return rand_regression_test(ITERATIONS, KEYS, return rand_regression_test(ITERATIONS, KEYS,
"trie_no_data_map_rand_regression_test", "trie_no_data_map_rand_regression_test",
map_tl_t()); map_tl_t());
} }
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