[multiple changes]

2006-02-07  Paolo Carlini  <pcarlini@suse.de>	

	* include/tr1/hashtable: Trivial formatting fixes.

2006-02-07  Paolo Carlini  <pcarlini@suse.de>
	    Zak Kipling  <zak@transversal.com>

	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 <zak@transversal.com>

From-SVN: r110697
This commit is contained in:
Paolo Carlini 2006-02-07 15:11:10 +00:00 committed by Paolo Carlini
parent 4f0de5dd33
commit 774b9d213a
3 changed files with 80 additions and 20 deletions

View File

@ -1,3 +1,15 @@
2006-02-07 Paolo Carlini <pcarlini@suse.de>
* include/tr1/hashtable: Trivial formatting fixes.
2006-02-07 Paolo Carlini <pcarlini@suse.de>
Zak Kipling <zak@transversal.com>
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 <pcarlini@suse.de>
* include/tr1/cmath: New.

View File

@ -653,7 +653,7 @@ namespace Internal
max_load_factor() const
{
const Hashtable* This = static_cast<const Hashtable*>(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<K, V, A, Ex, Eq, H1, H2, H, RP, c, ci, u>::
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<K, V, A, Ex, Eq, H1, H2, H, RP, c, ci, u>::
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<K, V, A, Ex, Eq, H1, H2, H, RP, c, ci, u>::
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<K, V, A, Ex, Eq, H1, H2, H, RP, c, ci, u>::
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<K, V, A, Ex, Eq, H1, H2, H, RP, c, ci, u>::
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<K, V, A, Ex, Eq, H1, H2, H, RP, c, ci, u>::
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;

View File

@ -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 <tr1/unordered_set>
// libstdc++/26127
void test01()
{
std::tr1::unordered_set<int> s;
s.bucket(42);
s.key_eq();
s.max_load_factor();
}
int main()
{
test01();
return 0;
}