Commit 03ba64bb by Paolo Carlini Committed by Paolo Carlini

hashtable: Trivial formatting fixes.

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

	* include/tr1/hashtable: Trivial formatting fixes.

From-SVN: r111355
parent 411c6f86
2006-02-21 Paolo Carlini <pcarlini@suse.de>
* include/tr1/hashtable: Trivial formatting fixes.
2006-02-20 Paolo Carlini <pcarlini@suse.de> 2006-02-20 Paolo Carlini <pcarlini@suse.de>
Revert recent commit for libstdc++/26211, now suspended waiting for Revert recent commit for libstdc++/26211, now suspended waiting for
......
...@@ -101,6 +101,7 @@ namespace Internal ...@@ -101,6 +101,7 @@ namespace Internal
} // namespace Internal } // namespace Internal
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// Auxiliary types used for all instantiations of hashtable: nodes // Auxiliary types used for all instantiations of hashtable: nodes
// and iterators. // and iterators.
...@@ -381,6 +382,7 @@ namespace Internal ...@@ -381,6 +382,7 @@ namespace Internal
}; };
} // namespace Internal } // namespace Internal
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Many of class template hashtable's template parameters are policy // Many of class template hashtable's template parameters are policy
// classes. These are defaults for the policies. // classes. These are defaults for the policies.
...@@ -413,7 +415,7 @@ namespace Internal ...@@ -413,7 +415,7 @@ namespace Internal
typedef std::size_t result_type; typedef std::size_t result_type;
result_type result_type
operator() (first_argument_type r, second_argument_type N) const operator()(first_argument_type r, second_argument_type N) const
{ return r % N; } { return r % N; }
}; };
...@@ -542,7 +544,7 @@ namespace Internal ...@@ -542,7 +544,7 @@ namespace Internal
next_bkt(std::size_t n) const next_bkt(std::size_t n) const
{ {
const unsigned long* const last = X<0>::primes + X<0>::n_primes; const unsigned long* const last = X<0>::primes + X<0>::n_primes;
const unsigned long* p = std::lower_bound (X<0>::primes, last, n); const unsigned long* p = std::lower_bound(X<0>::primes, last, n);
m_next_resize = static_cast<std::size_t>(std::ceil(*p * m_max_load_factor)); m_next_resize = static_cast<std::size_t>(std::ceil(*p * m_max_load_factor));
return *p; return *p;
} }
...@@ -555,7 +557,7 @@ namespace Internal ...@@ -555,7 +557,7 @@ namespace Internal
{ {
const unsigned long* const last = X<0>::primes + X<0>::n_primes; const unsigned long* const last = X<0>::primes + X<0>::n_primes;
const float min_bkts = n / m_max_load_factor; const float min_bkts = n / m_max_load_factor;
const unsigned long* p = std::lower_bound (X<0>::primes, last, const unsigned long* p = std::lower_bound(X<0>::primes, last,
min_bkts, lt()); min_bkts, lt());
m_next_resize = static_cast<std::size_t>(std::ceil(*p * m_max_load_factor)); m_next_resize = static_cast<std::size_t>(std::ceil(*p * m_max_load_factor));
return *p; return *p;
...@@ -579,9 +581,9 @@ namespace Internal ...@@ -579,9 +581,9 @@ namespace Internal
float min_bkts = (float(n_ins) + float(n_elt)) / m_max_load_factor; float min_bkts = (float(n_ins) + float(n_elt)) / m_max_load_factor;
if (min_bkts > n_bkt) if (min_bkts > n_bkt)
{ {
min_bkts = std::max (min_bkts, m_growth_factor * n_bkt); min_bkts = std::max(min_bkts, m_growth_factor * n_bkt);
const unsigned long* const last = X<0>::primes + X<0>::n_primes; const unsigned long* const last = X<0>::primes + X<0>::n_primes;
const unsigned long* p = std::lower_bound (X<0>::primes, last, const unsigned long* p = std::lower_bound(X<0>::primes, last,
min_bkts, lt()); min_bkts, lt());
m_next_resize = m_next_resize =
static_cast<std::size_t>(std::ceil(*p * m_max_load_factor)); static_cast<std::size_t>(std::ceil(*p * m_max_load_factor));
...@@ -600,6 +602,7 @@ namespace Internal ...@@ -600,6 +602,7 @@ namespace Internal
} // namespace Internal } // namespace Internal
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// Base classes for std::tr1::hashtable. We define these base classes // Base classes for std::tr1::hashtable. We define these base classes
// because in some cases we want to do different things depending on // because in some cases we want to do different things depending on
...@@ -703,15 +706,15 @@ namespace Internal ...@@ -703,15 +706,15 @@ namespace Internal
std::size_t std::size_t
bucket_index(const Key& k, hash_code_t, std::size_t N) const bucket_index(const Key& k, hash_code_t, std::size_t N) const
{ return m_ranged_hash (k, N); } { return m_ranged_hash(k, N); }
std::size_t std::size_t
bucket_index(const hash_node<Value, false>* p, std::size_t N) const bucket_index(const hash_node<Value, false>* p, std::size_t N) const
{ return m_ranged_hash (m_extract (p->m_v), N); } { return m_ranged_hash(m_extract(p->m_v), N); }
bool bool
compare(const Key& k, hash_code_t, hash_node<Value, false>* n) const compare(const Key& k, hash_code_t, hash_node<Value, false>* n) const
{ return m_eq (k, m_extract(n->m_v)); } { return m_eq(k, m_extract(n->m_v)); }
void void
store_code(hash_node<Value, false>*, hash_code_t) const store_code(hash_node<Value, false>*, hash_code_t) const
...@@ -779,15 +782,15 @@ namespace Internal ...@@ -779,15 +782,15 @@ namespace Internal
std::size_t std::size_t
bucket_index(const Key&, hash_code_t c, std::size_t N) const bucket_index(const Key&, hash_code_t c, std::size_t N) const
{ return m_h2 (c, N); } { return m_h2(c, N); }
std::size_t std::size_t
bucket_index(const hash_node<Value, false>* p, std::size_t N) const bucket_index(const hash_node<Value, false>* p, std::size_t N) const
{ return m_h2 (m_h1 (m_extract (p->m_v)), N); } { return m_h2(m_h1(m_extract(p->m_v)), N); }
bool bool
compare(const Key& k, hash_code_t, hash_node<Value, false>* n) const compare(const Key& k, hash_code_t, hash_node<Value, false>* n) const
{ return m_eq (k, m_extract(n->m_v)); } { return m_eq(k, m_extract(n->m_v)); }
void void
store_code(hash_node<Value, false>*, hash_code_t) const store_code(hash_node<Value, false>*, hash_code_t) const
...@@ -841,11 +844,11 @@ namespace Internal ...@@ -841,11 +844,11 @@ namespace Internal
std::size_t std::size_t
bucket_index(const Key&, hash_code_t c, std::size_t N) const bucket_index(const Key&, hash_code_t c, std::size_t N) const
{ return m_h2 (c, N); } { return m_h2(c, N); }
std::size_t std::size_t
bucket_index(const hash_node<Value, true>* p, std::size_t N) const bucket_index(const hash_node<Value, true>* p, std::size_t N) const
{ return m_h2 (p->hash_code, N); } { return m_h2(p->hash_code, N); }
bool bool
compare(const Key& k, hash_code_t c, hash_node<Value, true>* n) const compare(const Key& k, hash_code_t c, hash_node<Value, true>* n) const
...@@ -1231,6 +1234,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1231,6 +1234,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
void m_rehash(size_type n); void m_rehash(size_type n);
}; };
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// Definitions of class template hashtable's out-of-line member functions. // Definitions of class template hashtable's out-of-line member functions.
...@@ -1283,7 +1287,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1283,7 +1287,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
{ {
node* tmp = p; node* tmp = p;
p = p->m_next; p = p->m_next;
m_deallocate_node (tmp); m_deallocate_node(tmp);
} }
array[i] = 0; array[i] = 0;
} }
...@@ -1301,7 +1305,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1301,7 +1305,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
// We allocate one extra bucket to hold a sentinel, an arbitrary // We allocate one extra bucket to hold a sentinel, an arbitrary
// non-null pointer. Iterator increment relies on this. // non-null pointer. Iterator increment relies on this.
node** p = alloc.allocate(n+1); node** p = alloc.allocate(n + 1);
std::fill(p, p+n, (node*) 0); std::fill(p, p+n, (node*) 0);
p[n] = reinterpret_cast<node*>(0x1000); p[n] = reinterpret_cast<node*>(0x1000);
return p; return p;
...@@ -1328,7 +1332,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1328,7 +1332,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
const H1& h1, const H2& h2, const H& h, const H1& h1, const H2& h2, const H& h,
const Eq& eq, const Ex& exk, const Eq& eq, const Ex& exk,
const allocator_type& a) const allocator_type& a)
: Internal::rehash_base<RP,hashtable>(), : Internal::rehash_base<RP, hashtable>(),
Internal::hash_code_base<K, V, Ex, Eq, H1, H2, H, c>(exk, eq, h1, h2, h), Internal::hash_code_base<K, V, Ex, Eq, H1, H2, H, c>(exk, eq, h1, h2, h),
Internal::map_base<K, V, Ex, u, hashtable>(), Internal::map_base<K, V, Ex, u, hashtable>(),
m_node_allocator(a), m_node_allocator(a),
...@@ -1351,10 +1355,10 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1351,10 +1355,10 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
const H1& h1, const H2& h2, const H& h, const H1& h1, const H2& h2, const H& h,
const Eq& eq, const Ex& exk, const Eq& eq, const Ex& exk,
const allocator_type& a) const allocator_type& a)
: Internal::rehash_base<RP,hashtable>(), : Internal::rehash_base<RP, hashtable>(),
Internal::hash_code_base<K, V, Ex, Eq, H1, H2, H, c> (exk, eq, Internal::hash_code_base<K, V, Ex, Eq, H1, H2, H, c> (exk, eq,
h1, h2, h), h1, h2, h),
Internal::map_base<K,V,Ex,u,hashtable>(), Internal::map_base<K, V, Ex, u, hashtable>(),
m_node_allocator(a), m_node_allocator(a),
m_bucket_count (0), m_bucket_count (0),
m_element_count(0), m_element_count(0),
...@@ -1408,7 +1412,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1408,7 +1412,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
} }
} }
} }
catch (...) catch(...)
{ {
clear(); clear();
m_deallocate_buckets (m_buckets, m_bucket_count); m_deallocate_buckets (m_buckets, m_bucket_count);
...@@ -1475,7 +1479,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1475,7 +1479,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
m_rehash_policy = pol; m_rehash_policy = pol;
size_type n_bkt = pol.bkt_for_elements(m_element_count); size_type n_bkt = pol.bkt_for_elements(m_element_count);
if (n_bkt > m_bucket_count) if (n_bkt > m_bucket_count)
m_rehash (n_bkt); m_rehash(n_bkt);
} }
template<typename K, typename V, template<typename K, typename V,
...@@ -1517,7 +1521,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1517,7 +1521,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
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()); std::size_t n = this->bucket_index(k, code, this->bucket_count());
size_t result = 0; size_t result = 0;
for (node* p = m_buckets[n]; p ; p = p->m_next) for (node* p = m_buckets[n]; p; p = p->m_next)
if (this->compare(k, code, p)) if (this->compare(k, code, p))
++result; ++result;
return result; return result;
...@@ -1542,8 +1546,8 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1542,8 +1546,8 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
if (p) if (p)
{ {
node* p1 = p->m_next; node* p1 = p->m_next;
for (; p1 ; p1 = p1->m_next) for (; p1; p1 = p1->m_next)
if (!this->compare (k, code, p1)) if (!this->compare(k, code, p1))
break; break;
iterator first(p, head); iterator first(p, head);
...@@ -1575,7 +1579,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1575,7 +1579,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
if (p) if (p)
{ {
node* p1 = p->m_next; node* p1 = p->m_next;
for (; p1 ; p1 = p1->m_next) for (; p1; p1 = p1->m_next)
if (!this->compare(k, code, p1)) if (!this->compare(k, code, p1))
break; break;
...@@ -1600,8 +1604,8 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1600,8 +1604,8 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
find_node(node* p, const key_type& k, find_node(node* p, const key_type& k,
typename hashtable::hash_code_t code) const typename hashtable::hash_code_t code) const
{ {
for ( ; p ; p = p->m_next) for (; p ; p = p->m_next)
if (this->compare (k, code, p)) if (this->compare(k, code, p))
return p; return p;
return false; return false;
} }
...@@ -1628,7 +1632,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1628,7 +1632,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
// Allocate the new node before doing the rehash so that we don't // Allocate the new node before doing the rehash so that we don't
// do a rehash if the allocation throws. // do a rehash if the allocation throws.
node* new_node = m_allocate_node (v); node* new_node = m_allocate_node(v);
try try
{ {
...@@ -1644,9 +1648,9 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1644,9 +1648,9 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
++m_element_count; ++m_element_count;
return std::make_pair(iterator(new_node, m_buckets + n), true); return std::make_pair(iterator(new_node, m_buckets + n), true);
} }
catch (...) catch(...)
{ {
m_deallocate_node (new_node); m_deallocate_node(new_node);
__throw_exception_again; __throw_exception_again;
} }
} }
...@@ -1669,7 +1673,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1669,7 +1673,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
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 n = this->bucket_index(k, code, m_bucket_count);
node* new_node = m_allocate_node (v); node* new_node = m_allocate_node(v);
node* prev = find_node(m_buckets[n], k, code); node* prev = find_node(m_buckets[n], k, code);
if (prev) if (prev)
{ {
...@@ -1710,7 +1714,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1710,7 +1714,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
cur->m_next = next->m_next; cur->m_next = next->m_next;
} }
m_deallocate_node (p); m_deallocate_node(p);
--m_element_count; --m_element_count;
} }
...@@ -1730,7 +1734,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1730,7 +1734,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
m_rehash(do_rehash.second); m_rehash(do_rehash.second);
for (; first != last; ++first) for (; first != last; ++first)
this->insert (*first); this->insert(*first);
} }
template<typename K, typename V, template<typename K, typename V,
...@@ -1774,14 +1778,14 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1774,14 +1778,14 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
size_type result = 0; size_type result = 0;
node** slot = m_buckets + n; node** slot = m_buckets + n;
while (*slot && ! this->compare(k, code, *slot)) while (*slot && !this->compare(k, code, *slot))
slot = &((*slot)->m_next); slot = &((*slot)->m_next);
while (*slot && this->compare(k, code, *slot)) while (*slot && this->compare(k, code, *slot))
{ {
node* n = *slot; node* n = *slot;
*slot = n->m_next; *slot = n->m_next;
m_deallocate_node (n); m_deallocate_node(n);
--m_element_count; --m_element_count;
++result; ++result;
} }
...@@ -1838,13 +1842,13 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1838,13 +1842,13 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
hashtable<K, V, A, Ex, Eq, H1, H2, H, RP, c, ci, u>:: hashtable<K, V, A, Ex, Eq, H1, H2, H, RP, c, ci, u>::
m_rehash(size_type N) m_rehash(size_type N)
{ {
node** new_array = m_allocate_buckets (N); node** new_array = m_allocate_buckets(N);
try try
{ {
for (size_type i = 0; i < m_bucket_count; ++i) for (size_type i = 0; i < m_bucket_count; ++i)
while (node* p = m_buckets[i]) while (node* p = m_buckets[i])
{ {
size_type new_index = this->bucket_index (p, N); size_type new_index = this->bucket_index(p, N);
m_buckets[i] = p->m_next; m_buckets[i] = p->m_next;
p->m_next = new_array[new_index]; p->m_next = new_array[new_index];
new_array[new_index] = p; new_array[new_index] = p;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment