xref: /openbsd-src/gnu/gcc/libstdc++-v3/include/tr1/hashtable_policy.h (revision 404b540a9034ac75a6199ad1a32d1bbc7a0d4210)
1*404b540aSrobert // Internal policy header for TR1 unordered_set and unordered_map -*- C++ -*-
2*404b540aSrobert 
3*404b540aSrobert // Copyright (C) 2005, 2006 Free Software Foundation, Inc.
4*404b540aSrobert //
5*404b540aSrobert // This file is part of the GNU ISO C++ Library.  This library is free
6*404b540aSrobert // software; you can redistribute it and/or modify it under the
7*404b540aSrobert // terms of the GNU General Public License as published by the
8*404b540aSrobert // Free Software Foundation; either version 2, or (at your option)
9*404b540aSrobert // any later version.
10*404b540aSrobert 
11*404b540aSrobert // This library is distributed in the hope that it will be useful,
12*404b540aSrobert // but WITHOUT ANY WARRANTY; without even the implied warranty of
13*404b540aSrobert // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*404b540aSrobert // GNU General Public License for more details.
15*404b540aSrobert 
16*404b540aSrobert // You should have received a copy of the GNU General Public License along
17*404b540aSrobert // with this library; see the file COPYING.  If not, write to the Free
18*404b540aSrobert // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19*404b540aSrobert // USA.
20*404b540aSrobert 
21*404b540aSrobert // As a special exception, you may use this file as part of a free software
22*404b540aSrobert // library without restriction.  Specifically, if other files instantiate
23*404b540aSrobert // templates or use macros or inline functions from this file, or you compile
24*404b540aSrobert // this file and link it with other files to produce an executable, this
25*404b540aSrobert // file does not by itself cause the resulting executable to be covered by
26*404b540aSrobert // the GNU General Public License.  This exception does not however
27*404b540aSrobert // invalidate any other reasons why the executable file might be covered by
28*404b540aSrobert // the GNU General Public License.
29*404b540aSrobert 
30*404b540aSrobert /** @file tr1/hashtable_policy.h
31*404b540aSrobert  *  This is a TR1 C++ Library header.
32*404b540aSrobert  */
33*404b540aSrobert 
34*404b540aSrobert #ifndef _TR1_HASHTABLE_POLICY_H
35*404b540aSrobert #define _TR1_HASHTABLE_POLICY_H 1
36*404b540aSrobert 
37*404b540aSrobert #include <functional> // _Identity, _Select1st
38*404b540aSrobert #include <tr1/utility>
39*404b540aSrobert #include <ext/type_traits.h>
40*404b540aSrobert 
41*404b540aSrobert namespace std
42*404b540aSrobert {
_GLIBCXX_BEGIN_NAMESPACE(tr1)43*404b540aSrobert _GLIBCXX_BEGIN_NAMESPACE(tr1)
44*404b540aSrobert namespace __detail
45*404b540aSrobert {
46*404b540aSrobert   // Helper function: return distance(first, last) for forward
47*404b540aSrobert   // iterators, or 0 for input iterators.
48*404b540aSrobert   template<class _Iterator>
49*404b540aSrobert     inline typename std::iterator_traits<_Iterator>::difference_type
50*404b540aSrobert     __distance_fw(_Iterator __first, _Iterator __last,
51*404b540aSrobert 		  std::input_iterator_tag)
52*404b540aSrobert     { return 0; }
53*404b540aSrobert 
54*404b540aSrobert   template<class _Iterator>
55*404b540aSrobert     inline typename std::iterator_traits<_Iterator>::difference_type
56*404b540aSrobert     __distance_fw(_Iterator __first, _Iterator __last,
57*404b540aSrobert 		  std::forward_iterator_tag)
58*404b540aSrobert     { return std::distance(__first, __last); }
59*404b540aSrobert 
60*404b540aSrobert   template<class _Iterator>
61*404b540aSrobert     inline typename std::iterator_traits<_Iterator>::difference_type
62*404b540aSrobert     __distance_fw(_Iterator __first, _Iterator __last)
63*404b540aSrobert     {
64*404b540aSrobert       typedef typename std::iterator_traits<_Iterator>::iterator_category _Tag;
65*404b540aSrobert       return __distance_fw(__first, __last, _Tag());
66*404b540aSrobert     }
67*404b540aSrobert 
68*404b540aSrobert   // XXX This is a hack.  _Prime_rehash_policy's member functions, and
69*404b540aSrobert   // certainly the list of primes, should be defined in a .cc file.
70*404b540aSrobert   // We're temporarily putting them in a header because we don't have a
71*404b540aSrobert   // place to put TR1 .cc files yet.  There's no good reason for any of
72*404b540aSrobert   // _Prime_rehash_policy's member functions to be inline, and there's
73*404b540aSrobert   // certainly no good reason for _Primes<> to exist at all.
74*404b540aSrobert   struct _LessThan
75*404b540aSrobert   {
76*404b540aSrobert     template<typename _Tp, typename _Up>
77*404b540aSrobert       bool
78*404b540aSrobert       operator()(_Tp __x, _Up __y)
79*404b540aSrobert       { return __x < __y; }
80*404b540aSrobert   };
81*404b540aSrobert 
82*404b540aSrobert   template<int __ulongsize = sizeof(unsigned long)>
83*404b540aSrobert     struct _Primes
84*404b540aSrobert     {
85*404b540aSrobert       static const int __n_primes = __ulongsize != 8 ? 256 : 256 + 48;
86*404b540aSrobert       static const unsigned long __primes[256 + 48 + 1];
87*404b540aSrobert     };
88*404b540aSrobert 
89*404b540aSrobert   template<int __ulongsize>
90*404b540aSrobert     const int _Primes<__ulongsize>::__n_primes;
91*404b540aSrobert 
92*404b540aSrobert   template<int __ulongsize>
93*404b540aSrobert     const unsigned long _Primes<__ulongsize>::__primes[256 + 48 + 1] =
94*404b540aSrobert     {
95*404b540aSrobert       2ul, 3ul, 5ul, 7ul, 11ul, 13ul, 17ul, 19ul, 23ul, 29ul, 31ul,
96*404b540aSrobert       37ul, 41ul, 43ul, 47ul, 53ul, 59ul, 61ul, 67ul, 71ul, 73ul, 79ul,
97*404b540aSrobert       83ul, 89ul, 97ul, 103ul, 109ul, 113ul, 127ul, 137ul, 139ul, 149ul,
98*404b540aSrobert       157ul, 167ul, 179ul, 193ul, 199ul, 211ul, 227ul, 241ul, 257ul,
99*404b540aSrobert       277ul, 293ul, 313ul, 337ul, 359ul, 383ul, 409ul, 439ul, 467ul,
100*404b540aSrobert       503ul, 541ul, 577ul, 619ul, 661ul, 709ul, 761ul, 823ul, 887ul,
101*404b540aSrobert       953ul, 1031ul, 1109ul, 1193ul, 1289ul, 1381ul, 1493ul, 1613ul,
102*404b540aSrobert       1741ul, 1879ul, 2029ul, 2179ul, 2357ul, 2549ul, 2753ul, 2971ul,
103*404b540aSrobert       3209ul, 3469ul, 3739ul, 4027ul, 4349ul, 4703ul, 5087ul, 5503ul,
104*404b540aSrobert       5953ul, 6427ul, 6949ul, 7517ul, 8123ul, 8783ul, 9497ul, 10273ul,
105*404b540aSrobert       11113ul, 12011ul, 12983ul, 14033ul, 15173ul, 16411ul, 17749ul,
106*404b540aSrobert       19183ul, 20753ul, 22447ul, 24281ul, 26267ul, 28411ul, 30727ul,
107*404b540aSrobert       33223ul, 35933ul, 38873ul, 42043ul, 45481ul, 49201ul, 53201ul,
108*404b540aSrobert       57557ul, 62233ul, 67307ul, 72817ul, 78779ul, 85229ul, 92203ul,
109*404b540aSrobert       99733ul, 107897ul, 116731ul, 126271ul, 136607ul, 147793ul,
110*404b540aSrobert       159871ul, 172933ul, 187091ul, 202409ul, 218971ul, 236897ul,
111*404b540aSrobert       256279ul, 277261ul, 299951ul, 324503ul, 351061ul, 379787ul,
112*404b540aSrobert       410857ul, 444487ul, 480881ul, 520241ul, 562841ul, 608903ul,
113*404b540aSrobert       658753ul, 712697ul, 771049ul, 834181ul, 902483ul, 976369ul,
114*404b540aSrobert       1056323ul, 1142821ul, 1236397ul, 1337629ul, 1447153ul, 1565659ul,
115*404b540aSrobert       1693859ul, 1832561ul, 1982627ul, 2144977ul, 2320627ul, 2510653ul,
116*404b540aSrobert       2716249ul, 2938679ul, 3179303ul, 3439651ul, 3721303ul, 4026031ul,
117*404b540aSrobert       4355707ul, 4712381ul, 5098259ul, 5515729ul, 5967347ul, 6456007ul,
118*404b540aSrobert       6984629ul, 7556579ul, 8175383ul, 8844859ul, 9569143ul, 10352717ul,
119*404b540aSrobert       11200489ul, 12117689ul, 13109983ul, 14183539ul, 15345007ul,
120*404b540aSrobert       16601593ul, 17961079ul, 19431899ul, 21023161ul, 22744717ul,
121*404b540aSrobert       24607243ul, 26622317ul, 28802401ul, 31160981ul, 33712729ul,
122*404b540aSrobert       36473443ul, 39460231ul, 42691603ul, 46187573ul, 49969847ul,
123*404b540aSrobert       54061849ul, 58488943ul, 63278561ul, 68460391ul, 74066549ul,
124*404b540aSrobert       80131819ul, 86693767ul, 93793069ul, 101473717ul, 109783337ul,
125*404b540aSrobert       118773397ul, 128499677ul, 139022417ul, 150406843ul, 162723577ul,
126*404b540aSrobert       176048909ul, 190465427ul, 206062531ul, 222936881ul, 241193053ul,
127*404b540aSrobert       260944219ul, 282312799ul, 305431229ul, 330442829ul, 357502601ul,
128*404b540aSrobert       386778277ul, 418451333ul, 452718089ul, 489790921ul, 529899637ul,
129*404b540aSrobert       573292817ul, 620239453ul, 671030513ul, 725980837ul, 785430967ul,
130*404b540aSrobert       849749479ul, 919334987ul, 994618837ul, 1076067617ul, 1164186217ul,
131*404b540aSrobert       1259520799ul, 1362662261ul, 1474249943ul, 1594975441ul,
132*404b540aSrobert       1725587117ul, 1866894511ul, 2019773507ul, 2185171673ul,
133*404b540aSrobert       2364114217ul, 2557710269ul, 2767159799ul, 2993761039ul,
134*404b540aSrobert       3238918481ul, 3504151727ul, 3791104843ul, 4101556399ul,
135*404b540aSrobert       4294967291ul,
136*404b540aSrobert       // Sentinel, so we don't have to test the result of lower_bound,
137*404b540aSrobert       // or, on 64-bit machines, rest of the table.
138*404b540aSrobert       __ulongsize != 8 ? 4294967291ul : (unsigned long)6442450933ull,
139*404b540aSrobert       (unsigned long)8589934583ull,
140*404b540aSrobert       (unsigned long)12884901857ull, (unsigned long)17179869143ull,
141*404b540aSrobert       (unsigned long)25769803693ull, (unsigned long)34359738337ull,
142*404b540aSrobert       (unsigned long)51539607367ull, (unsigned long)68719476731ull,
143*404b540aSrobert       (unsigned long)103079215087ull, (unsigned long)137438953447ull,
144*404b540aSrobert       (unsigned long)206158430123ull, (unsigned long)274877906899ull,
145*404b540aSrobert       (unsigned long)412316860387ull, (unsigned long)549755813881ull,
146*404b540aSrobert       (unsigned long)824633720731ull, (unsigned long)1099511627689ull,
147*404b540aSrobert       (unsigned long)1649267441579ull, (unsigned long)2199023255531ull,
148*404b540aSrobert       (unsigned long)3298534883309ull, (unsigned long)4398046511093ull,
149*404b540aSrobert       (unsigned long)6597069766607ull, (unsigned long)8796093022151ull,
150*404b540aSrobert       (unsigned long)13194139533241ull, (unsigned long)17592186044399ull,
151*404b540aSrobert       (unsigned long)26388279066581ull, (unsigned long)35184372088777ull,
152*404b540aSrobert       (unsigned long)52776558133177ull, (unsigned long)70368744177643ull,
153*404b540aSrobert       (unsigned long)105553116266399ull, (unsigned long)140737488355213ull,
154*404b540aSrobert       (unsigned long)211106232532861ull, (unsigned long)281474976710597ull,
155*404b540aSrobert       (unsigned long)562949953421231ull, (unsigned long)1125899906842597ull,
156*404b540aSrobert       (unsigned long)2251799813685119ull, (unsigned long)4503599627370449ull,
157*404b540aSrobert       (unsigned long)9007199254740881ull, (unsigned long)18014398509481951ull,
158*404b540aSrobert       (unsigned long)36028797018963913ull, (unsigned long)72057594037927931ull,
159*404b540aSrobert       (unsigned long)144115188075855859ull,
160*404b540aSrobert       (unsigned long)288230376151711717ull,
161*404b540aSrobert       (unsigned long)576460752303423433ull,
162*404b540aSrobert       (unsigned long)1152921504606846883ull,
163*404b540aSrobert       (unsigned long)2305843009213693951ull,
164*404b540aSrobert       (unsigned long)4611686018427387847ull,
165*404b540aSrobert       (unsigned long)9223372036854775783ull,
166*404b540aSrobert       (unsigned long)18446744073709551557ull,
167*404b540aSrobert       (unsigned long)18446744073709551557ull
168*404b540aSrobert     };
169*404b540aSrobert 
170*404b540aSrobert   // Auxiliary types used for all instantiations of _Hashtable: nodes
171*404b540aSrobert   // and iterators.
172*404b540aSrobert 
173*404b540aSrobert   // Nodes, used to wrap elements stored in the hash table.  A policy
174*404b540aSrobert   // template parameter of class template _Hashtable controls whether
175*404b540aSrobert   // nodes also store a hash code. In some cases (e.g. strings) this
176*404b540aSrobert   // may be a performance win.
177*404b540aSrobert   template<typename _Value, bool __cache_hash_code>
178*404b540aSrobert     struct _Hash_node;
179*404b540aSrobert 
180*404b540aSrobert   template<typename _Value>
181*404b540aSrobert     struct _Hash_node<_Value, true>
182*404b540aSrobert     {
183*404b540aSrobert       _Value       _M_v;
184*404b540aSrobert       std::size_t  _M_hash_code;
185*404b540aSrobert       _Hash_node*  _M_next;
186*404b540aSrobert     };
187*404b540aSrobert 
188*404b540aSrobert   template<typename _Value>
189*404b540aSrobert     struct _Hash_node<_Value, false>
190*404b540aSrobert     {
191*404b540aSrobert       _Value       _M_v;
192*404b540aSrobert       _Hash_node*  _M_next;
193*404b540aSrobert     };
194*404b540aSrobert 
195*404b540aSrobert   // Local iterators, used to iterate within a bucket but not between
196*404b540aSrobert   // buckets.
197*404b540aSrobert   template<typename _Value, bool __cache>
198*404b540aSrobert     struct _Node_iterator_base
199*404b540aSrobert     {
200*404b540aSrobert       _Node_iterator_base(_Hash_node<_Value, __cache>* __p)
201*404b540aSrobert       : _M_cur(__p) { }
202*404b540aSrobert 
203*404b540aSrobert       void
204*404b540aSrobert       _M_incr()
205*404b540aSrobert       { _M_cur = _M_cur->_M_next; }
206*404b540aSrobert 
207*404b540aSrobert       _Hash_node<_Value, __cache>*  _M_cur;
208*404b540aSrobert     };
209*404b540aSrobert 
210*404b540aSrobert   template<typename _Value, bool __cache>
211*404b540aSrobert     inline bool
212*404b540aSrobert     operator==(const _Node_iterator_base<_Value, __cache>& __x,
213*404b540aSrobert 	       const _Node_iterator_base<_Value, __cache>& __y)
214*404b540aSrobert     { return __x._M_cur == __y._M_cur; }
215*404b540aSrobert 
216*404b540aSrobert   template<typename _Value, bool __cache>
217*404b540aSrobert     inline bool
218*404b540aSrobert     operator!=(const _Node_iterator_base<_Value, __cache>& __x,
219*404b540aSrobert 	       const _Node_iterator_base<_Value, __cache>& __y)
220*404b540aSrobert     { return __x._M_cur != __y._M_cur; }
221*404b540aSrobert 
222*404b540aSrobert   template<typename _Value, bool __constant_iterators, bool __cache>
223*404b540aSrobert     struct _Node_iterator
224*404b540aSrobert     : public _Node_iterator_base<_Value, __cache>
225*404b540aSrobert     {
226*404b540aSrobert       typedef _Value                                   value_type;
227*404b540aSrobert       typedef typename
228*404b540aSrobert       __gnu_cxx::__conditional_type<__constant_iterators,
229*404b540aSrobert 				    const _Value*, _Value*>::__type
230*404b540aSrobert                                                        pointer;
231*404b540aSrobert       typedef typename
232*404b540aSrobert       __gnu_cxx::__conditional_type<__constant_iterators,
233*404b540aSrobert 				    const _Value&, _Value&>::__type
234*404b540aSrobert                                                        reference;
235*404b540aSrobert       typedef std::ptrdiff_t                           difference_type;
236*404b540aSrobert       typedef std::forward_iterator_tag                iterator_category;
237*404b540aSrobert 
238*404b540aSrobert       _Node_iterator()
239*404b540aSrobert       : _Node_iterator_base<_Value, __cache>(0) { }
240*404b540aSrobert 
241*404b540aSrobert       explicit
242*404b540aSrobert       _Node_iterator(_Hash_node<_Value, __cache>* __p)
243*404b540aSrobert       : _Node_iterator_base<_Value, __cache>(__p) { }
244*404b540aSrobert 
245*404b540aSrobert       reference
246*404b540aSrobert       operator*() const
247*404b540aSrobert       { return this->_M_cur->_M_v; }
248*404b540aSrobert 
249*404b540aSrobert       pointer
250*404b540aSrobert       operator->() const
251*404b540aSrobert       { return &this->_M_cur->_M_v; }
252*404b540aSrobert 
253*404b540aSrobert       _Node_iterator&
254*404b540aSrobert       operator++()
255*404b540aSrobert       {
256*404b540aSrobert 	this->_M_incr();
257*404b540aSrobert 	return *this;
258*404b540aSrobert       }
259*404b540aSrobert 
260*404b540aSrobert       _Node_iterator
261*404b540aSrobert       operator++(int)
262*404b540aSrobert       {
263*404b540aSrobert 	_Node_iterator __tmp(*this);
264*404b540aSrobert 	this->_M_incr();
265*404b540aSrobert 	return __tmp;
266*404b540aSrobert       }
267*404b540aSrobert     };
268*404b540aSrobert 
269*404b540aSrobert   template<typename _Value, bool __constant_iterators, bool __cache>
270*404b540aSrobert     struct _Node_const_iterator
271*404b540aSrobert     : public _Node_iterator_base<_Value, __cache>
272*404b540aSrobert     {
273*404b540aSrobert       typedef _Value                                   value_type;
274*404b540aSrobert       typedef const _Value*                            pointer;
275*404b540aSrobert       typedef const _Value&                            reference;
276*404b540aSrobert       typedef std::ptrdiff_t                           difference_type;
277*404b540aSrobert       typedef std::forward_iterator_tag                iterator_category;
278*404b540aSrobert 
279*404b540aSrobert       _Node_const_iterator()
280*404b540aSrobert       : _Node_iterator_base<_Value, __cache>(0) { }
281*404b540aSrobert 
282*404b540aSrobert       explicit
283*404b540aSrobert       _Node_const_iterator(_Hash_node<_Value, __cache>* __p)
284*404b540aSrobert       : _Node_iterator_base<_Value, __cache>(__p) { }
285*404b540aSrobert 
286*404b540aSrobert       _Node_const_iterator(const _Node_iterator<_Value, __constant_iterators,
287*404b540aSrobert 			   __cache>& __x)
288*404b540aSrobert       : _Node_iterator_base<_Value, __cache>(__x._M_cur) { }
289*404b540aSrobert 
290*404b540aSrobert       reference
291*404b540aSrobert       operator*() const
292*404b540aSrobert       { return this->_M_cur->_M_v; }
293*404b540aSrobert 
294*404b540aSrobert       pointer
295*404b540aSrobert       operator->() const
296*404b540aSrobert       { return &this->_M_cur->_M_v; }
297*404b540aSrobert 
298*404b540aSrobert       _Node_const_iterator&
299*404b540aSrobert       operator++()
300*404b540aSrobert       {
301*404b540aSrobert 	this->_M_incr();
302*404b540aSrobert 	return *this;
303*404b540aSrobert       }
304*404b540aSrobert 
305*404b540aSrobert       _Node_const_iterator
306*404b540aSrobert       operator++(int)
307*404b540aSrobert       {
308*404b540aSrobert 	_Node_const_iterator __tmp(*this);
309*404b540aSrobert 	this->_M_incr();
310*404b540aSrobert 	return __tmp;
311*404b540aSrobert       }
312*404b540aSrobert     };
313*404b540aSrobert 
314*404b540aSrobert   template<typename _Value, bool __cache>
315*404b540aSrobert     struct _Hashtable_iterator_base
316*404b540aSrobert     {
317*404b540aSrobert       _Hashtable_iterator_base(_Hash_node<_Value, __cache>* __node,
318*404b540aSrobert 			       _Hash_node<_Value, __cache>** __bucket)
319*404b540aSrobert       : _M_cur_node(__node), _M_cur_bucket(__bucket) { }
320*404b540aSrobert 
321*404b540aSrobert       void
322*404b540aSrobert       _M_incr()
323*404b540aSrobert       {
324*404b540aSrobert 	_M_cur_node = _M_cur_node->_M_next;
325*404b540aSrobert 	if (!_M_cur_node)
326*404b540aSrobert 	  _M_incr_bucket();
327*404b540aSrobert       }
328*404b540aSrobert 
329*404b540aSrobert       void
330*404b540aSrobert       _M_incr_bucket();
331*404b540aSrobert 
332*404b540aSrobert       _Hash_node<_Value, __cache>*   _M_cur_node;
333*404b540aSrobert       _Hash_node<_Value, __cache>**  _M_cur_bucket;
334*404b540aSrobert     };
335*404b540aSrobert 
336*404b540aSrobert   // Global iterators, used for arbitrary iteration within a hash
337*404b540aSrobert   // table.  Larger and more expensive than local iterators.
338*404b540aSrobert   template<typename _Value, bool __cache>
339*404b540aSrobert     void
340*404b540aSrobert     _Hashtable_iterator_base<_Value, __cache>::
341*404b540aSrobert     _M_incr_bucket()
342*404b540aSrobert     {
343*404b540aSrobert       ++_M_cur_bucket;
344*404b540aSrobert 
345*404b540aSrobert       // This loop requires the bucket array to have a non-null sentinel.
346*404b540aSrobert       while (!*_M_cur_bucket)
347*404b540aSrobert 	++_M_cur_bucket;
348*404b540aSrobert       _M_cur_node = *_M_cur_bucket;
349*404b540aSrobert     }
350*404b540aSrobert 
351*404b540aSrobert   template<typename _Value, bool __cache>
352*404b540aSrobert     inline bool
353*404b540aSrobert     operator==(const _Hashtable_iterator_base<_Value, __cache>& __x,
354*404b540aSrobert 	       const _Hashtable_iterator_base<_Value, __cache>& __y)
355*404b540aSrobert     { return __x._M_cur_node == __y._M_cur_node; }
356*404b540aSrobert 
357*404b540aSrobert   template<typename _Value, bool __cache>
358*404b540aSrobert     inline bool
359*404b540aSrobert     operator!=(const _Hashtable_iterator_base<_Value, __cache>& __x,
360*404b540aSrobert 	       const _Hashtable_iterator_base<_Value, __cache>& __y)
361*404b540aSrobert     { return __x._M_cur_node != __y._M_cur_node; }
362*404b540aSrobert 
363*404b540aSrobert   template<typename _Value, bool __constant_iterators, bool __cache>
364*404b540aSrobert     struct _Hashtable_iterator
365*404b540aSrobert     : public _Hashtable_iterator_base<_Value, __cache>
366*404b540aSrobert     {
367*404b540aSrobert       typedef _Value                                   value_type;
368*404b540aSrobert       typedef typename
369*404b540aSrobert       __gnu_cxx::__conditional_type<__constant_iterators,
370*404b540aSrobert 				    const _Value*, _Value*>::__type
371*404b540aSrobert                                                        pointer;
372*404b540aSrobert       typedef typename
373*404b540aSrobert       __gnu_cxx::__conditional_type<__constant_iterators,
374*404b540aSrobert 				    const _Value&, _Value&>::__type
375*404b540aSrobert                                                        reference;
376*404b540aSrobert       typedef std::ptrdiff_t                           difference_type;
377*404b540aSrobert       typedef std::forward_iterator_tag                iterator_category;
378*404b540aSrobert 
379*404b540aSrobert       _Hashtable_iterator()
380*404b540aSrobert       : _Hashtable_iterator_base<_Value, __cache>(0, 0) { }
381*404b540aSrobert 
382*404b540aSrobert       _Hashtable_iterator(_Hash_node<_Value, __cache>* __p,
383*404b540aSrobert 			  _Hash_node<_Value, __cache>** __b)
384*404b540aSrobert       : _Hashtable_iterator_base<_Value, __cache>(__p, __b) { }
385*404b540aSrobert 
386*404b540aSrobert       explicit
387*404b540aSrobert       _Hashtable_iterator(_Hash_node<_Value, __cache>** __b)
388*404b540aSrobert       : _Hashtable_iterator_base<_Value, __cache>(*__b, __b) { }
389*404b540aSrobert 
390*404b540aSrobert       reference
391*404b540aSrobert       operator*() const
392*404b540aSrobert       { return this->_M_cur_node->_M_v; }
393*404b540aSrobert 
394*404b540aSrobert       pointer
395*404b540aSrobert       operator->() const
396*404b540aSrobert       { return &this->_M_cur_node->_M_v; }
397*404b540aSrobert 
398*404b540aSrobert       _Hashtable_iterator&
399*404b540aSrobert       operator++()
400*404b540aSrobert       {
401*404b540aSrobert 	this->_M_incr();
402*404b540aSrobert 	return *this;
403*404b540aSrobert       }
404*404b540aSrobert 
405*404b540aSrobert       _Hashtable_iterator
406*404b540aSrobert       operator++(int)
407*404b540aSrobert       {
408*404b540aSrobert 	_Hashtable_iterator __tmp(*this);
409*404b540aSrobert 	this->_M_incr();
410*404b540aSrobert 	return __tmp;
411*404b540aSrobert       }
412*404b540aSrobert     };
413*404b540aSrobert 
414*404b540aSrobert   template<typename _Value, bool __constant_iterators, bool __cache>
415*404b540aSrobert     struct _Hashtable_const_iterator
416*404b540aSrobert     : public _Hashtable_iterator_base<_Value, __cache>
417*404b540aSrobert     {
418*404b540aSrobert       typedef _Value                                   value_type;
419*404b540aSrobert       typedef const _Value*                            pointer;
420*404b540aSrobert       typedef const _Value&                            reference;
421*404b540aSrobert       typedef std::ptrdiff_t                           difference_type;
422*404b540aSrobert       typedef std::forward_iterator_tag                iterator_category;
423*404b540aSrobert 
424*404b540aSrobert       _Hashtable_const_iterator()
425*404b540aSrobert       : _Hashtable_iterator_base<_Value, __cache>(0, 0) { }
426*404b540aSrobert 
427*404b540aSrobert       _Hashtable_const_iterator(_Hash_node<_Value, __cache>* __p,
428*404b540aSrobert 				_Hash_node<_Value, __cache>** __b)
429*404b540aSrobert       : _Hashtable_iterator_base<_Value, __cache>(__p, __b) { }
430*404b540aSrobert 
431*404b540aSrobert       explicit
432*404b540aSrobert       _Hashtable_const_iterator(_Hash_node<_Value, __cache>** __b)
433*404b540aSrobert       : _Hashtable_iterator_base<_Value, __cache>(*__b, __b) { }
434*404b540aSrobert 
435*404b540aSrobert       _Hashtable_const_iterator(const _Hashtable_iterator<_Value,
436*404b540aSrobert 				__constant_iterators, __cache>& __x)
437*404b540aSrobert       : _Hashtable_iterator_base<_Value, __cache>(__x._M_cur_node,
438*404b540aSrobert 						  __x._M_cur_bucket) { }
439*404b540aSrobert 
440*404b540aSrobert       reference
441*404b540aSrobert       operator*() const
442*404b540aSrobert       { return this->_M_cur_node->_M_v; }
443*404b540aSrobert 
444*404b540aSrobert       pointer
445*404b540aSrobert       operator->() const
446*404b540aSrobert       { return &this->_M_cur_node->_M_v; }
447*404b540aSrobert 
448*404b540aSrobert       _Hashtable_const_iterator&
449*404b540aSrobert       operator++()
450*404b540aSrobert       {
451*404b540aSrobert 	this->_M_incr();
452*404b540aSrobert 	return *this;
453*404b540aSrobert       }
454*404b540aSrobert 
455*404b540aSrobert       _Hashtable_const_iterator
456*404b540aSrobert       operator++(int)
457*404b540aSrobert       {
458*404b540aSrobert 	_Hashtable_const_iterator __tmp(*this);
459*404b540aSrobert 	this->_M_incr();
460*404b540aSrobert 	return __tmp;
461*404b540aSrobert       }
462*404b540aSrobert     };
463*404b540aSrobert 
464*404b540aSrobert 
465*404b540aSrobert   // Many of class template _Hashtable's template parameters are policy
466*404b540aSrobert   // classes.  These are defaults for the policies.
467*404b540aSrobert 
468*404b540aSrobert   // Default range hashing function: use division to fold a large number
469*404b540aSrobert   // into the range [0, N).
470*404b540aSrobert   struct _Mod_range_hashing
471*404b540aSrobert   {
472*404b540aSrobert     typedef std::size_t first_argument_type;
473*404b540aSrobert     typedef std::size_t second_argument_type;
474*404b540aSrobert     typedef std::size_t result_type;
475*404b540aSrobert 
476*404b540aSrobert     result_type
477*404b540aSrobert     operator()(first_argument_type __num, second_argument_type __den) const
478*404b540aSrobert     { return __num % __den; }
479*404b540aSrobert   };
480*404b540aSrobert 
481*404b540aSrobert   // Default ranged hash function H.  In principle it should be a
482*404b540aSrobert   // function object composed from objects of type H1 and H2 such that
483*404b540aSrobert   // h(k, N) = h2(h1(k), N), but that would mean making extra copies of
484*404b540aSrobert   // h1 and h2.  So instead we'll just use a tag to tell class template
485*404b540aSrobert   // hashtable to do that composition.
486*404b540aSrobert   struct _Default_ranged_hash { };
487*404b540aSrobert 
488*404b540aSrobert   // Default value for rehash policy.  Bucket size is (usually) the
489*404b540aSrobert   // smallest prime that keeps the load factor small enough.
490*404b540aSrobert   struct _Prime_rehash_policy
491*404b540aSrobert   {
492*404b540aSrobert     _Prime_rehash_policy(float __z = 1.0);
493*404b540aSrobert 
494*404b540aSrobert     float
495*404b540aSrobert     max_load_factor() const;
496*404b540aSrobert 
497*404b540aSrobert     // Return a bucket size no smaller than n.
498*404b540aSrobert     std::size_t
499*404b540aSrobert     _M_next_bkt(std::size_t __n) const;
500*404b540aSrobert 
501*404b540aSrobert     // Return a bucket count appropriate for n elements
502*404b540aSrobert     std::size_t
503*404b540aSrobert     _M_bkt_for_elements(std::size_t __n) const;
504*404b540aSrobert 
505*404b540aSrobert     // __n_bkt is current bucket count, __n_elt is current element count,
506*404b540aSrobert     // and __n_ins is number of elements to be inserted.  Do we need to
507*404b540aSrobert     // increase bucket count?  If so, return make_pair(true, n), where n
508*404b540aSrobert     // is the new bucket count.  If not, return make_pair(false, 0).
509*404b540aSrobert     std::pair<bool, std::size_t>
510*404b540aSrobert     _M_need_rehash(std::size_t __n_bkt, std::size_t __n_elt,
511*404b540aSrobert 		   std::size_t __n_ins) const;
512*404b540aSrobert 
513*404b540aSrobert     float                _M_max_load_factor;
514*404b540aSrobert     float                _M_growth_factor;
515*404b540aSrobert     mutable std::size_t  _M_next_resize;
516*404b540aSrobert   };
517*404b540aSrobert 
518*404b540aSrobert   inline
519*404b540aSrobert   _Prime_rehash_policy::
520*404b540aSrobert   _Prime_rehash_policy(float __z)
521*404b540aSrobert   : _M_max_load_factor(__z), _M_growth_factor(2.f), _M_next_resize(0)
522*404b540aSrobert   { }
523*404b540aSrobert 
524*404b540aSrobert   inline float
525*404b540aSrobert   _Prime_rehash_policy::
526*404b540aSrobert   max_load_factor() const
527*404b540aSrobert   { return _M_max_load_factor; }
528*404b540aSrobert 
529*404b540aSrobert   // Return a prime no smaller than n.
530*404b540aSrobert   inline std::size_t
531*404b540aSrobert   _Prime_rehash_policy::
532*404b540aSrobert   _M_next_bkt(std::size_t __n) const
533*404b540aSrobert   {
534*404b540aSrobert     const unsigned long* const __last = (_Primes<>::__primes
535*404b540aSrobert 					 + _Primes<>::__n_primes);
536*404b540aSrobert     const unsigned long* __p = std::lower_bound(_Primes<>::__primes, __last,
537*404b540aSrobert 						__n);
538*404b540aSrobert     _M_next_resize = static_cast<std::size_t>(std::ceil(*__p
539*404b540aSrobert 							* _M_max_load_factor));
540*404b540aSrobert     return *__p;
541*404b540aSrobert   }
542*404b540aSrobert 
543*404b540aSrobert   // Return the smallest prime p such that alpha p >= n, where alpha
544*404b540aSrobert   // is the load factor.
545*404b540aSrobert   inline std::size_t
546*404b540aSrobert   _Prime_rehash_policy::
547*404b540aSrobert   _M_bkt_for_elements(std::size_t __n) const
548*404b540aSrobert   {
549*404b540aSrobert     const unsigned long* const __last = (_Primes<>::__primes
550*404b540aSrobert 					 + _Primes<>::__n_primes);
551*404b540aSrobert     const float __min_bkts = __n / _M_max_load_factor;
552*404b540aSrobert     const unsigned long* __p = std::lower_bound(_Primes<>::__primes, __last,
553*404b540aSrobert 						__min_bkts, _LessThan());
554*404b540aSrobert     _M_next_resize = static_cast<std::size_t>(std::ceil(*__p
555*404b540aSrobert 							* _M_max_load_factor));
556*404b540aSrobert     return *__p;
557*404b540aSrobert   }
558*404b540aSrobert 
559*404b540aSrobert   // Finds the smallest prime p such that alpha p > __n_elt + __n_ins.
560*404b540aSrobert   // If p > __n_bkt, return make_pair(true, p); otherwise return
561*404b540aSrobert   // make_pair(false, 0).  In principle this isn't very different from
562*404b540aSrobert   // _M_bkt_for_elements.
563*404b540aSrobert 
564*404b540aSrobert   // The only tricky part is that we're caching the element count at
565*404b540aSrobert   // which we need to rehash, so we don't have to do a floating-point
566*404b540aSrobert   // multiply for every insertion.
567*404b540aSrobert 
568*404b540aSrobert   inline std::pair<bool, std::size_t>
569*404b540aSrobert   _Prime_rehash_policy::
570*404b540aSrobert   _M_need_rehash(std::size_t __n_bkt, std::size_t __n_elt,
571*404b540aSrobert 		 std::size_t __n_ins) const
572*404b540aSrobert   {
573*404b540aSrobert     if (__n_elt + __n_ins > _M_next_resize)
574*404b540aSrobert       {
575*404b540aSrobert 	float __min_bkts = ((float(__n_ins) + float(__n_elt))
576*404b540aSrobert 			    / _M_max_load_factor);
577*404b540aSrobert 	if (__min_bkts > __n_bkt)
578*404b540aSrobert 	  {
579*404b540aSrobert 	    __min_bkts = std::max(__min_bkts, _M_growth_factor * __n_bkt);
580*404b540aSrobert 	    const unsigned long* const __last = (_Primes<>::__primes
581*404b540aSrobert 						 + _Primes<>::__n_primes);
582*404b540aSrobert 	    const unsigned long* __p = std::lower_bound(_Primes<>::__primes,
583*404b540aSrobert 							__last, __min_bkts,
584*404b540aSrobert 							_LessThan());
585*404b540aSrobert 	    _M_next_resize =
586*404b540aSrobert 	      static_cast<std::size_t>(std::ceil(*__p * _M_max_load_factor));
587*404b540aSrobert 	    return std::make_pair(true, *__p);
588*404b540aSrobert 	  }
589*404b540aSrobert 	else
590*404b540aSrobert 	  {
591*404b540aSrobert 	    _M_next_resize =
592*404b540aSrobert 	      static_cast<std::size_t>(std::ceil(__n_bkt
593*404b540aSrobert 						 * _M_max_load_factor));
594*404b540aSrobert 	    return std::make_pair(false, 0);
595*404b540aSrobert 	  }
596*404b540aSrobert       }
597*404b540aSrobert     else
598*404b540aSrobert       return std::make_pair(false, 0);
599*404b540aSrobert   }
600*404b540aSrobert 
601*404b540aSrobert   // Base classes for std::tr1::_Hashtable.  We define these base
602*404b540aSrobert   // classes because in some cases we want to do different things
603*404b540aSrobert   // depending on the value of a policy class.  In some cases the
604*404b540aSrobert   // policy class affects which member functions and nested typedefs
605*404b540aSrobert   // are defined; we handle that by specializing base class templates.
606*404b540aSrobert   // Several of the base class templates need to access other members
607*404b540aSrobert   // of class template _Hashtable, so we use the "curiously recurring
608*404b540aSrobert   // template pattern" for them.
609*404b540aSrobert 
610*404b540aSrobert   // class template _Map_base.  If the hashtable has a value type of the
611*404b540aSrobert   // form pair<T1, T2> and a key extraction policy that returns the
612*404b540aSrobert   // first part of the pair, the hashtable gets a mapped_type typedef.
613*404b540aSrobert   // If it satisfies those criteria and also has unique keys, then it
614*404b540aSrobert   // also gets an operator[].
615*404b540aSrobert   template<typename _Key, typename _Value, typename _Ex, bool __unique,
616*404b540aSrobert 	   typename _Hashtable>
617*404b540aSrobert     struct _Map_base { };
618*404b540aSrobert 
619*404b540aSrobert   template<typename _Key, typename _Pair, typename _Hashtable>
620*404b540aSrobert     struct _Map_base<_Key, _Pair, std::_Select1st<_Pair>, false, _Hashtable>
621*404b540aSrobert     {
622*404b540aSrobert       typedef typename _Pair::second_type mapped_type;
623*404b540aSrobert     };
624*404b540aSrobert 
625*404b540aSrobert   template<typename _Key, typename _Pair, typename _Hashtable>
626*404b540aSrobert   struct _Map_base<_Key, _Pair, std::_Select1st<_Pair>, true, _Hashtable>
627*404b540aSrobert     {
628*404b540aSrobert       typedef typename _Pair::second_type mapped_type;
629*404b540aSrobert 
630*404b540aSrobert       mapped_type&
631*404b540aSrobert       operator[](const _Key& __k);
632*404b540aSrobert     };
633*404b540aSrobert 
634*404b540aSrobert   template<typename _Key, typename _Pair, typename _Hashtable>
635*404b540aSrobert     typename _Map_base<_Key, _Pair, std::_Select1st<_Pair>,
636*404b540aSrobert 		       true, _Hashtable>::mapped_type&
637*404b540aSrobert     _Map_base<_Key, _Pair, std::_Select1st<_Pair>, true, _Hashtable>::
638*404b540aSrobert     operator[](const _Key& __k)
639*404b540aSrobert     {
640*404b540aSrobert       _Hashtable* __h = static_cast<_Hashtable*>(this);
641*404b540aSrobert       typename _Hashtable::_Hash_code_type __code = __h->_M_hash_code(__k);
642*404b540aSrobert       std::size_t __n = __h->_M_bucket_index(__k, __code,
643*404b540aSrobert 					     __h->_M_bucket_count);
644*404b540aSrobert 
645*404b540aSrobert       typename _Hashtable::_Node* __p =
646*404b540aSrobert 	__h->_M_find_node(__h->_M_buckets[__n], __k, __code);
647*404b540aSrobert       if (!__p)
648*404b540aSrobert 	return __h->_M_insert_bucket(std::make_pair(__k, mapped_type()),
649*404b540aSrobert 				     __n, __code)->second;
650*404b540aSrobert       return (__p->_M_v).second;
651*404b540aSrobert     }
652*404b540aSrobert 
653*404b540aSrobert   // class template _Rehash_base.  Give hashtable the max_load_factor
654*404b540aSrobert   // functions iff the rehash policy is _Prime_rehash_policy.
655*404b540aSrobert   template<typename _RehashPolicy, typename _Hashtable>
656*404b540aSrobert     struct _Rehash_base { };
657*404b540aSrobert 
658*404b540aSrobert   template<typename _Hashtable>
659*404b540aSrobert     struct _Rehash_base<_Prime_rehash_policy, _Hashtable>
660*404b540aSrobert     {
661*404b540aSrobert       float
662*404b540aSrobert       max_load_factor() const
663*404b540aSrobert       {
664*404b540aSrobert 	const _Hashtable* __this = static_cast<const _Hashtable*>(this);
665*404b540aSrobert 	return __this->__rehash_policy().max_load_factor();
666*404b540aSrobert       }
667*404b540aSrobert 
668*404b540aSrobert       void
669*404b540aSrobert       max_load_factor(float __z)
670*404b540aSrobert       {
671*404b540aSrobert 	_Hashtable* __this = static_cast<_Hashtable*>(this);
672*404b540aSrobert 	__this->__rehash_policy(_Prime_rehash_policy(__z));
673*404b540aSrobert       }
674*404b540aSrobert     };
675*404b540aSrobert 
676*404b540aSrobert   // Class template _Hash_code_base.  Encapsulates two policy issues that
677*404b540aSrobert   // aren't quite orthogonal.
678*404b540aSrobert   //   (1) the difference between using a ranged hash function and using
679*404b540aSrobert   //       the combination of a hash function and a range-hashing function.
680*404b540aSrobert   //       In the former case we don't have such things as hash codes, so
681*404b540aSrobert   //       we have a dummy type as placeholder.
682*404b540aSrobert   //   (2) Whether or not we cache hash codes.  Caching hash codes is
683*404b540aSrobert   //       meaningless if we have a ranged hash function.
684*404b540aSrobert   // We also put the key extraction and equality comparison function
685*404b540aSrobert   // objects here, for convenience.
686*404b540aSrobert 
687*404b540aSrobert   // Primary template: unused except as a hook for specializations.
688*404b540aSrobert   template<typename _Key, typename _Value,
689*404b540aSrobert 	   typename _ExtractKey, typename _Equal,
690*404b540aSrobert 	   typename _H1, typename _H2, typename _Hash,
691*404b540aSrobert 	   bool __cache_hash_code>
692*404b540aSrobert     struct _Hash_code_base;
693*404b540aSrobert 
694*404b540aSrobert   // Specialization: ranged hash function, no caching hash codes.  H1
695*404b540aSrobert   // and H2 are provided but ignored.  We define a dummy hash code type.
696*404b540aSrobert   template<typename _Key, typename _Value,
697*404b540aSrobert 	   typename _ExtractKey, typename _Equal,
698*404b540aSrobert 	   typename _H1, typename _H2, typename _Hash>
699*404b540aSrobert     struct _Hash_code_base<_Key, _Value, _ExtractKey, _Equal, _H1, _H2,
700*404b540aSrobert 			   _Hash, false>
701*404b540aSrobert     {
702*404b540aSrobert     protected:
703*404b540aSrobert       _Hash_code_base(const _ExtractKey& __ex, const _Equal& __eq,
704*404b540aSrobert 		      const _H1&, const _H2&, const _Hash& __h)
705*404b540aSrobert       : _M_extract(__ex), _M_eq(__eq), _M_ranged_hash(__h) { }
706*404b540aSrobert 
707*404b540aSrobert       typedef void* _Hash_code_type;
708*404b540aSrobert 
709*404b540aSrobert       _Hash_code_type
710*404b540aSrobert       _M_hash_code(const _Key& __key) const
711*404b540aSrobert       { return 0; }
712*404b540aSrobert 
713*404b540aSrobert       std::size_t
714*404b540aSrobert       _M_bucket_index(const _Key& __k, _Hash_code_type,
715*404b540aSrobert 		      std::size_t __n) const
716*404b540aSrobert       { return _M_ranged_hash(__k, __n); }
717*404b540aSrobert 
718*404b540aSrobert       std::size_t
719*404b540aSrobert       _M_bucket_index(const _Hash_node<_Value, false>* __p,
720*404b540aSrobert 		      std::size_t __n) const
721*404b540aSrobert       { return _M_ranged_hash(_M_extract(__p->_M_v), __n); }
722*404b540aSrobert 
723*404b540aSrobert       bool
724*404b540aSrobert       _M_compare(const _Key& __k, _Hash_code_type,
725*404b540aSrobert 		 _Hash_node<_Value, false>* __n) const
726*404b540aSrobert       { return _M_eq(__k, _M_extract(__n->_M_v)); }
727*404b540aSrobert 
728*404b540aSrobert       void
729*404b540aSrobert       _M_store_code(_Hash_node<_Value, false>*, _Hash_code_type) const
730*404b540aSrobert       { }
731*404b540aSrobert 
732*404b540aSrobert       void
733*404b540aSrobert       _M_copy_code(_Hash_node<_Value, false>*,
734*404b540aSrobert 		   const _Hash_node<_Value, false>*) const
735*404b540aSrobert       { }
736*404b540aSrobert 
737*404b540aSrobert       void
738*404b540aSrobert       _M_swap(_Hash_code_base& __x)
739*404b540aSrobert       {
740*404b540aSrobert 	std::swap(_M_extract, __x._M_extract);
741*404b540aSrobert 	std::swap(_M_eq, __x._M_eq);
742*404b540aSrobert 	std::swap(_M_ranged_hash, __x._M_ranged_hash);
743*404b540aSrobert       }
744*404b540aSrobert 
745*404b540aSrobert     protected:
746*404b540aSrobert       _ExtractKey  _M_extract;
747*404b540aSrobert       _Equal       _M_eq;
748*404b540aSrobert       _Hash        _M_ranged_hash;
749*404b540aSrobert     };
750*404b540aSrobert 
751*404b540aSrobert 
752*404b540aSrobert   // No specialization for ranged hash function while caching hash codes.
753*404b540aSrobert   // That combination is meaningless, and trying to do it is an error.
754*404b540aSrobert 
755*404b540aSrobert 
756*404b540aSrobert   // Specialization: ranged hash function, cache hash codes.  This
757*404b540aSrobert   // combination is meaningless, so we provide only a declaration
758*404b540aSrobert   // and no definition.
759*404b540aSrobert   template<typename _Key, typename _Value,
760*404b540aSrobert 	   typename _ExtractKey, typename _Equal,
761*404b540aSrobert 	   typename _H1, typename _H2, typename _Hash>
762*404b540aSrobert     struct _Hash_code_base<_Key, _Value, _ExtractKey, _Equal, _H1, _H2,
763*404b540aSrobert 			   _Hash, true>;
764*404b540aSrobert 
765*404b540aSrobert   // Specialization: hash function and range-hashing function, no
766*404b540aSrobert   // caching of hash codes.  H is provided but ignored.  Provides
767*404b540aSrobert   // typedef and accessor required by TR1.
768*404b540aSrobert   template<typename _Key, typename _Value,
769*404b540aSrobert 	   typename _ExtractKey, typename _Equal,
770*404b540aSrobert 	   typename _H1, typename _H2>
771*404b540aSrobert     struct _Hash_code_base<_Key, _Value, _ExtractKey, _Equal, _H1, _H2,
772*404b540aSrobert 			   _Default_ranged_hash, false>
773*404b540aSrobert     {
774*404b540aSrobert       typedef _H1 hasher;
775*404b540aSrobert 
776*404b540aSrobert       hasher
777*404b540aSrobert       hash_function() const
778*404b540aSrobert       { return _M_h1; }
779*404b540aSrobert 
780*404b540aSrobert     protected:
781*404b540aSrobert       _Hash_code_base(const _ExtractKey& __ex, const _Equal& __eq,
782*404b540aSrobert 		      const _H1& __h1, const _H2& __h2,
783*404b540aSrobert 		      const _Default_ranged_hash&)
784*404b540aSrobert       : _M_extract(__ex), _M_eq(__eq), _M_h1(__h1), _M_h2(__h2) { }
785*404b540aSrobert 
786*404b540aSrobert       typedef std::size_t _Hash_code_type;
787*404b540aSrobert 
788*404b540aSrobert       _Hash_code_type
789*404b540aSrobert       _M_hash_code(const _Key& __k) const
790*404b540aSrobert       { return _M_h1(__k); }
791*404b540aSrobert 
792*404b540aSrobert       std::size_t
793*404b540aSrobert       _M_bucket_index(const _Key&, _Hash_code_type __c,
794*404b540aSrobert 		      std::size_t __n) const
795*404b540aSrobert       { return _M_h2(__c, __n); }
796*404b540aSrobert 
797*404b540aSrobert       std::size_t
798*404b540aSrobert       _M_bucket_index(const _Hash_node<_Value, false>* __p,
799*404b540aSrobert 		      std::size_t __n) const
800*404b540aSrobert       { return _M_h2(_M_h1(_M_extract(__p->_M_v)), __n); }
801*404b540aSrobert 
802*404b540aSrobert       bool
803*404b540aSrobert       _M_compare(const _Key& __k, _Hash_code_type,
804*404b540aSrobert 		 _Hash_node<_Value, false>* __n) const
805*404b540aSrobert       { return _M_eq(__k, _M_extract(__n->_M_v)); }
806*404b540aSrobert 
807*404b540aSrobert       void
808*404b540aSrobert       _M_store_code(_Hash_node<_Value, false>*, _Hash_code_type) const
809*404b540aSrobert       { }
810*404b540aSrobert 
811*404b540aSrobert       void
812*404b540aSrobert       _M_copy_code(_Hash_node<_Value, false>*,
813*404b540aSrobert 		   const _Hash_node<_Value, false>*) const
814*404b540aSrobert       { }
815*404b540aSrobert 
816*404b540aSrobert       void
817*404b540aSrobert       _M_swap(_Hash_code_base& __x)
818*404b540aSrobert       {
819*404b540aSrobert 	std::swap(_M_extract, __x._M_extract);
820*404b540aSrobert 	std::swap(_M_eq, __x._M_eq);
821*404b540aSrobert 	std::swap(_M_h1, __x._M_h1);
822*404b540aSrobert 	std::swap(_M_h2, __x._M_h2);
823*404b540aSrobert       }
824*404b540aSrobert 
825*404b540aSrobert     protected:
826*404b540aSrobert       _ExtractKey  _M_extract;
827*404b540aSrobert       _Equal       _M_eq;
828*404b540aSrobert       _H1          _M_h1;
829*404b540aSrobert       _H2          _M_h2;
830*404b540aSrobert     };
831*404b540aSrobert 
832*404b540aSrobert   // Specialization: hash function and range-hashing function,
833*404b540aSrobert   // caching hash codes.  H is provided but ignored.  Provides
834*404b540aSrobert   // typedef and accessor required by TR1.
835*404b540aSrobert   template<typename _Key, typename _Value,
836*404b540aSrobert 	   typename _ExtractKey, typename _Equal,
837*404b540aSrobert 	   typename _H1, typename _H2>
838*404b540aSrobert     struct _Hash_code_base<_Key, _Value, _ExtractKey, _Equal, _H1, _H2,
839*404b540aSrobert 			   _Default_ranged_hash, true>
840*404b540aSrobert     {
841*404b540aSrobert       typedef _H1 hasher;
842*404b540aSrobert 
843*404b540aSrobert       hasher
844*404b540aSrobert       hash_function() const
845*404b540aSrobert       { return _M_h1; }
846*404b540aSrobert 
847*404b540aSrobert     protected:
848*404b540aSrobert       _Hash_code_base(const _ExtractKey& __ex, const _Equal& __eq,
849*404b540aSrobert 		      const _H1& __h1, const _H2& __h2,
850*404b540aSrobert 		      const _Default_ranged_hash&)
851*404b540aSrobert       : _M_extract(__ex), _M_eq(__eq), _M_h1(__h1), _M_h2(__h2) { }
852*404b540aSrobert 
853*404b540aSrobert       typedef std::size_t _Hash_code_type;
854*404b540aSrobert 
855*404b540aSrobert       _Hash_code_type
856*404b540aSrobert       _M_hash_code(const _Key& __k) const
857*404b540aSrobert       { return _M_h1(__k); }
858*404b540aSrobert 
859*404b540aSrobert       std::size_t
860*404b540aSrobert       _M_bucket_index(const _Key&, _Hash_code_type __c,
861*404b540aSrobert 		      std::size_t __n) const
862*404b540aSrobert       { return _M_h2(__c, __n); }
863*404b540aSrobert 
864*404b540aSrobert       std::size_t
865*404b540aSrobert       _M_bucket_index(const _Hash_node<_Value, true>* __p,
866*404b540aSrobert 		      std::size_t __n) const
867*404b540aSrobert       { return _M_h2(__p->_M_hash_code, __n); }
868*404b540aSrobert 
869*404b540aSrobert       bool
870*404b540aSrobert       _M_compare(const _Key& __k, _Hash_code_type __c,
871*404b540aSrobert 		 _Hash_node<_Value, true>* __n) const
872*404b540aSrobert       { return __c == __n->_M_hash_code && _M_eq(__k, _M_extract(__n->_M_v)); }
873*404b540aSrobert 
874*404b540aSrobert       void
875*404b540aSrobert       _M_store_code(_Hash_node<_Value, true>* __n, _Hash_code_type __c) const
876*404b540aSrobert       { __n->_M_hash_code = __c; }
877*404b540aSrobert 
878*404b540aSrobert       void
879*404b540aSrobert       _M_copy_code(_Hash_node<_Value, true>* __to,
880*404b540aSrobert 		   const _Hash_node<_Value, true>* __from) const
881*404b540aSrobert       { __to->_M_hash_code = __from->_M_hash_code; }
882*404b540aSrobert 
883*404b540aSrobert       void
884*404b540aSrobert       _M_swap(_Hash_code_base& __x)
885*404b540aSrobert       {
886*404b540aSrobert 	std::swap(_M_extract, __x._M_extract);
887*404b540aSrobert 	std::swap(_M_eq, __x._M_eq);
888*404b540aSrobert 	std::swap(_M_h1, __x._M_h1);
889*404b540aSrobert 	std::swap(_M_h2, __x._M_h2);
890*404b540aSrobert       }
891*404b540aSrobert 
892*404b540aSrobert     protected:
893*404b540aSrobert       _ExtractKey  _M_extract;
894*404b540aSrobert       _Equal       _M_eq;
895*404b540aSrobert       _H1          _M_h1;
896*404b540aSrobert       _H2          _M_h2;
897*404b540aSrobert     };
898*404b540aSrobert } // namespace __detail
899*404b540aSrobert _GLIBCXX_END_NAMESPACE
900*404b540aSrobert } // namespace std::tr1
901*404b540aSrobert 
902*404b540aSrobert #endif // _TR1_HASHTABLE_POLICY_H
903*404b540aSrobert 
904