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.
51 num_distinct_sizes_32_bit = 30,
52 num_distinct_sizes_64_bit = 62,
53 num_distinct_sizes = sizeof(std::size_t) != 8 ?
54 num_distinct_sizes_32_bit : num_distinct_sizes_64_bit,
57 // Originally taken from the SGI implementation; acknowledged in the docs.
58 // Further modified (for 64 bits) from tr1's hashtable.
59 static const std::size_t g_a_sizes[num_distinct_sizes_64_bit] =
88 /* 27 */ 1164186217ul,
89 /* 28 */ 2364114217ul,
90 /* 29 */ 4294967291ul,
91 /* 30 */ (std::size_t)8589934583ull,
92 /* 31 */ (std::size_t)17179869143ull,
93 /* 32 */ (std::size_t)34359738337ull,
94 /* 33 */ (std::size_t)68719476731ull,
95 /* 34 */ (std::size_t)137438953447ull,
96 /* 35 */ (std::size_t)274877906899ull,
97 /* 36 */ (std::size_t)549755813881ull,
98 /* 37 */ (std::size_t)1099511627689ull,
99 /* 38 */ (std::size_t)2199023255531ull,
100 /* 39 */ (std::size_t)4398046511093ull,
101 /* 40 */ (std::size_t)8796093022151ull,
102 /* 41 */ (std::size_t)17592186044399ull,
103 /* 42 */ (std::size_t)35184372088777ull,
104 /* 43 */ (std::size_t)70368744177643ull,
105 /* 44 */ (std::size_t)140737488355213ull,
106 /* 45 */ (std::size_t)281474976710597ull,
107 /* 46 */ (std::size_t)562949953421231ull,
108 /* 47 */ (std::size_t)1125899906842597ull,
109 /* 48 */ (std::size_t)2251799813685119ull,
110 /* 49 */ (std::size_t)4503599627370449ull,
111 /* 50 */ (std::size_t)9007199254740881ull,
112 /* 51 */ (std::size_t)18014398509481951ull,
113 /* 52 */ (std::size_t)36028797018963913ull,
114 /* 53 */ (std::size_t)72057594037927931ull,
115 /* 54 */ (std::size_t)144115188075855859ull,
116 /* 55 */ (std::size_t)288230376151711717ull,
117 /* 56 */ (std::size_t)576460752303423433ull,
118 /* 57 */ (std::size_t)1152921504606846883ull,
119 /* 58 */ (std::size_t)2305843009213693951ull,
120 /* 59 */ (std::size_t)4611686018427387847ull,
121 /* 60 */ (std::size_t)9223372036854775783ull,
122 /* 61 */ (std::size_t)18446744073709551557ull,
125 } // namespace detail
130 hash_prime_size_policy(size_type n) : m_start_size(n)
131 { m_start_size = get_nearest_larger_size(n); }
136 swap(PB_DS_CLASS_C_DEC& other)
137 { std::swap(m_start_size, other.m_start_size); }
140 inline PB_DS_CLASS_C_DEC::size_type
142 get_nearest_larger_size(size_type n) const
144 const std::size_t* const p_upper = std::upper_bound(detail::g_a_sizes,
145 detail::g_a_sizes + detail::num_distinct_sizes, n);
147 if (p_upper == detail::g_a_sizes + detail::num_distinct_sizes)
148 __throw_resize_error();
153 inline PB_DS_CLASS_C_DEC::size_type
155 get_nearest_smaller_size(size_type n) const
157 const size_t* p_lower = std::lower_bound(detail::g_a_sizes,
158 detail::g_a_sizes + detail::num_distinct_sizes, n);
160 if (*p_lower >= n && p_lower != detail::g_a_sizes)
162 if (*p_lower < m_start_size)