diff options
author | François Dumont <fdumont@gcc.gnu.org> | 2013-02-01 20:44:41 +0000 |
---|---|---|
committer | François Dumont <fdumont@gcc.gnu.org> | 2013-02-01 20:44:41 +0000 |
commit | 6e1479465794ad3ba7fe99b4d8986c6fd463feb0 (patch) | |
tree | 84518f8f30d1e3aa18963b72f5e5994b1c6e4483 /libstdc++-v3/src | |
parent | 99113dff9d9f04184797e8f3565dfe0c900a2345 (diff) | |
download | gcc-6e1479465794ad3ba7fe99b4d8986c6fd463feb0.zip gcc-6e1479465794ad3ba7fe99b4d8986c6fd463feb0.tar.gz gcc-6e1479465794ad3ba7fe99b4d8986c6fd463feb0.tar.bz2 |
2013-02-01 François Dumont <fdumont@gcc.gnu.org>
* include/bits/hashtable_policy.h
(_Prime_rehash_policy::_M_next_bkt)
(_Prime_rehash_policy::_M_need_rehash): Move definition...
* src/c++11/hashtable_c++0x.cc: ... here.
* src/shared/hashtable-aux.cc: Remove c++config.h include.
* config/abi/gnu.ver (GLIBCXX_3.4.18): Export _Prime_rehash_policy
symbols.
From-SVN: r195676
Diffstat (limited to 'libstdc++-v3/src')
-rw-r--r-- | libstdc++-v3/src/c++11/hashtable_c++0x.cc | 71 | ||||
-rw-r--r-- | libstdc++-v3/src/shared/hashtable-aux.cc | 4 |
2 files changed, 68 insertions, 7 deletions
diff --git a/libstdc++-v3/src/c++11/hashtable_c++0x.cc b/libstdc++-v3/src/c++11/hashtable_c++0x.cc index 3391131..7617c58 100644 --- a/libstdc++-v3/src/c++11/hashtable_c++0x.cc +++ b/libstdc++-v3/src/c++11/hashtable_c++0x.cc @@ -1,6 +1,6 @@ // std::__detail definitions -*- C++ -*- -// Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. +// Copyright (C) 2007-2013 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 @@ -22,13 +22,76 @@ // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see // <http://www.gnu.org/licenses/>. -#include <bits/c++config.h> - #if __cplusplus < 201103L # error "hashtable_c++0x.cc must be compiled with -std=gnu++0x" #endif +#include <initializer_list> +#include <tuple> +#include <bits/hashtable_policy.h> + namespace std _GLIBCXX_VISIBILITY(default) { #include "../shared/hashtable-aux.cc" -} // namespace // namespace std + +namespace __detail +{ + _GLIBCXX_BEGIN_NAMESPACE_VERSION + + // Return a prime no smaller than n. + std::size_t + _Prime_rehash_policy::_M_next_bkt(std::size_t __n) const + { + // Optimize lookups involving the first elements of __prime_list. + // (useful to speed-up, eg, constructors) + static const unsigned char __fast_bkt[12] + = { 2, 2, 2, 3, 5, 5, 7, 7, 11, 11, 11, 11 }; + + if (__n <= 11) + { + _M_next_resize = + __builtin_ceil(__fast_bkt[__n] * (long double)_M_max_load_factor); + return __fast_bkt[__n]; + } + + const unsigned long* __next_bkt = + std::lower_bound(__prime_list + 5, __prime_list + _S_n_primes, __n); + _M_next_resize = + __builtin_ceil(*__next_bkt * (long double)_M_max_load_factor); + return *__next_bkt; + } + + // Finds the smallest prime p such that alpha p > __n_elt + __n_ins. + // If p > __n_bkt, return make_pair(true, p); otherwise return + // make_pair(false, 0). In principle this isn't very different from + // _M_bkt_for_elements. + + // The only tricky part is that we're caching the element count at + // which we need to rehash, so we don't have to do a floating-point + // multiply for every insertion. + + std::pair<bool, std::size_t> + _Prime_rehash_policy:: + _M_need_rehash(std::size_t __n_bkt, std::size_t __n_elt, + std::size_t __n_ins) const + { + if (__n_elt + __n_ins >= _M_next_resize) + { + long double __min_bkts = (__n_elt + __n_ins) + / (long double)_M_max_load_factor; + if (__min_bkts >= __n_bkt) + return std::make_pair(true, + _M_next_bkt(std::max<std::size_t>(__builtin_floor(__min_bkts) + 1, + __n_bkt * _S_growth_factor))); + + _M_next_resize + = __builtin_floor(__n_bkt * (long double)_M_max_load_factor); + return std::make_pair(false, 0); + } + else + return std::make_pair(false, 0); + } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace __detail +} // namespace std diff --git a/libstdc++-v3/src/shared/hashtable-aux.cc b/libstdc++-v3/src/shared/hashtable-aux.cc index 23bb00e..876ffe1 100644 --- a/libstdc++-v3/src/shared/hashtable-aux.cc +++ b/libstdc++-v3/src/shared/hashtable-aux.cc @@ -1,6 +1,6 @@ // std::__detail and std::tr1::__detail definitions -*- C++ -*- -// Copyright (C) 2007, 2009, 2011 Free Software Foundation, Inc. +// Copyright (C) 2007-2013 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 @@ -22,8 +22,6 @@ // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see // <http://www.gnu.org/licenses/>. -#include <bits/c++config.h> - namespace __detail { _GLIBCXX_BEGIN_NAMESPACE_VERSION |