From 774b9d213ac7f52fd74f3aca414775356fb6770c Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Tue, 7 Feb 2006 15:11:10 +0000 Subject: [PATCH] [multiple changes] 2006-02-07 Paolo Carlini * include/tr1/hashtable: Trivial formatting fixes. 2006-02-07 Paolo Carlini Zak Kipling PR libstdc++/26127 * include/tr1/hashtable (hashtable<>::key_equal): Define. (hashtable<>::bucket, rehash_base<>::max_load_factor): Fix. * testsuite/tr1/6_containers/unordered/hashtable/26127.cc: New. Co-Authored-By: Zak Kipling From-SVN: r110697 --- libstdc++-v3/ChangeLog | 12 +++++ libstdc++-v3/include/tr1/hashtable | 49 +++++++++++-------- .../6_containers/unordered/hashtable/26127.cc | 39 +++++++++++++++ 3 files changed, 80 insertions(+), 20 deletions(-) create mode 100644 libstdc++-v3/testsuite/tr1/6_containers/unordered/hashtable/26127.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index c35668506fc0..66489338ec63 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,15 @@ +2006-02-07 Paolo Carlini + + * include/tr1/hashtable: Trivial formatting fixes. + +2006-02-07 Paolo Carlini + Zak Kipling + + PR libstdc++/26127 + * include/tr1/hashtable (hashtable<>::key_equal): Define. + (hashtable<>::bucket, rehash_base<>::max_load_factor): Fix. + * testsuite/tr1/6_containers/unordered/hashtable/26127.cc: New. + 2006-02-07 Paolo Carlini * include/tr1/cmath: New. diff --git a/libstdc++-v3/include/tr1/hashtable b/libstdc++-v3/include/tr1/hashtable index 0b9bc4184431..e9b73c65d637 100644 --- a/libstdc++-v3/include/tr1/hashtable +++ b/libstdc++-v3/include/tr1/hashtable @@ -653,7 +653,7 @@ namespace Internal max_load_factor() const { const Hashtable* This = static_cast(this); - return This->rehash_policy()->max_load_factor(); + return This->rehash_policy().max_load_factor(); } void @@ -836,7 +836,7 @@ namespace Internal typedef std::size_t hash_code_t; hash_code_t - m_hash_code (const Key& k) const + m_hash_code(const Key& k) const { return m_h1(k); } std::size_t @@ -1081,6 +1081,13 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) max_size() const { return m_node_allocator.max_size(); } + public: // Observers + key_equal + key_eq() const + { return this->m_eq; } + + // hash_function, if present, comes from hash_code_base. + public: // Bucket operations size_type bucket_count() const @@ -1094,9 +1101,11 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) bucket_size(size_type n) const { return std::distance(begin(n), end(n)); } - size_type bucket(const key_type& k) const + size_type + bucket(const key_type& k) const { - return this->bucket_index(k, this->m_hash_code, this->m_bucket_count); + return this->bucket_index(k, this->m_hash_code(k), + this->m_bucket_count); } local_iterator @@ -1477,9 +1486,9 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) hashtable:: find(const key_type& k) { - typename hashtable::hash_code_t code = this->m_hash_code (k); + typename hashtable::hash_code_t code = this->m_hash_code(k); std::size_t n = this->bucket_index(k, code, this->bucket_count()); - node* p = find_node (m_buckets[n], k, code); + node* p = find_node(m_buckets[n], k, code); return p ? iterator(p, m_buckets + n) : this->end(); } @@ -1491,9 +1500,9 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) hashtable:: find(const key_type& k) const { - typename hashtable::hash_code_t code = this->m_hash_code (k); + typename hashtable::hash_code_t code = this->m_hash_code(k); std::size_t n = this->bucket_index(k, code, this->bucket_count()); - node* p = find_node (m_buckets[n], k, code); + node* p = find_node(m_buckets[n], k, code); return p ? const_iterator(p, m_buckets + n) : this->end(); } @@ -1505,11 +1514,11 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) hashtable:: count(const key_type& k) const { - typename hashtable::hash_code_t code = this->m_hash_code (k); - std::size_t n = this->bucket_index (k, code, this->bucket_count()); + typename hashtable::hash_code_t code = this->m_hash_code(k); + std::size_t n = this->bucket_index(k, code, this->bucket_count()); size_t result = 0; for (node* p = m_buckets[n]; p ; p = p->m_next) - if (this->compare (k, code, p)) + if (this->compare(k, code, p)) ++result; return result; } @@ -1525,7 +1534,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) hashtable:: equal_range(const key_type& k) { - typename hashtable::hash_code_t code = this->m_hash_code (k); + typename hashtable::hash_code_t code = this->m_hash_code(k); std::size_t n = this->bucket_index(k, code, this->bucket_count()); node** head = m_buckets + n; node* p = find_node (*head, k, code); @@ -1558,16 +1567,16 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) hashtable:: equal_range(const key_type& k) const { - typename hashtable::hash_code_t code = this->m_hash_code (k); + typename hashtable::hash_code_t code = this->m_hash_code(k); std::size_t n = this->bucket_index(k, code, this->bucket_count()); node** head = m_buckets + n; - node* p = find_node (*head, k, code); + node* p = find_node(*head, k, code); if (p) { node* p1 = p->m_next; for (; p1 ; p1 = p1->m_next) - if (!this->compare (k, code, p1)) + if (!this->compare(k, code, p1)) break; const_iterator first(p, head); @@ -1608,7 +1617,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) insert(const value_type& v, std::tr1::true_type) { const key_type& k = this->m_extract(v); - typename hashtable::hash_code_t code = this->m_hash_code (k); + typename hashtable::hash_code_t code = this->m_hash_code(k); size_type n = this->bucket_index(k, code, m_bucket_count); if (node* p = find_node(m_buckets[n], k, code)) @@ -1657,7 +1666,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) m_rehash(do_rehash.second); const key_type& k = this->m_extract(v); - typename hashtable::hash_code_t code = this->m_hash_code (k); + typename hashtable::hash_code_t code = this->m_hash_code(k); size_type n = this->bucket_index(k, code, m_bucket_count); node* new_node = m_allocate_node (v); @@ -1760,15 +1769,15 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) hashtable:: erase(const key_type& k) { - typename hashtable::hash_code_t code = this->m_hash_code (k); + typename hashtable::hash_code_t code = this->m_hash_code(k); size_type n = this->bucket_index(k, code, m_bucket_count); size_type result = 0; node** slot = m_buckets + n; - while (*slot && ! this->compare (k, code, *slot)) + while (*slot && ! this->compare(k, code, *slot)) slot = &((*slot)->m_next); - while (*slot && this->compare (k, code, *slot)) + while (*slot && this->compare(k, code, *slot)) { node* n = *slot; *slot = n->m_next; diff --git a/libstdc++-v3/testsuite/tr1/6_containers/unordered/hashtable/26127.cc b/libstdc++-v3/testsuite/tr1/6_containers/unordered/hashtable/26127.cc new file mode 100644 index 000000000000..d14a625b554c --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/unordered/hashtable/26127.cc @@ -0,0 +1,39 @@ +// { dg-do compile } + +// Copyright (C) 2006 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 6.3 Unordered associative containers + +#include + +// libstdc++/26127 +void test01() +{ + std::tr1::unordered_set s; + + s.bucket(42); + s.key_eq(); + s.max_load_factor(); +} + +int main() +{ + test01(); + return 0; +} -- 2.43.5