aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrançois Dumont <fdumont@gcc.gnu.org>2011-11-29 07:45:58 +0000
committerFrançois Dumont <fdumont@gcc.gnu.org>2011-11-29 07:45:58 +0000
commit40207762a82f9d6fde9a9ac529ea3a170dac1a91 (patch)
tree9a9ec4da9401072fba5355ee158be75f6a46ec0b
parent714cb9f01a3b5ebcc929263295262010844a1b90 (diff)
downloadgcc-40207762a82f9d6fde9a9ac529ea3a170dac1a91.zip
gcc-40207762a82f9d6fde9a9ac529ea3a170dac1a91.tar.gz
gcc-40207762a82f9d6fde9a9ac529ea3a170dac1a91.tar.bz2
hashtable.h (_Hashtable<>::_M_rehash): Remove code useless now that the hashtable implementation put the hash code in...
2011-11-29 François Dumont <fdumont@gcc.gnu.org> * include/bits/hashtable.h (_Hashtable<>::_M_rehash): Remove code useless now that the hashtable implementation put the hash code in cache if the hash functor throws. * testsuite/23_containers/unordered_set/erase/1.cc: Enhance test by checking also distance between begin and end iterators to validate underlying data model. * testsuite/23_containers/unordered_multiset/erase/1.cc: Likewise. * testsuire/23_containers/unordered_map/erase/1.cc: Likewise. * testsuite/23_containers/unordered_multimap/erase/1.cc: Likewise. * testsuite/23_containers/unordered_multiset/erase/2.cc: New. * testsuite/23_containers/unordered_multimap/erase/2.cc: New. From-SVN: r181799
-rw-r--r--libstdc++-v3/ChangeLog14
-rw-r--r--libstdc++-v3/include/bits/hashtable.h44
-rw-r--r--libstdc++-v3/testsuite/23_containers/unordered_map/erase/1.cc38
-rw-r--r--libstdc++-v3/testsuite/23_containers/unordered_multimap/erase/1.cc36
-rw-r--r--libstdc++-v3/testsuite/23_containers/unordered_multimap/erase/2.cc90
-rw-r--r--libstdc++-v3/testsuite/23_containers/unordered_multiset/erase/1.cc12
-rw-r--r--libstdc++-v3/testsuite/23_containers/unordered_multiset/erase/2.cc89
-rw-r--r--libstdc++-v3/testsuite/23_containers/unordered_set/erase/1.cc36
8 files changed, 319 insertions, 40 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 48c3db2..4be8353 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,17 @@
+2011-11-29 François Dumont <fdumont@gcc.gnu.org>
+
+ * include/bits/hashtable.h (_Hashtable<>::_M_rehash): Remove code
+ useless now that the hashtable implementation put the hash code in
+ cache if the hash functor throws.
+ * testsuite/23_containers/unordered_set/erase/1.cc: Enhance test by
+ checking also distance between begin and end iterators to validate
+ underlying data model.
+ * testsuite/23_containers/unordered_multiset/erase/1.cc: Likewise.
+ * testsuire/23_containers/unordered_map/erase/1.cc: Likewise.
+ * testsuite/23_containers/unordered_multimap/erase/1.cc: Likewise.
+ * testsuite/23_containers/unordered_multiset/erase/2.cc: New.
+ * testsuite/23_containers/unordered_multimap/erase/2.cc: New.
+
2011-11-28 Andrew MacLeod <amacleod@redhat.com>
* include/bits/atomic_base.h (ATOMIC_*_LOCK_FREE): Use new cpp
diff --git a/libstdc++-v3/include/bits/hashtable.h b/libstdc++-v3/include/bits/hashtable.h
index dfa91f7..712b1df 100644
--- a/libstdc++-v3/include/bits/hashtable.h
+++ b/libstdc++-v3/include/bits/hashtable.h
@@ -233,11 +233,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
void
_M_deallocate_node(_Node* __n);
- // Deallocate all nodes contained in the bucket array, buckets' nodes
- // are not linked to each other
- void
- _M_deallocate_nodes(_Bucket*, size_type);
-
// Deallocate the linked list of nodes pointed to by __n
void
_M_deallocate_nodes(_Node* __n);
@@ -591,19 +586,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
void
_Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
_H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
- _M_deallocate_nodes(_Bucket* __buckets, size_type __n)
- {
- for (size_type __i = 0; __i != __n; ++__i)
- _M_deallocate_nodes(__buckets[__i]);
- }
-
- template<typename _Key, typename _Value,
- typename _Allocator, typename _ExtractKey, typename _Equal,
- typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
- bool __chc, bool __cit, bool __uk>
- void
- _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
- _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
_M_deallocate_nodes(_Node* __n)
{
while (__n)
@@ -1542,11 +1524,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
_M_rehash(size_type __n, const _RehashPolicyState& __state)
{
- _Bucket* __new_buckets = nullptr;
- _Node* __p = _M_buckets[_M_begin_bucket_index];
__try
{
- __new_buckets = _M_allocate_buckets(__n);
+ _Bucket* __new_buckets = _M_allocate_buckets(__n);
+ _Node* __p = _M_buckets[_M_begin_bucket_index];
// First loop to store each node in its new bucket
while (__p)
{
@@ -1591,24 +1572,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
__catch(...)
{
- if (__new_buckets)
- {
- // A failure here means that a hash function threw an exception.
- // We can't restore the previous state without calling the hash
- // function again, so the only sensible recovery is to delete
- // everything.
- _M_deallocate_nodes(__new_buckets, __n);
- _M_deallocate_buckets(__new_buckets, __n);
- _M_deallocate_nodes(__p);
- __builtin_memset(_M_buckets, 0, sizeof(_Bucket) * _M_bucket_count);
- _M_element_count = 0;
- _M_begin_bucket_index = _M_bucket_count;
- _M_rehash_policy._M_reset(_RehashPolicyState());
- }
- else
- // A failure here means that buckets allocation failed. We only
- // have to restore hash policy previous state.
- _M_rehash_policy._M_reset(__state);
+ // A failure here means that buckets allocation failed. We only
+ // have to restore hash policy previous state.
+ _M_rehash_policy._M_reset(__state);
__throw_exception_again;
}
}
diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/erase/1.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/erase/1.cc
index f9b74e0..9863ef7 100644
--- a/libstdc++-v3/testsuite/23_containers/unordered_map/erase/1.cc
+++ b/libstdc++-v3/testsuite/23_containers/unordered_map/erase/1.cc
@@ -23,6 +23,18 @@
#include <string>
#include <testsuite_hooks.h>
+namespace
+{
+ std::size_t
+ get_nb_bucket_elems(const std::unordered_map<std::string, int>& us)
+ {
+ std::size_t nb = 0;
+ for (std::size_t b = 0; b != us.bucket_count(); ++b)
+ nb += us.bucket_size(b);
+ return nb;
+ }
+}
+
void test01()
{
bool test __attribute__((unused)) = true;
@@ -33,7 +45,7 @@ void test01()
typedef Map::value_type value_type;
Map m1;
-
+
m1.insert(value_type("because to why", 1));
m1.insert(value_type("the stockholm syndrome", 2));
m1.insert(value_type("a cereous night", 3));
@@ -45,14 +57,20 @@ void test01()
m1.insert(value_type("belonging (no longer mix)", 9));
m1.insert(value_type("one line behind", 10));
VERIFY( m1.size() == 10 );
+ VERIFY( get_nb_bucket_elems(m1) == m1.size() );
+ VERIFY( distance(m1.begin(), m1.end()) == m1.size() );
VERIFY( m1.erase("eeilo") == 1 );
VERIFY( m1.size() == 9 );
+ VERIFY( get_nb_bucket_elems(m1) == m1.size() );
+ VERIFY( distance(m1.begin(), m1.end()) == m1.size() );
iterator it1 = m1.find("eeilo");
VERIFY( it1 == m1.end() );
VERIFY( m1.erase("tillsammans") == 1 );
VERIFY( m1.size() == 8 );
+ VERIFY( get_nb_bucket_elems(m1) == m1.size() );
+ VERIFY( distance(m1.begin(), m1.end()) == m1.size() );
iterator it2 = m1.find("tillsammans");
VERIFY( it2 == m1.end() );
@@ -61,17 +79,23 @@ void test01()
VERIFY( it3 != m1.end() );
VERIFY( m1.erase(it3->first) == 1 );
VERIFY( m1.size() == 7 );
+ VERIFY( get_nb_bucket_elems(m1) == m1.size() );
+ VERIFY( distance(m1.begin(), m1.end()) == m1.size() );
it3 = m1.find("belonging (no longer mix)");
VERIFY( it3 == m1.end() );
VERIFY( !m1.erase("abra") );
VERIFY( m1.size() == 7 );
+ VERIFY( get_nb_bucket_elems(m1) == m1.size() );
+ VERIFY( distance(m1.begin(), m1.end()) == m1.size() );
VERIFY( !m1.erase("eeilo") );
VERIFY( m1.size() == 7 );
VERIFY( m1.erase("because to why") == 1 );
VERIFY( m1.size() == 6 );
+ VERIFY( get_nb_bucket_elems(m1) == m1.size() );
+ VERIFY( distance(m1.begin(), m1.end()) == m1.size() );
iterator it4 = m1.find("because to why");
VERIFY( it4 == m1.end() );
@@ -87,11 +111,15 @@ void test01()
VERIFY( m1.erase(it5->first) == 1 );
VERIFY( m1.size() == 5 );
+ VERIFY( get_nb_bucket_elems(m1) == m1.size() );
+ VERIFY( distance(m1.begin(), m1.end()) == m1.size() );
it5 = m1.find("umbra/penumbra");
VERIFY( it5 == m1.end() );
VERIFY( m1.erase(it6->first) == 1 );
VERIFY( m1.size() == 4 );
+ VERIFY( get_nb_bucket_elems(m1) == m1.size() );
+ VERIFY( distance(m1.begin(), m1.end()) == m1.size() );
it6 = m1.find("one line behind");
VERIFY( it6 == m1.end() );
@@ -103,6 +131,8 @@ void test01()
VERIFY( m1.erase(it8->first) == 1 );
VERIFY( m1.size() == 3 );
+ VERIFY( get_nb_bucket_elems(m1) == m1.size() );
+ VERIFY( distance(m1.begin(), m1.end()) == m1.size() );
VERIFY( ++it7 == it9 );
iterator it10 = it9;
@@ -110,15 +140,21 @@ void test01()
iterator it11 = it10;
VERIFY( m1.erase(it9->first) == 1 );
+ VERIFY( get_nb_bucket_elems(m1) == m1.size() );
+ VERIFY( distance(m1.begin(), m1.end()) == m1.size() );
VERIFY( m1.size() == 2 );
VERIFY( ++it10 == m1.end() );
VERIFY( m1.erase(m1.begin()) != m1.end() );
VERIFY( m1.size() == 1 );
+ VERIFY( get_nb_bucket_elems(m1) == m1.size() );
+ VERIFY( distance(m1.begin(), m1.end()) == m1.size() );
VERIFY( m1.begin() == it11 );
VERIFY( m1.erase(m1.begin()->first) == 1 );
VERIFY( m1.size() == 0 );
+ VERIFY( get_nb_bucket_elems(m1) == m1.size() );
+ VERIFY( distance(m1.begin(), m1.end()) == m1.size() );
VERIFY( m1.begin() == m1.end() );
}
diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/erase/1.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/erase/1.cc
index 0951572..c599cc0 100644
--- a/libstdc++-v3/testsuite/23_containers/unordered_multimap/erase/1.cc
+++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/erase/1.cc
@@ -23,6 +23,18 @@
#include <string>
#include <testsuite_hooks.h>
+namespace
+{
+ std::size_t
+ get_nb_bucket_elems(const std::unordered_multimap<std::string, int>& us)
+ {
+ std::size_t nb = 0;
+ for (std::size_t b = 0; b != us.bucket_count(); ++b)
+ nb += us.bucket_size(b);
+ return nb;
+ }
+}
+
void test01()
{
bool test __attribute__((unused)) = true;
@@ -46,14 +58,20 @@ void test01()
mm1.insert(value_type("one line behind", 10));
mm1.insert(value_type("because to why", 11));
VERIFY( mm1.size() == 11 );
+ VERIFY( get_nb_bucket_elems(mm1) == mm1.size() );
+ VERIFY( distance(mm1.begin(), mm1.end()) == mm1.size() );
VERIFY( mm1.erase("eeilo") == 1 );
VERIFY( mm1.size() == 10 );
+ VERIFY( get_nb_bucket_elems(mm1) == mm1.size() );
+ VERIFY( distance(mm1.begin(), mm1.end()) == mm1.size() );
iterator it1 = mm1.find("eeilo");
VERIFY( it1 == mm1.end() );
VERIFY( mm1.erase("tillsammans") == 1 );
VERIFY( mm1.size() == 9 );
+ VERIFY( get_nb_bucket_elems(mm1) == mm1.size() );
+ VERIFY( distance(mm1.begin(), mm1.end()) == mm1.size() );
iterator it2 = mm1.find("tillsammans");
VERIFY( it2 == mm1.end() );
@@ -62,17 +80,23 @@ void test01()
VERIFY( it3 != mm1.end() );
VERIFY( mm1.erase(it3->first) == 1 );
VERIFY( mm1.size() == 8 );
+ VERIFY( get_nb_bucket_elems(mm1) == mm1.size() );
+ VERIFY( distance(mm1.begin(), mm1.end()) == mm1.size() );
it3 = mm1.find("belonging (no longer mix)");
VERIFY( it3 == mm1.end() );
VERIFY( !mm1.erase("abra") );
VERIFY( mm1.size() == 8 );
+ VERIFY( get_nb_bucket_elems(mm1) == mm1.size() );
+ VERIFY( distance(mm1.begin(), mm1.end()) == mm1.size() );
VERIFY( !mm1.erase("eeilo") );
VERIFY( mm1.size() == 8 );
VERIFY( mm1.erase("because to why") == 2 );
VERIFY( mm1.size() == 6 );
+ VERIFY( get_nb_bucket_elems(mm1) == mm1.size() );
+ VERIFY( distance(mm1.begin(), mm1.end()) == mm1.size() );
iterator it4 = mm1.find("because to why");
VERIFY( it4 == mm1.end() );
@@ -88,11 +112,15 @@ void test01()
VERIFY( mm1.erase(it5->first) == 1 );
VERIFY( mm1.size() == 5 );
+ VERIFY( get_nb_bucket_elems(mm1) == mm1.size() );
+ VERIFY( distance(mm1.begin(), mm1.end()) == mm1.size() );
it5 = mm1.find("umbra/penumbra");
VERIFY( it5 == mm1.end() );
VERIFY( mm1.erase(it6->first) == 1 );
VERIFY( mm1.size() == 4 );
+ VERIFY( get_nb_bucket_elems(mm1) == mm1.size() );
+ VERIFY( distance(mm1.begin(), mm1.end()) == mm1.size() );
it6 = mm1.find("one line behind");
VERIFY( it6 == mm1.end() );
@@ -104,6 +132,8 @@ void test01()
VERIFY( mm1.erase(it8->first) == 1 );
VERIFY( mm1.size() == 3 );
+ VERIFY( get_nb_bucket_elems(mm1) == mm1.size() );
+ VERIFY( distance(mm1.begin(), mm1.end()) == mm1.size() );
VERIFY( ++it7 == it9 );
iterator it10 = it9;
@@ -111,15 +141,21 @@ void test01()
iterator it11 = it10;
VERIFY( mm1.erase(it9->first) == 1 );
+ VERIFY( get_nb_bucket_elems(mm1) == mm1.size() );
+ VERIFY( distance(mm1.begin(), mm1.end()) == mm1.size() );
VERIFY( mm1.size() == 2 );
VERIFY( ++it10 == mm1.end() );
VERIFY( mm1.erase(mm1.begin()) != mm1.end() );
VERIFY( mm1.size() == 1 );
+ VERIFY( get_nb_bucket_elems(mm1) == mm1.size() );
+ VERIFY( distance(mm1.begin(), mm1.end()) == mm1.size() );
VERIFY( mm1.begin() == it11 );
VERIFY( mm1.erase(mm1.begin()->first) == 1 );
VERIFY( mm1.size() == 0 );
+ VERIFY( get_nb_bucket_elems(mm1) == mm1.size() );
+ VERIFY( distance(mm1.begin(), mm1.end()) == mm1.size() );
VERIFY( mm1.begin() == mm1.end() );
}
diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/erase/2.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/erase/2.cc
new file mode 100644
index 0000000..df73a85
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/erase/2.cc
@@ -0,0 +1,90 @@
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2011 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 <string>
+#include <testsuite_hooks.h>
+
+namespace
+{
+ std::size_t
+ get_nb_bucket_elems(const std::unordered_multimap<std::string, int>& um)
+ {
+ std::size_t nb = 0;
+ for (std::size_t b = 0; b != um.bucket_count(); ++b)
+ nb += um.bucket_size(b);
+ return nb;
+ }
+}
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ typedef std::unordered_multimap<std::string, int> Mmap;
+ typedef Mmap::iterator iterator;
+ typedef Mmap::const_iterator const_iterator;
+ typedef Mmap::value_type value_type;
+
+ Mmap mm1;
+
+ mm1.insert(value_type("foo", 10));
+ mm1.insert(value_type("foo", 11));
+ mm1.insert(value_type("foo", 12));
+ mm1.insert(value_type("foo", 13));
+ mm1.insert(value_type("foo", 14));
+ mm1.insert(value_type("foo", 15));
+ mm1.insert(value_type("bar", 20));
+ mm1.insert(value_type("bar", 21));
+ mm1.insert(value_type("bar", 22));
+ mm1.insert(value_type("bar", 23));
+ mm1.insert(value_type("bar", 24));
+ mm1.insert(value_type("bar", 25));
+ VERIFY( mm1.size() == 12 );
+ VERIFY( get_nb_bucket_elems(mm1) == mm1.size() );
+ VERIFY( distance(mm1.begin(), mm1.end()) == mm1.size() );
+
+ VERIFY( mm1.erase(mm1.begin()) != mm1.end() );
+ VERIFY( mm1.size() == 11 );
+ VERIFY( get_nb_bucket_elems(mm1) == mm1.size() );
+ VERIFY( distance(mm1.begin(), mm1.end()) == mm1.size() );
+
+ auto it = mm1.begin();
+ advance(it, 2);
+ VERIFY( mm1.erase(mm1.begin(), it) != mm1.end() );
+ VERIFY( mm1.size() == 9 );
+ VERIFY( get_nb_bucket_elems(mm1) == mm1.size() );
+ VERIFY( distance(mm1.begin(), mm1.end()) == mm1.size() );
+
+ VERIFY( mm1.erase(mm1.begin()->first) == 3 );
+ VERIFY( mm1.size() == 6 );
+ VERIFY( get_nb_bucket_elems(mm1) == mm1.size() );
+ VERIFY( distance(mm1.begin(), mm1.end()) == mm1.size() );
+
+ VERIFY( mm1.erase(mm1.begin(), mm1.end()) == mm1.end() );
+ VERIFY( mm1.empty() );
+ VERIFY( get_nb_bucket_elems(mm1) == mm1.size() );
+ VERIFY( distance(mm1.begin(), mm1.end()) == mm1.size() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/erase/1.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/erase/1.cc
index e48e311..b95c8a3 100644
--- a/libstdc++-v3/testsuite/23_containers/unordered_multiset/erase/1.cc
+++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/erase/1.cc
@@ -58,16 +58,19 @@ void test01()
ms1.insert("because to why");
VERIFY( ms1.size() == 11 );
VERIFY( get_nb_bucket_elems(ms1) == ms1.size() );
+ VERIFY( distance(ms1.begin(), ms1.end()) == ms1.size() );
VERIFY( ms1.erase("eeilo") == 1 );
VERIFY( ms1.size() == 10 );
VERIFY( get_nb_bucket_elems(ms1) == ms1.size() );
+ VERIFY( distance(ms1.begin(), ms1.end()) == ms1.size() );
iterator it1 = ms1.find("eeilo");
VERIFY( it1 == ms1.end() );
VERIFY( ms1.erase("tillsammans") == 1 );
VERIFY( ms1.size() == 9 );
VERIFY( get_nb_bucket_elems(ms1) == ms1.size() );
+ VERIFY( distance(ms1.begin(), ms1.end()) == ms1.size() );
iterator it2 = ms1.find("tillsammans");
VERIFY( it2 == ms1.end() );
@@ -77,12 +80,14 @@ void test01()
VERIFY( ms1.erase(*it3) == 1 );
VERIFY( ms1.size() == 8 );
VERIFY( get_nb_bucket_elems(ms1) == ms1.size() );
+ VERIFY( distance(ms1.begin(), ms1.end()) == ms1.size() );
it3 = ms1.find("belonging (no longer mix)");
VERIFY( it3 == ms1.end() );
VERIFY( !ms1.erase("abra") );
VERIFY( ms1.size() == 8 );
VERIFY( get_nb_bucket_elems(ms1) == ms1.size() );
+ VERIFY( distance(ms1.begin(), ms1.end()) == ms1.size() );
VERIFY( !ms1.erase("eeilo") );
VERIFY( ms1.size() == 8 );
@@ -90,6 +95,7 @@ void test01()
VERIFY( ms1.erase("because to why") == 2 );
VERIFY( ms1.size() == 6 );
VERIFY( get_nb_bucket_elems(ms1) == ms1.size() );
+ VERIFY( distance(ms1.begin(), ms1.end()) == ms1.size() );
iterator it4 = ms1.find("because to why");
VERIFY( it4 == ms1.end() );
@@ -106,12 +112,14 @@ void test01()
VERIFY( ms1.erase(*it5) == 1 );
VERIFY( ms1.size() == 5 );
VERIFY( get_nb_bucket_elems(ms1) == ms1.size() );
+ VERIFY( distance(ms1.begin(), ms1.end()) == ms1.size() );
it5 = ms1.find("umbra/penumbra");
VERIFY( it5 == ms1.end() );
VERIFY( ms1.erase(*it6) == 1 );
VERIFY( ms1.size() == 4 );
VERIFY( get_nb_bucket_elems(ms1) == ms1.size() );
+ VERIFY( distance(ms1.begin(), ms1.end()) == ms1.size() );
it6 = ms1.find("one line behind");
VERIFY( it6 == ms1.end() );
@@ -124,6 +132,7 @@ void test01()
VERIFY( ms1.erase(*it8) == 1 );
VERIFY( ms1.size() == 3 );
VERIFY( get_nb_bucket_elems(ms1) == ms1.size() );
+ VERIFY( distance(ms1.begin(), ms1.end()) == ms1.size() );
VERIFY( ++it7 == it9 );
iterator it10 = it9;
@@ -132,17 +141,20 @@ void test01()
VERIFY( ms1.erase(*it9) == 1 );
VERIFY( get_nb_bucket_elems(ms1) == ms1.size() );
+ VERIFY( distance(ms1.begin(), ms1.end()) == ms1.size() );
VERIFY( ms1.size() == 2 );
VERIFY( ++it10 == ms1.end() );
VERIFY( ms1.erase(ms1.begin()) != ms1.end() );
VERIFY( ms1.size() == 1 );
VERIFY( get_nb_bucket_elems(ms1) == ms1.size() );
+ VERIFY( distance(ms1.begin(), ms1.end()) == ms1.size() );
VERIFY( ms1.begin() == it11 );
VERIFY( ms1.erase(*ms1.begin()) == 1 );
VERIFY( ms1.size() == 0 );
VERIFY( get_nb_bucket_elems(ms1) == ms1.size() );
+ VERIFY( distance(ms1.begin(), ms1.end()) == ms1.size() );
VERIFY( ms1.begin() == ms1.end() );
}
diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/erase/2.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/erase/2.cc
new file mode 100644
index 0000000..ad6cad4
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/erase/2.cc
@@ -0,0 +1,89 @@
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2011 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 <string>
+#include <testsuite_hooks.h>
+
+namespace
+{
+ std::size_t
+ get_nb_bucket_elems(const std::unordered_multiset<std::string>& us)
+ {
+ std::size_t nb = 0;
+ for (std::size_t b = 0; b != us.bucket_count(); ++b)
+ nb += us.bucket_size(b);
+ return nb;
+ }
+}
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ typedef std::unordered_multiset<std::string> Mset;
+ typedef Mset::iterator iterator;
+ typedef Mset::const_iterator const_iterator;
+
+ Mset ms1;
+
+ ms1.insert("foo");
+ ms1.insert("foo");
+ ms1.insert("foo");
+ ms1.insert("foo");
+ ms1.insert("foo");
+ ms1.insert("foo");
+ ms1.insert("bar");
+ ms1.insert("bar");
+ ms1.insert("bar");
+ ms1.insert("bar");
+ ms1.insert("bar");
+ ms1.insert("bar");
+ VERIFY( ms1.size() == 12 );
+ VERIFY( get_nb_bucket_elems(ms1) == ms1.size() );
+ VERIFY( distance(ms1.begin(), ms1.end()) == ms1.size() );
+
+ VERIFY( ms1.erase(ms1.begin()) != ms1.end() );
+ VERIFY( ms1.size() == 11 );
+ VERIFY( get_nb_bucket_elems(ms1) == ms1.size() );
+ VERIFY( distance(ms1.begin(), ms1.end()) == ms1.size() );
+
+ auto it = ms1.begin();
+ advance(it, 2);
+ VERIFY( ms1.erase(ms1.begin(), it) != ms1.end() );
+ VERIFY( ms1.size() == 9 );
+ VERIFY( get_nb_bucket_elems(ms1) == ms1.size() );
+ VERIFY( distance(ms1.begin(), ms1.end()) == ms1.size() );
+
+ VERIFY( ms1.erase(*(ms1.begin())) == 3 );
+ VERIFY( ms1.size() == 6 );
+ VERIFY( get_nb_bucket_elems(ms1) == ms1.size() );
+ VERIFY( distance(ms1.begin(), ms1.end()) == ms1.size() );
+
+ VERIFY( ms1.erase(ms1.begin(), ms1.end()) == ms1.end() );
+ VERIFY( ms1.empty() );
+ VERIFY( get_nb_bucket_elems(ms1) == ms1.size() );
+ VERIFY( distance(ms1.begin(), ms1.end()) == ms1.size() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/erase/1.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/erase/1.cc
index 8f59773..cdefef2 100644
--- a/libstdc++-v3/testsuite/23_containers/unordered_set/erase/1.cc
+++ b/libstdc++-v3/testsuite/23_containers/unordered_set/erase/1.cc
@@ -23,6 +23,18 @@
#include <string>
#include <testsuite_hooks.h>
+namespace
+{
+ std::size_t
+ get_nb_bucket_elems(const std::unordered_set<std::string>& us)
+ {
+ std::size_t nb = 0;
+ for (std::size_t b = 0; b != us.bucket_count(); ++b)
+ nb += us.bucket_size(b);
+ return nb;
+ }
+}
+
void test01()
{
bool test __attribute__((unused)) = true;
@@ -44,14 +56,20 @@ void test01()
s1.insert("belonging (no longer mix)");
s1.insert("one line behind");
VERIFY( s1.size() == 10 );
+ VERIFY( get_nb_bucket_elems(s1) == s1.size() );
+ VERIFY( distance(s1.begin(), s1.end()) == s1.size() );
VERIFY( s1.erase("eeilo") == 1 );
VERIFY( s1.size() == 9 );
+ VERIFY( get_nb_bucket_elems(s1) == s1.size() );
+ VERIFY( distance(s1.begin(), s1.end()) == s1.size() );
iterator it1 = s1.find("eeilo");
VERIFY( it1 == s1.end() );
VERIFY( s1.erase("tillsammans") == 1 );
VERIFY( s1.size() == 8 );
+ VERIFY( get_nb_bucket_elems(s1) == s1.size() );
+ VERIFY( distance(s1.begin(), s1.end()) == s1.size() );
iterator it2 = s1.find("tillsammans");
VERIFY( it2 == s1.end() );
@@ -60,17 +78,23 @@ void test01()
VERIFY( it3 != s1.end() );
VERIFY( s1.erase(*it3) == 1 );
VERIFY( s1.size() == 7 );
+ VERIFY( get_nb_bucket_elems(s1) == s1.size() );
+ VERIFY( distance(s1.begin(), s1.end()) == s1.size() );
it3 = s1.find("belonging (no longer mix)");
VERIFY( it3 == s1.end() );
VERIFY( !s1.erase("abra") );
VERIFY( s1.size() == 7 );
+ VERIFY( get_nb_bucket_elems(s1) == s1.size() );
+ VERIFY( distance(s1.begin(), s1.end()) == s1.size() );
VERIFY( !s1.erase("eeilo") );
VERIFY( s1.size() == 7 );
VERIFY( s1.erase("because to why") == 1 );
VERIFY( s1.size() == 6 );
+ VERIFY( get_nb_bucket_elems(s1) == s1.size() );
+ VERIFY( distance(s1.begin(), s1.end()) == s1.size() );
iterator it4 = s1.find("because to why");
VERIFY( it4 == s1.end() );
@@ -86,11 +110,15 @@ void test01()
VERIFY( s1.erase(*it5) == 1 );
VERIFY( s1.size() == 5 );
+ VERIFY( get_nb_bucket_elems(s1) == s1.size() );
+ VERIFY( distance(s1.begin(), s1.end()) == s1.size() );
it5 = s1.find("umbra/penumbra");
VERIFY( it5 == s1.end() );
VERIFY( s1.erase(*it6) == 1 );
VERIFY( s1.size() == 4 );
+ VERIFY( get_nb_bucket_elems(s1) == s1.size() );
+ VERIFY( distance(s1.begin(), s1.end()) == s1.size() );
it6 = s1.find("one line behind");
VERIFY( it6 == s1.end() );
@@ -102,6 +130,8 @@ void test01()
VERIFY( s1.erase(*it8) == 1 );
VERIFY( s1.size() == 3 );
+ VERIFY( get_nb_bucket_elems(s1) == s1.size() );
+ VERIFY( distance(s1.begin(), s1.end()) == s1.size() );
VERIFY( ++it7 == it9 );
iterator it10 = it9;
@@ -109,15 +139,21 @@ void test01()
iterator it11 = it10;
VERIFY( s1.erase(*it9) == 1 );
+ VERIFY( get_nb_bucket_elems(s1) == s1.size() );
+ VERIFY( distance(s1.begin(), s1.end()) == s1.size() );
VERIFY( s1.size() == 2 );
VERIFY( ++it10 == s1.end() );
VERIFY( s1.erase(s1.begin()) != s1.end() );
VERIFY( s1.size() == 1 );
+ VERIFY( get_nb_bucket_elems(s1) == s1.size() );
+ VERIFY( distance(s1.begin(), s1.end()) == s1.size() );
VERIFY( s1.begin() == it11 );
VERIFY( s1.erase(*s1.begin()) == 1 );
VERIFY( s1.size() == 0 );
+ VERIFY( get_nb_bucket_elems(s1) == s1.size() );
+ VERIFY( distance(s1.begin(), s1.end()) == s1.size() );
VERIFY( s1.begin() == s1.end() );
}