From 111d656236a72d52a17fd6cf86cdd50d52b0885b Mon Sep 17 00:00:00 2001 From: paolo Date: Wed, 10 Mar 2010 23:49:28 +0000 Subject: [PATCH] 2010-03-10 Paolo Carlini * 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@157373 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 11 +++++ libstdc++-v3/include/bits/hashtable.h | 11 +++-- libstdc++-v3/include/bits/hashtable_policy.h | 9 +++- .../23_containers/unordered_map/dr1189.cc | 48 ++++++++++++++++++++++ .../23_containers/unordered_multimap/dr1189.cc | 48 ++++++++++++++++++++++ .../23_containers/unordered_multiset/dr1189.cc | 48 ++++++++++++++++++++++ .../23_containers/unordered_set/dr1189.cc | 48 ++++++++++++++++++++++ 7 files changed, 218 insertions(+), 5 deletions(-) create mode 100644 libstdc++-v3/testsuite/23_containers/unordered_map/dr1189.cc create mode 100644 libstdc++-v3/testsuite/23_containers/unordered_multimap/dr1189.cc create mode 100644 libstdc++-v3/testsuite/23_containers/unordered_multiset/dr1189.cc create mode 100644 libstdc++-v3/testsuite/23_containers/unordered_set/dr1189.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 2a4c464..0985a7b 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,14 @@ +2010-03-10 Paolo Carlini + + * 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 Revert: diff --git a/libstdc++-v3/include/bits/hashtable.h b/libstdc++-v3/include/bits/hashtable.h index 96bb8ac..cd7553d5 100644 --- a/libstdc++-v3/include/bits/hashtable.h +++ b/libstdc++-v3/include/bits/hashtable.h @@ -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 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); diff --git a/libstdc++-v3/include/bits/hashtable_policy.h b/libstdc++-v3/include/bits/hashtable_policy.h index 4eccc88..8471dfb 100644 --- a/libstdc++-v3/include/bits/hashtable_policy.h +++ b/libstdc++-v3/include/bits/hashtable_policy.h @@ -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 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 diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/dr1189.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/dr1189.cc new file mode 100644 index 0000000..f89d5f1 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/dr1189.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++0x" } +// 2010-03-10 Paolo Carlini +// +// 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 +// . + +#include +#include + +// 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 m1; + m1.reserve(10); + VERIFY( m1.bucket_count() >= 10 ); + + m1.reserve(100); + VERIFY( m1.bucket_count() >= 100 ); + + std::unordered_map m2(100); + VERIFY( m2.bucket_count() >= 100 ); + + m2.reserve(1000); + VERIFY( m2.bucket_count() >= 1000 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/dr1189.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/dr1189.cc new file mode 100644 index 0000000..57e5f7d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/dr1189.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++0x" } +// 2010-03-10 Paolo Carlini +// +// 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 +// . + +#include +#include + +// 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 mm1; + mm1.reserve(10); + VERIFY( mm1.bucket_count() >= 10 ); + + mm1.reserve(100); + VERIFY( mm1.bucket_count() >= 100 ); + + std::unordered_map mm2(100); + VERIFY( mm2.bucket_count() >= 100 ); + + mm2.reserve(1000); + VERIFY( mm2.bucket_count() >= 1000 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/dr1189.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/dr1189.cc new file mode 100644 index 0000000..59232a3 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/dr1189.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++0x" } +// 2010-03-10 Paolo Carlini +// +// 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 +// . + +#include +#include + +// 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 ms1; + ms1.reserve(10); + VERIFY( ms1.bucket_count() >= 10 ); + + ms1.reserve(100); + VERIFY( ms1.bucket_count() >= 100 ); + + std::unordered_multiset ms2(100); + VERIFY( ms2.bucket_count() >= 100 ); + + ms2.reserve(1000); + VERIFY( ms2.bucket_count() >= 1000 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/dr1189.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/dr1189.cc new file mode 100644 index 0000000..e7047db --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/dr1189.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++0x" } +// 2010-03-10 Paolo Carlini +// +// 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 +// . + +#include +#include + +// 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 s1; + s1.reserve(10); + VERIFY( s1.bucket_count() >= 10 ); + + s1.reserve(100); + VERIFY( s1.bucket_count() >= 100 ); + + std::unordered_set s2(100); + VERIFY( s2.bucket_count() >= 100 ); + + s2.reserve(1000); + VERIFY( s2.bucket_count() >= 1000 ); +} + +int main() +{ + test01(); + return 0; +} -- 2.7.4