3 // Copyright (C) 2005, 2006 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 2, or (at your option) any later
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21 // As a special exception, you may use this file as part of a free
22 // software library without restriction. Specifically, if other files
23 // instantiate templates or use macros or inline functions from this
24 // file, or you compile this file and link it with other files to
25 // produce an executable, this file does not by itself cause the
26 // resulting executable to be covered by the GNU General Public
27 // License. This exception does not however invalidate any other
28 // reasons why the executable file might be covered by the GNU General
31 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
33 // Permission to use, copy, modify, sell, and distribute this software
34 // is hereby granted without fee, provided that the above copyright
35 // notice appears in all copies, and that both that copyright notice
36 // and this permission notice appear in supporting documentation. None
37 // of the above authors, nor IBM Haifa Research Laboratories, make any
38 // representation about the suitability of this software for any
39 // purpose. It is provided "as is" without express or implied
43 * @file hash_prime_size_policy_imp.hpp
44 * Contains a resize size policy implementation.
47 #pragma GCC system_header
53 num_distinct_sizes_32_bit
= 30,
54 num_distinct_sizes_64_bit
= 62,
55 num_distinct_sizes
= sizeof(std::size_t) != 8 ?
56 num_distinct_sizes_32_bit
: num_distinct_sizes_64_bit
,
59 // Originally taken from the SGI implementation; acknowledged in the docs.
60 // Further modified (for 64 bits) from tr1's hashtable.
61 static const std::size_t g_a_sizes
[num_distinct_sizes_64_bit
] =
90 /* 27 */ 1164186217ul,
91 /* 28 */ 2364114217ul,
92 /* 29 */ 4294967291ul,
93 /* 30 */ (std::size_t)8589934583ull,
94 /* 31 */ (std::size_t)17179869143ull,
95 /* 32 */ (std::size_t)34359738337ull,
96 /* 33 */ (std::size_t)68719476731ull,
97 /* 34 */ (std::size_t)137438953447ull,
98 /* 35 */ (std::size_t)274877906899ull,
99 /* 36 */ (std::size_t)549755813881ull,
100 /* 37 */ (std::size_t)1099511627689ull,
101 /* 38 */ (std::size_t)2199023255531ull,
102 /* 39 */ (std::size_t)4398046511093ull,
103 /* 40 */ (std::size_t)8796093022151ull,
104 /* 41 */ (std::size_t)17592186044399ull,
105 /* 42 */ (std::size_t)35184372088777ull,
106 /* 43 */ (std::size_t)70368744177643ull,
107 /* 44 */ (std::size_t)140737488355213ull,
108 /* 45 */ (std::size_t)281474976710597ull,
109 /* 46 */ (std::size_t)562949953421231ull,
110 /* 47 */ (std::size_t)1125899906842597ull,
111 /* 48 */ (std::size_t)2251799813685119ull,
112 /* 49 */ (std::size_t)4503599627370449ull,
113 /* 50 */ (std::size_t)9007199254740881ull,
114 /* 51 */ (std::size_t)18014398509481951ull,
115 /* 52 */ (std::size_t)36028797018963913ull,
116 /* 53 */ (std::size_t)72057594037927931ull,
117 /* 54 */ (std::size_t)144115188075855859ull,
118 /* 55 */ (std::size_t)288230376151711717ull,
119 /* 56 */ (std::size_t)576460752303423433ull,
120 /* 57 */ (std::size_t)1152921504606846883ull,
121 /* 58 */ (std::size_t)2305843009213693951ull,
122 /* 59 */ (std::size_t)4611686018427387847ull,
123 /* 60 */ (std::size_t)9223372036854775783ull,
124 /* 61 */ (std::size_t)18446744073709551557ull,
127 } // namespace detail
132 hash_prime_size_policy(size_type n
) : m_start_size(n
)
133 { m_start_size
= get_nearest_larger_size(n
); }
138 swap(PB_DS_CLASS_C_DEC
& other
)
139 { std::swap(m_start_size
, other
.m_start_size
); }
142 inline PB_DS_CLASS_C_DEC::size_type
144 get_nearest_larger_size(size_type n
) const
146 const std::size_t* const p_upper
= std::upper_bound(detail::g_a_sizes
,
147 detail::g_a_sizes
+ detail::num_distinct_sizes
, n
);
149 if (p_upper
== detail::g_a_sizes
+ detail::num_distinct_sizes
)
150 __throw_resize_error();
155 inline PB_DS_CLASS_C_DEC::size_type
157 get_nearest_smaller_size(size_type n
) const
159 const size_t* p_lower
= std::lower_bound(detail::g_a_sizes
,
160 detail::g_a_sizes
+ detail::num_distinct_sizes
, n
);
162 if (*p_lower
>= n
&& p_lower
!= detail::g_a_sizes
)
164 if (*p_lower
< m_start_size
)