This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Export _Prime_rehash_policy symbols
- From: François Dumont <frs dot dumont at gmail dot com>
- To: "libstdc++ at gcc dot gnu dot org" <libstdc++ at gcc dot gnu dot org>
- Date: Tue, 29 Jan 2013 22:22:33 +0100
- Subject: Export _Prime_rehash_policy symbols
Hi
This long standing issue has been reported to my attention by Paolo
some weeks ago. This is the patch to export _Prime_rehash_policy symbols.
2013-01-29 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.
* config/abi/gnu.ver (GLIBCXX_3.4.18): Export _Prime_rehash_policy
symbols.
Tested under Linux x86_64.
Ok for trunk ?
I also notice a weird thing in hashtable_c++0x.cc. It is including
shared/hashtable-aux.cc within namespace std scope. However
hashtable-aux.cc includes <bits/config.h> itself. If hashtable_c++0x.cc
was not including <bits/config.h> it would fail to compile. Do you want
me to remove <bits/config.h> include from shared/hashtable-aux.cc at the
same time ?
François
Index: include/bits/hashtable_policy.h
===================================================================
--- include/bits/hashtable_policy.h (revision 195557)
+++ include/bits/hashtable_policy.h (working copy)
@@ -369,7 +369,8 @@
// Return a bucket count appropriate for n elements
std::size_t
- _M_bkt_for_elements(std::size_t __n) const;
+ _M_bkt_for_elements(std::size_t __n) const
+ { return __builtin_ceil(__n / (long double)_M_max_load_factor); }
// __n_bkt is current bucket count, __n_elt is current element count,
// and __n_ins is number of elements to be inserted. Do we need to
@@ -397,77 +398,6 @@
mutable std::size_t _M_next_resize;
};
- extern const unsigned long __prime_list[];
-
- // XXX This is a hack. There's no good reason for any of
- // _Prime_rehash_policy's member functions to be inline.
-
- // Return a prime no smaller than n.
- inline 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;
- }
-
- // Return the smallest integer p such that alpha p >= n, where alpha
- // is the load factor.
- inline std::size_t
- _Prime_rehash_policy::
- _M_bkt_for_elements(std::size_t __n) const
- { return __builtin_ceil(__n / (long double)_M_max_load_factor); }
-
- // 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.
-
- inline 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)));
- else
- {
- _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);
- }
-
// Base classes for std::_Hashtable. We define these base classes
// because in some cases we want to do different things depending on
// the value of a policy class. In some cases the policy class
Index: src/c++11/hashtable_c++0x.cc
===================================================================
--- src/c++11/hashtable_c++0x.cc (revision 195557)
+++ src/c++11/hashtable_c++0x.cc (working copy)
@@ -1,6 +1,6 @@
// std::__detail definitions -*- C++ -*-
-// Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+// Copyright (C) 2007-2012 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
@@ -28,7 +28,70 @@
# error "hashtable_c++0x.cc must be compiled with -std=gnu++0x"
#endif
+#include <unordered_set>
+
namespace std _GLIBCXX_VISIBILITY(default)
{
#include "../shared/hashtable-aux.cc"
+
+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 // namespace std
Index: config/abi/pre/gnu.ver
===================================================================
--- config/abi/pre/gnu.ver (revision 195557)
+++ config/abi/pre/gnu.ver (working copy)
@@ -1334,6 +1334,7 @@
extern "C++"
{
std::random_device::*;
+ std::__detail::_Prime_rehash_policy::*;
};
# std::this_thread::__sleep_for