Commit 291e91da by François Dumont

hashtable.h (_Hashtable<>::__rehash_policy): Do not rehash container.

2015-07-05  François Dumont  <fdumont@gcc.gnu.org>

	* include/bits/hashtable.h (_Hashtable<>::__rehash_policy): Do not
	rehash container.
	* testsuite/23_containers/unordered_set/max_load_factor/robustness.cc:
	Adapt.

From-SVN: r225436
parent 3b973a7f
2015-07-05 François Dumont <fdumont@gcc.gnu.org>
* include/bits/hashtable.h (_Hashtable<>::__rehash_policy): Do not
rehash container.
* testsuite/23_containers/unordered_set/max_load_factor/robustness.cc:
Adapt.
2015-07-03 Jonathan Wakely <jwakely@redhat.com> 2015-07-03 Jonathan Wakely <jwakely@redhat.com>
* doc/xml/manual/status_cxx2017.xml: Update status table. * doc/xml/manual/status_cxx2017.xml: Update status table.
......
...@@ -594,7 +594,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -594,7 +594,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return _M_rehash_policy; } { return _M_rehash_policy; }
void void
__rehash_policy(const _RehashPolicy&); __rehash_policy(const _RehashPolicy& __pol)
{ _M_rehash_policy = __pol; }
// Lookup. // Lookup.
iterator iterator
...@@ -1284,22 +1285,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -1284,22 +1285,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
typename _Alloc, typename _ExtractKey, typename _Equal, typename _Alloc, typename _ExtractKey, typename _Equal,
typename _H1, typename _H2, typename _Hash, typename _RehashPolicy, typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
typename _Traits> typename _Traits>
void
_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
_H1, _H2, _Hash, _RehashPolicy, _Traits>::
__rehash_policy(const _RehashPolicy& __pol)
{
auto __do_rehash =
__pol._M_need_rehash(_M_bucket_count, _M_element_count, 0);
if (__do_rehash.first)
_M_rehash(__do_rehash.second, _M_rehash_policy._M_state());
_M_rehash_policy = __pol;
}
template<typename _Key, typename _Value,
typename _Alloc, typename _ExtractKey, typename _Equal,
typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
typename _Traits>
auto auto
_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
_H1, _H2, _Hash, _RehashPolicy, _Traits>:: _H1, _H2, _Hash, _RehashPolicy, _Traits>::
......
...@@ -32,41 +32,47 @@ void test01() ...@@ -32,41 +32,47 @@ void test01()
int val = 0; int val = 0;
for (; val != 100; ++val) for (; val != 100; ++val)
{ {
VERIFY( us.insert(val).second) ; VERIFY( us.insert(val).second );
VERIFY( us.load_factor() <= us.max_load_factor() ); VERIFY( us.load_factor() <= us.max_load_factor() );
} }
float cur_max_load_factor = us.max_load_factor(); float cur_max_load_factor = us.max_load_factor();
int counter = 0; int counter = 0;
std::size_t thrown_exceptions = 0; std::size_t thrown_exceptions = 0;
// Reduce max load factor.
us.max_load_factor(us.max_load_factor() / 2);
// At this point load factor is higher than max_load_factor because we can't
// rehash in max_load_factor call.
VERIFY( us.load_factor() > us.max_load_factor() );
while (true) while (true)
{ {
__gnu_cxx::limit_condition::set_limit(counter++); __gnu_cxx::limit_condition::set_limit(counter++);
bool do_break = false; bool do_break = false;
try try
{ {
us.max_load_factor(.5f); size_t nbkts = us.bucket_count();
// Check that unordered_set will still be correctly resized when
// needed.
VERIFY( us.insert(val++).second );
VERIFY( us.bucket_count() != nbkts );
VERIFY( us.load_factor() <= us.max_load_factor() );
do_break = true; do_break = true;
} }
catch (const __gnu_cxx::forced_error&) catch (const __gnu_cxx::forced_error&)
{ {
VERIFY( us.max_load_factor() == cur_max_load_factor ); // max load factor doesn't change.
VERIFY( us.max_load_factor() == .5f );
++thrown_exceptions; ++thrown_exceptions;
} }
// Lets check that unordered_set will still be correctly resized
// when needed
__gnu_cxx::limit_condition::set_limit(nl_size_t::max());
for (;;)
{
VERIFY( us.load_factor() <= us.max_load_factor() );
size_t nbkts = us.bucket_count();
VERIFY( us.insert(val++).second );
if (us.bucket_count() != nbkts)
break;
}
if (do_break) if (do_break)
break; break;
} }
VERIFY( thrown_exceptions > 0 ); VERIFY( thrown_exceptions > 0 );
} }
......
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