hashtable_policy.h (_Rehash_base<_Prime_rehash_policy, [...]): Add, per DR 1189.

2010-03-10  Paolo Carlini  <paolo.carlini@oracle.com>

	* include/bits/hashtable_policy.h (_Rehash_base<_Prime_rehash_policy,
	_Hashtable>::reserve): Add, per DR 1189.
	* include/bits/hashtable.h (_Hashtable<>::size_type,
	_Hashtable<>::difference_type): Do not typedef from _Allocator.
	* testsuite/23_containers/unordered_map/dr1189.cc: New.
	* testsuite/23_containers/unordered_set/dr1189.cc: Likewise.
	* testsuite/23_containers/unordered_multimap/dr1189.cc: Likewise.
	* testsuite/23_containers/unordered_multiset/dr1189.cc: Likewise.

From-SVN: r157373
This commit is contained in:
Paolo Carlini 2010-03-10 23:49:28 +00:00 committed by Paolo Carlini
parent f37f5bb93a
commit 9155c0e3df
7 changed files with 218 additions and 5 deletions

View File

@ -1,3 +1,14 @@
2010-03-10 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/hashtable_policy.h (_Rehash_base<_Prime_rehash_policy,
_Hashtable>::reserve): Add, per DR 1189.
* include/bits/hashtable.h (_Hashtable<>::size_type,
_Hashtable<>::difference_type): Do not typedef from _Allocator.
* testsuite/23_containers/unordered_map/dr1189.cc: New.
* testsuite/23_containers/unordered_set/dr1189.cc: Likewise.
* testsuite/23_containers/unordered_multimap/dr1189.cc: Likewise.
* testsuite/23_containers/unordered_multiset/dr1189.cc: Likewise.
2010-03-08 Paolo Carlini <paolo.carlini@oracle.com>
Revert:

View File

@ -127,13 +127,13 @@ namespace std
typedef _Equal key_equal;
// mapped_type, if present, comes from _Map_base.
// hasher, if present, comes from _Hash_code_base.
typedef typename _Allocator::difference_type difference_type;
typedef typename _Allocator::size_type size_type;
typedef typename _Allocator::pointer pointer;
typedef typename _Allocator::const_pointer const_pointer;
typedef typename _Allocator::reference reference;
typedef typename _Allocator::const_reference const_reference;
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef __detail::_Node_iterator<value_type, __constant_iterators,
__cache_hash_code>
local_iterator;
@ -421,7 +421,10 @@ namespace std
// Set number of buckets to be appropriate for container of n element.
void rehash(size_type __n);
// DR 1189.
// reserve, if present, comes from _Rehash_base.
private:
// Unconditionally change size of bucket array to n.
void _M_rehash(size_type __n);

View File

@ -604,7 +604,7 @@ namespace __detail
}
// class template _Rehash_base. Give hashtable the max_load_factor
// functions iff the rehash policy is _Prime_rehash_policy.
// functions and reserve iff the rehash policy is _Prime_rehash_policy.
template<typename _RehashPolicy, typename _Hashtable>
struct _Rehash_base { };
@ -624,6 +624,13 @@ namespace __detail
_Hashtable* __this = static_cast<_Hashtable*>(this);
__this->__rehash_policy(_Prime_rehash_policy(__z));
}
void
reserve(std::size_t __n)
{
_Hashtable* __this = static_cast<_Hashtable*>(this);
__this->rehash(__builtin_ceil(__n / max_load_factor()));
}
};
// Class template _Hash_code_base. Encapsulates two policy issues that

View File

@ -0,0 +1,48 @@
// { dg-options "-std=gnu++0x" }
// 2010-03-10 Paolo Carlini <paolo.carlini@oracle.com>
//
// Copyright (C) 2010 Free Software Foundation, Inc.
//
// 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 of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <unordered_map>
#include <testsuite_hooks.h>
// DR 1189. Awkward interface for changing the number of buckets
// in an unordered associative container
void test01()
{
bool test __attribute__((unused)) = true;
std::unordered_map<int, double> m1;
m1.reserve(10);
VERIFY( m1.bucket_count() >= 10 );
m1.reserve(100);
VERIFY( m1.bucket_count() >= 100 );
std::unordered_map<int, double> m2(100);
VERIFY( m2.bucket_count() >= 100 );
m2.reserve(1000);
VERIFY( m2.bucket_count() >= 1000 );
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,48 @@
// { dg-options "-std=gnu++0x" }
// 2010-03-10 Paolo Carlini <paolo.carlini@oracle.com>
//
// Copyright (C) 2010 Free Software Foundation, Inc.
//
// 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 of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <unordered_map>
#include <testsuite_hooks.h>
// DR 1189. Awkward interface for changing the number of buckets
// in an unordered associative container
void test01()
{
bool test __attribute__((unused)) = true;
std::unordered_multimap<int, double> mm1;
mm1.reserve(10);
VERIFY( mm1.bucket_count() >= 10 );
mm1.reserve(100);
VERIFY( mm1.bucket_count() >= 100 );
std::unordered_map<int, double> mm2(100);
VERIFY( mm2.bucket_count() >= 100 );
mm2.reserve(1000);
VERIFY( mm2.bucket_count() >= 1000 );
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,48 @@
// { dg-options "-std=gnu++0x" }
// 2010-03-10 Paolo Carlini <paolo.carlini@oracle.com>
//
// Copyright (C) 2010 Free Software Foundation, Inc.
//
// 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 of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <unordered_set>
#include <testsuite_hooks.h>
// DR 1189. Awkward interface for changing the number of buckets
// in an unordered associative container
void test01()
{
bool test __attribute__((unused)) = true;
std::unordered_multiset<int> ms1;
ms1.reserve(10);
VERIFY( ms1.bucket_count() >= 10 );
ms1.reserve(100);
VERIFY( ms1.bucket_count() >= 100 );
std::unordered_multiset<int> ms2(100);
VERIFY( ms2.bucket_count() >= 100 );
ms2.reserve(1000);
VERIFY( ms2.bucket_count() >= 1000 );
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,48 @@
// { dg-options "-std=gnu++0x" }
// 2010-03-10 Paolo Carlini <paolo.carlini@oracle.com>
//
// Copyright (C) 2010 Free Software Foundation, Inc.
//
// 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 of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <unordered_set>
#include <testsuite_hooks.h>
// DR 1189. Awkward interface for changing the number of buckets
// in an unordered associative container
void test01()
{
bool test __attribute__((unused)) = true;
std::unordered_set<int> s1;
s1.reserve(10);
VERIFY( s1.bucket_count() >= 10 );
s1.reserve(100);
VERIFY( s1.bucket_count() >= 100 );
std::unordered_set<int> s2(100);
VERIFY( s2.bucket_count() >= 100 );
s2.reserve(1000);
VERIFY( s2.bucket_count() >= 1000 );
}
int main()
{
test01();
return 0;
}