xref: /openbsd-src/gnu/gcc/libstdc++-v3/include/ext/pb_ds/assoc_container.hpp (revision 404b540a9034ac75a6199ad1a32d1bbc7a0d4210)
1*404b540aSrobert // -*- 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 terms
7*404b540aSrobert // of the GNU General Public License as published by the Free Software
8*404b540aSrobert // Foundation; either version 2, or (at your option) any later
9*404b540aSrobert // version.
10*404b540aSrobert 
11*404b540aSrobert // This library is distributed in the hope that it will be useful, but
12*404b540aSrobert // WITHOUT ANY WARRANTY; without even the implied warranty of
13*404b540aSrobert // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14*404b540aSrobert // General Public License for more details.
15*404b540aSrobert 
16*404b540aSrobert // You should have received a copy of the GNU General Public License
17*404b540aSrobert // along with this library; see the file COPYING.  If not, write to
18*404b540aSrobert // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19*404b540aSrobert // MA 02111-1307, USA.
20*404b540aSrobert 
21*404b540aSrobert // As a special exception, you may use this file as part of a free
22*404b540aSrobert // software library without restriction.  Specifically, if other files
23*404b540aSrobert // instantiate templates or use macros or inline functions from this
24*404b540aSrobert // file, or you compile this file and link it with other files to
25*404b540aSrobert // produce an executable, this file does not by itself cause the
26*404b540aSrobert // resulting executable to be covered by the GNU General Public
27*404b540aSrobert // License.  This exception does not however invalidate any other
28*404b540aSrobert // reasons why the executable file might be covered by the GNU General
29*404b540aSrobert // Public License.
30*404b540aSrobert 
31*404b540aSrobert // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
32*404b540aSrobert 
33*404b540aSrobert // Permission to use, copy, modify, sell, and distribute this software
34*404b540aSrobert // is hereby granted without fee, provided that the above copyright
35*404b540aSrobert // notice appears in all copies, and that both that copyright notice
36*404b540aSrobert // and this permission notice appear in supporting documentation. None
37*404b540aSrobert // of the above authors, nor IBM Haifa Research Laboratories, make any
38*404b540aSrobert // representation about the suitability of this software for any
39*404b540aSrobert // purpose. It is provided "as is" without express or implied
40*404b540aSrobert // warranty.
41*404b540aSrobert 
42*404b540aSrobert /**
43*404b540aSrobert  * @file assoc_container.hpp
44*404b540aSrobert  * Contains associative containers.
45*404b540aSrobert  */
46*404b540aSrobert 
47*404b540aSrobert #ifndef PB_DS_ASSOC_CNTNR_HPP
48*404b540aSrobert #define PB_DS_ASSOC_CNTNR_HPP
49*404b540aSrobert 
50*404b540aSrobert #include <ext/typelist.h>
51*404b540aSrobert #include <ext/pb_ds/tag_and_trait.hpp>
52*404b540aSrobert #include <ext/pb_ds/detail/standard_policies.hpp>
53*404b540aSrobert #include <ext/pb_ds/detail/container_base_dispatch.hpp>
54*404b540aSrobert #include <ext/pb_ds/detail/basic_tree_policy/traits.hpp>
55*404b540aSrobert 
56*404b540aSrobert namespace pb_ds
57*404b540aSrobert {
58*404b540aSrobert #define PB_DS_BASE_C_DEC \
59*404b540aSrobert   detail::container_base_dispatch<Key, Mapped, Tag, Policy_Tl, Allocator>::type
60*404b540aSrobert 
61*404b540aSrobert   // An abstract basic associative container.
62*404b540aSrobert   template<typename Key,
63*404b540aSrobert 	   typename Mapped,
64*404b540aSrobert 	   typename Tag,
65*404b540aSrobert 	   typename Policy_Tl,
66*404b540aSrobert 	   typename Allocator>
67*404b540aSrobert   class container_base : public PB_DS_BASE_C_DEC
68*404b540aSrobert   {
69*404b540aSrobert   private:
70*404b540aSrobert     typedef typename PB_DS_BASE_C_DEC 			base_type;
71*404b540aSrobert 
72*404b540aSrobert   public:
73*404b540aSrobert     typedef Tag 					container_category;
74*404b540aSrobert     typedef Allocator 					allocator;
75*404b540aSrobert     typedef typename allocator::size_type 		size_type;
76*404b540aSrobert     typedef typename allocator::difference_type 	difference_type;
77*404b540aSrobert 
78*404b540aSrobert     // key_type
79*404b540aSrobert     typedef typename allocator::template rebind<Key>::other::value_type key_type;
80*404b540aSrobert     typedef typename allocator::template rebind<key_type>::other key_rebind;
81*404b540aSrobert     typedef typename key_rebind::reference 		key_reference;
82*404b540aSrobert     typedef typename key_rebind::const_reference 	const_key_reference;
83*404b540aSrobert     typedef typename key_rebind::pointer 		key_pointer;
84*404b540aSrobert     typedef typename key_rebind::const_pointer 		const_key_pointer;
85*404b540aSrobert 
86*404b540aSrobert     // mapped_type
87*404b540aSrobert     typedef Mapped 					mapped_type;
88*404b540aSrobert     typedef typename allocator::template rebind<mapped_type>::other mapped_rebind;
89*404b540aSrobert     typedef typename mapped_rebind::reference 		mapped_reference;
90*404b540aSrobert     typedef typename mapped_rebind::const_reference	const_mapped_reference;
91*404b540aSrobert     typedef typename mapped_rebind::pointer 		mapped_pointer;
92*404b540aSrobert     typedef typename mapped_rebind::const_pointer 	const_mapped_pointer;
93*404b540aSrobert 
94*404b540aSrobert     // value_type
95*404b540aSrobert     typedef typename base_type::value_type 		value_type;
96*404b540aSrobert     typedef typename allocator::template rebind<value_type>::other value_rebind;
97*404b540aSrobert     typedef typename value_rebind::reference		reference;
98*404b540aSrobert     typedef typename value_rebind::const_reference 	const_reference;
99*404b540aSrobert     typedef typename value_rebind::pointer 		pointer;
100*404b540aSrobert     typedef typename value_rebind::const_pointer 	const_pointer;
101*404b540aSrobert 
102*404b540aSrobert     // iterators
103*404b540aSrobert     typedef typename base_type::iterator 		iterator;
104*404b540aSrobert     typedef typename base_type::const_iterator 		const_iterator;
105*404b540aSrobert     typedef typename base_type::point_iterator 		point_iterator;
106*404b540aSrobert     typedef typename base_type::const_point_iterator 	const_point_iterator;
107*404b540aSrobert 
108*404b540aSrobert     virtual
~container_base()109*404b540aSrobert     ~container_base() { }
110*404b540aSrobert 
111*404b540aSrobert   protected:
112*404b540aSrobert #define PB_DS_CLASS_NAME 		container_base
113*404b540aSrobert #include <ext/pb_ds/detail/constructors_destructor_fn_imps.hpp>
114*404b540aSrobert #undef PB_DS_CLASS_NAME
115*404b540aSrobert   };
116*404b540aSrobert 
117*404b540aSrobert #undef PB_DS_BASE_C_DEC
118*404b540aSrobert 
119*404b540aSrobert 
120*404b540aSrobert #define PB_DS_BASE_C_DEC \
121*404b540aSrobert   container_base<Key, Mapped, Tag, typename __gnu_cxx::typelist::append< \
122*404b540aSrobert   typename __gnu_cxx::typelist::create4<Hash_Fn, Eq_Fn, Resize_Policy, detail::integral_constant<int, Store_Hash> >::type, Policy_TL>::type, Allocator>
123*404b540aSrobert 
124*404b540aSrobert   // An abstract basic hash-based associative container.
125*404b540aSrobert   template<typename Key,
126*404b540aSrobert 	   typename Mapped,
127*404b540aSrobert 	   typename Hash_Fn,
128*404b540aSrobert 	   typename Eq_Fn,
129*404b540aSrobert 	   typename Resize_Policy,
130*404b540aSrobert 	   bool Store_Hash,
131*404b540aSrobert 	   typename Tag,
132*404b540aSrobert 	   typename Policy_TL,
133*404b540aSrobert 	   typename Allocator>
134*404b540aSrobert   class basic_hash_table : public PB_DS_BASE_C_DEC
135*404b540aSrobert   {
136*404b540aSrobert   private:
137*404b540aSrobert     typedef PB_DS_BASE_C_DEC base_type;
138*404b540aSrobert 
139*404b540aSrobert   public:
140*404b540aSrobert     virtual
~basic_hash_table()141*404b540aSrobert     ~basic_hash_table() { }
142*404b540aSrobert 
143*404b540aSrobert   protected:
144*404b540aSrobert #define PB_DS_CLASS_NAME basic_hash_table
145*404b540aSrobert #include <ext/pb_ds/detail/constructors_destructor_fn_imps.hpp>
146*404b540aSrobert #undef PB_DS_CLASS_NAME
147*404b540aSrobert 
148*404b540aSrobert   private:
149*404b540aSrobert     basic_hash_table&
150*404b540aSrobert     operator=(const base_type&);
151*404b540aSrobert   };
152*404b540aSrobert 
153*404b540aSrobert #undef PB_DS_BASE_C_DEC
154*404b540aSrobert 
155*404b540aSrobert 
156*404b540aSrobert #define PB_DS_BASE_C_DEC \
157*404b540aSrobert   basic_hash_table<Key, Mapped,	Hash_Fn, Eq_Fn, Resize_Policy, Store_Hash, \
158*404b540aSrobert 		   cc_hash_tag,	\
159*404b540aSrobert 	  typename __gnu_cxx::typelist::create1<Comb_Hash_Fn>::type, Allocator>
160*404b540aSrobert 
161*404b540aSrobert   // A concrete collision-chaining hash-based associative container.
162*404b540aSrobert   template<typename Key,
163*404b540aSrobert 	   typename Mapped,
164*404b540aSrobert 	   typename Hash_Fn = typename detail::default_hash_fn<Key>::type,
165*404b540aSrobert 	   typename Eq_Fn = typename detail::default_eq_fn<Key>::type,
166*404b540aSrobert 	   typename Comb_Hash_Fn = detail::default_comb_hash_fn::type,
167*404b540aSrobert 	   typename Resize_Policy = typename detail::default_resize_policy<Comb_Hash_Fn>::type,
168*404b540aSrobert 	   bool Store_Hash = detail::default_store_hash,
169*404b540aSrobert 	   typename Allocator = std::allocator<char> >
170*404b540aSrobert   class cc_hash_table :  public PB_DS_BASE_C_DEC
171*404b540aSrobert   {
172*404b540aSrobert   private:
173*404b540aSrobert     typedef PB_DS_BASE_C_DEC 	base_type;
174*404b540aSrobert 
175*404b540aSrobert   public:
176*404b540aSrobert     typedef Hash_Fn 		hash_fn;
177*404b540aSrobert     typedef Eq_Fn 		eq_fn;
178*404b540aSrobert     typedef Resize_Policy 	resize_policy;
179*404b540aSrobert     typedef Comb_Hash_Fn 	comb_hash_fn;
180*404b540aSrobert 
181*404b540aSrobert     // Default constructor.
cc_hash_table()182*404b540aSrobert     cc_hash_table() { }
183*404b540aSrobert 
184*404b540aSrobert     // Constructor taking some policy objects. r_hash_fn will be
185*404b540aSrobert     // copied by the Hash_Fn object of the container object.
cc_hash_table(const hash_fn & h)186*404b540aSrobert     cc_hash_table(const hash_fn& h)
187*404b540aSrobert     : base_type(h) { }
188*404b540aSrobert 
189*404b540aSrobert     // Constructor taking some policy objects. r_hash_fn will be
190*404b540aSrobert     // copied by the hash_fn object of the container object, and
191*404b540aSrobert     // r_eq_fn will be copied by the eq_fn object of the container
192*404b540aSrobert     // object.
cc_hash_table(const hash_fn & h,const eq_fn & e)193*404b540aSrobert     cc_hash_table(const hash_fn& h, const eq_fn& e)
194*404b540aSrobert     : base_type(h, e) { }
195*404b540aSrobert 
196*404b540aSrobert     // Constructor taking some policy objects. r_hash_fn will be
197*404b540aSrobert     // copied by the hash_fn object of the container object, r_eq_fn
198*404b540aSrobert     // will be copied by the eq_fn object of the container object, and
199*404b540aSrobert     // r_comb_hash_fn will be copied by the comb_hash_fn object of the
200*404b540aSrobert     // container object.
cc_hash_table(const hash_fn & h,const eq_fn & e,const comb_hash_fn & ch)201*404b540aSrobert     cc_hash_table(const hash_fn& h, const eq_fn& e, const comb_hash_fn& ch)
202*404b540aSrobert     : base_type(h, e, ch) { }
203*404b540aSrobert 
204*404b540aSrobert     // Constructor taking some policy objects. r_hash_fn will be
205*404b540aSrobert     // copied by the hash_fn object of the container object, r_eq_fn
206*404b540aSrobert     // will be copied by the eq_fn object of the container object,
207*404b540aSrobert     // r_comb_hash_fn will be copied by the comb_hash_fn object of the
208*404b540aSrobert     // container object, and r_resize_policy will be copied by the
209*404b540aSrobert     // resize_policy object of the container object.
cc_hash_table(const hash_fn & h,const eq_fn & e,const comb_hash_fn & ch,const resize_policy & rp)210*404b540aSrobert     cc_hash_table(const hash_fn& h, const eq_fn& e, const comb_hash_fn& ch,
211*404b540aSrobert 		  const resize_policy& rp)
212*404b540aSrobert     : base_type(h, e, ch, rp) { }
213*404b540aSrobert 
214*404b540aSrobert     // Constructor taking __iterators to a range of value_types. The
215*404b540aSrobert     // value_types between first_it and last_it will be inserted into
216*404b540aSrobert     // the container object.
217*404b540aSrobert     template<typename It>
cc_hash_table(It first,It last)218*404b540aSrobert     cc_hash_table(It first, It last)
219*404b540aSrobert     { base_type::copy_from_range(first, last); }
220*404b540aSrobert 
221*404b540aSrobert     // Constructor taking __iterators to a range of value_types and
222*404b540aSrobert     // some policy objects. The value_types between first_it and
223*404b540aSrobert     // last_it will be inserted into the container object.
224*404b540aSrobert     template<typename It>
cc_hash_table(It first,It last,const hash_fn & h)225*404b540aSrobert     cc_hash_table(It first, It last, const hash_fn& h)
226*404b540aSrobert     : base_type(h)
227*404b540aSrobert     { copy_from_range(first, last); }
228*404b540aSrobert 
229*404b540aSrobert     // Constructor taking __iterators to a range of value_types and
230*404b540aSrobert     // some policy objects The value_types between first_it and
231*404b540aSrobert     // last_it will be inserted into the container object. r_hash_fn
232*404b540aSrobert     // will be copied by the hash_fn object of the container object,
233*404b540aSrobert     // and r_eq_fn will be copied by the eq_fn object of the container
234*404b540aSrobert     // object.
235*404b540aSrobert     template<typename It>
cc_hash_table(It first,It last,const hash_fn & h,const eq_fn & e)236*404b540aSrobert     cc_hash_table(It first, It last, const hash_fn& h, const eq_fn& e)
237*404b540aSrobert     : base_type(h, e)
238*404b540aSrobert     { copy_from_range(first, last); }
239*404b540aSrobert 
240*404b540aSrobert     // Constructor taking __iterators to a range of value_types and
241*404b540aSrobert     // some policy objects The value_types between first_it and
242*404b540aSrobert     // last_it will be inserted into the container object. r_hash_fn
243*404b540aSrobert     // will be copied by the hash_fn object of the container object,
244*404b540aSrobert     // r_eq_fn will be copied by the eq_fn object of the container
245*404b540aSrobert     // object, and r_comb_hash_fn will be copied by the comb_hash_fn
246*404b540aSrobert     // object of the container object.
247*404b540aSrobert     template<typename It>
cc_hash_table(It first,It last,const hash_fn & h,const eq_fn & e,const comb_hash_fn & ch)248*404b540aSrobert     cc_hash_table(It first, It last, const hash_fn& h, const eq_fn& e,
249*404b540aSrobert 		  const comb_hash_fn& ch)
250*404b540aSrobert     : base_type(h, e, ch)
251*404b540aSrobert     { copy_from_range(first, last); }
252*404b540aSrobert 
253*404b540aSrobert     // Constructor taking __iterators to a range of value_types and
254*404b540aSrobert     // some policy objects The value_types between first_it and
255*404b540aSrobert     // last_it will be inserted into the container object. r_hash_fn
256*404b540aSrobert     // will be copied by the hash_fn object of the container object,
257*404b540aSrobert     // r_eq_fn will be copied by the eq_fn object of the container
258*404b540aSrobert     // object, r_comb_hash_fn will be copied by the comb_hash_fn
259*404b540aSrobert     // object of the container object, and r_resize_policy will be
260*404b540aSrobert     // copied by the resize_policy object of the container object.
261*404b540aSrobert     template<typename It>
cc_hash_table(It first,It last,const hash_fn & h,const eq_fn & e,const comb_hash_fn & ch,const resize_policy & rp)262*404b540aSrobert     cc_hash_table(It first, It last, const hash_fn& h, const eq_fn& e,
263*404b540aSrobert 		  const comb_hash_fn& ch, const resize_policy& rp)
264*404b540aSrobert     : base_type(h, e, ch, rp)
265*404b540aSrobert     { copy_from_range(first, last); }
266*404b540aSrobert 
cc_hash_table(const cc_hash_table & other)267*404b540aSrobert     cc_hash_table(const cc_hash_table& other)
268*404b540aSrobert     : base_type((const base_type&)other)
269*404b540aSrobert     { }
270*404b540aSrobert 
271*404b540aSrobert     virtual
~cc_hash_table()272*404b540aSrobert     ~cc_hash_table() { }
273*404b540aSrobert 
274*404b540aSrobert     cc_hash_table&
operator =(const cc_hash_table & other)275*404b540aSrobert     operator=(const cc_hash_table& other)
276*404b540aSrobert     {
277*404b540aSrobert       if (this != &other)
278*404b540aSrobert 	{
279*404b540aSrobert 	  cc_hash_table tmp(other);
280*404b540aSrobert 	  swap(tmp);
281*404b540aSrobert 	}
282*404b540aSrobert       return *this;
283*404b540aSrobert     }
284*404b540aSrobert 
285*404b540aSrobert     void
swap(cc_hash_table & other)286*404b540aSrobert     swap(cc_hash_table& other)
287*404b540aSrobert     { base_type::swap(other); }
288*404b540aSrobert   };
289*404b540aSrobert 
290*404b540aSrobert #undef PB_DS_BASE_C_DEC
291*404b540aSrobert 
292*404b540aSrobert 
293*404b540aSrobert #define PB_DS_BASE_C_DEC \
294*404b540aSrobert   basic_hash_table<Key, Mapped,	Hash_Fn, Eq_Fn, Resize_Policy, Store_Hash, \
295*404b540aSrobert 		   gp_hash_tag, \
296*404b540aSrobert 		   typename __gnu_cxx::typelist::create2<Comb_Probe_Fn, Probe_Fn>::type, Allocator>
297*404b540aSrobert 
298*404b540aSrobert   // A concrete general-probing hash-based associative container.
299*404b540aSrobert   template<typename Key,
300*404b540aSrobert 	   typename Mapped,
301*404b540aSrobert 	   typename Hash_Fn = typename detail::default_hash_fn<Key>::type,
302*404b540aSrobert 	   typename Eq_Fn = typename detail::default_eq_fn<Key>::type,
303*404b540aSrobert 	   typename Comb_Probe_Fn = detail::default_comb_hash_fn::type,
304*404b540aSrobert 	   typename Probe_Fn = typename detail::default_probe_fn<Comb_Probe_Fn>::type,
305*404b540aSrobert 	   typename Resize_Policy = typename detail::default_resize_policy<Comb_Probe_Fn>::type,
306*404b540aSrobert 	   bool Store_Hash = detail::default_store_hash,
307*404b540aSrobert 	   typename Allocator = std::allocator<char> >
308*404b540aSrobert   class gp_hash_table : public PB_DS_BASE_C_DEC
309*404b540aSrobert   {
310*404b540aSrobert   private:
311*404b540aSrobert     typedef PB_DS_BASE_C_DEC 	base_type;
312*404b540aSrobert 
313*404b540aSrobert   public:
314*404b540aSrobert     typedef Hash_Fn 		hash_fn;
315*404b540aSrobert     typedef Eq_Fn 		eq_fn;
316*404b540aSrobert     typedef Comb_Probe_Fn	comb_probe_fn;
317*404b540aSrobert     typedef Probe_Fn 		probe_fn;
318*404b540aSrobert     typedef Resize_Policy 	resize_policy;
319*404b540aSrobert 
320*404b540aSrobert     // Default constructor.
gp_hash_table()321*404b540aSrobert     gp_hash_table() { }
322*404b540aSrobert 
323*404b540aSrobert     // Constructor taking some policy objects. r_hash_fn will be
324*404b540aSrobert     // copied by the hash_fn object of the container object.
gp_hash_table(const hash_fn & h)325*404b540aSrobert     gp_hash_table(const hash_fn& h)
326*404b540aSrobert     : base_type(h) { }
327*404b540aSrobert 
328*404b540aSrobert     // Constructor taking some policy objects. r_hash_fn will be
329*404b540aSrobert     // copied by the hash_fn object of the container object, and
330*404b540aSrobert     // r_eq_fn will be copied by the eq_fn object of the container
331*404b540aSrobert     // object.
gp_hash_table(const hash_fn & h,const eq_fn & e)332*404b540aSrobert     gp_hash_table(const hash_fn& h, const eq_fn& e)
333*404b540aSrobert     : base_type(h, e) { }
334*404b540aSrobert 
335*404b540aSrobert     // Constructor taking some policy objects. r_hash_fn will be
336*404b540aSrobert     // copied by the hash_fn object of the container object, r_eq_fn
337*404b540aSrobert     // will be copied by the eq_fn object of the container object, and
338*404b540aSrobert     // r_comb_probe_fn will be copied by the comb_probe_fn object of
339*404b540aSrobert     // the container object.
gp_hash_table(const hash_fn & h,const eq_fn & e,const comb_probe_fn & cp)340*404b540aSrobert     gp_hash_table(const hash_fn& h, const eq_fn& e, const comb_probe_fn& cp)
341*404b540aSrobert     : base_type(h, e, cp) { }
342*404b540aSrobert 
343*404b540aSrobert     // Constructor taking some policy objects. r_hash_fn will be
344*404b540aSrobert     // copied by the hash_fn object of the container object, r_eq_fn
345*404b540aSrobert     // will be copied by the eq_fn object of the container object,
346*404b540aSrobert     // r_comb_probe_fn will be copied by the comb_probe_fn object of
347*404b540aSrobert     // the container object, and r_probe_fn will be copied by the
348*404b540aSrobert     // probe_fn object of the container object.
gp_hash_table(const hash_fn & h,const eq_fn & e,const comb_probe_fn & cp,const probe_fn & p)349*404b540aSrobert     gp_hash_table(const hash_fn& h, const eq_fn& e, const comb_probe_fn& cp,
350*404b540aSrobert 		  const probe_fn& p)
351*404b540aSrobert     : base_type(h, e, cp, p) { }
352*404b540aSrobert 
353*404b540aSrobert     // Constructor taking some policy objects. r_hash_fn will be
354*404b540aSrobert     // copied by the hash_fn object of the container object, r_eq_fn
355*404b540aSrobert     // will be copied by the eq_fn object of the container object,
356*404b540aSrobert     // r_comb_probe_fn will be copied by the comb_probe_fn object of
357*404b540aSrobert     // the container object, r_probe_fn will be copied by the probe_fn
358*404b540aSrobert     // object of the container object, and r_resize_policy will be
359*404b540aSrobert     // copied by the Resize_Policy object of the container object.
gp_hash_table(const hash_fn & h,const eq_fn & e,const comb_probe_fn & cp,const probe_fn & p,const resize_policy & rp)360*404b540aSrobert     gp_hash_table(const hash_fn& h, const eq_fn& e, const comb_probe_fn& cp,
361*404b540aSrobert 		  const probe_fn& p, const resize_policy& rp)
362*404b540aSrobert     : base_type(h, e, cp, p, rp) { }
363*404b540aSrobert 
364*404b540aSrobert     // Constructor taking __iterators to a range of value_types. The
365*404b540aSrobert     // value_types between first_it and last_it will be inserted into
366*404b540aSrobert     // the container object.
367*404b540aSrobert     template<typename It>
gp_hash_table(It first,It last)368*404b540aSrobert     gp_hash_table(It first, It last)
369*404b540aSrobert     { base_type::copy_from_range(first, last); }
370*404b540aSrobert 
371*404b540aSrobert     // Constructor taking __iterators to a range of value_types and
372*404b540aSrobert     // some policy objects. The value_types between first_it and
373*404b540aSrobert     // last_it will be inserted into the container object. r_hash_fn
374*404b540aSrobert     // will be copied by the hash_fn object of the container object.
375*404b540aSrobert     template<typename It>
gp_hash_table(It first,It last,const hash_fn & h)376*404b540aSrobert     gp_hash_table(It first, It last, const hash_fn& h)
377*404b540aSrobert     : base_type(h)
378*404b540aSrobert     { base_type::copy_from_range(first, last); }
379*404b540aSrobert 
380*404b540aSrobert     // Constructor taking __iterators to a range of value_types and
381*404b540aSrobert     // some policy objects. The value_types between first_it and
382*404b540aSrobert     // last_it will be inserted into the container object. r_hash_fn
383*404b540aSrobert     // will be copied by the hash_fn object of the container object,
384*404b540aSrobert     // and r_eq_fn will be copied by the eq_fn object of the container
385*404b540aSrobert     // object.
386*404b540aSrobert     template<typename It>
gp_hash_table(It first,It last,const hash_fn & h,const eq_fn & e)387*404b540aSrobert     gp_hash_table(It first, It last, const hash_fn& h, const eq_fn& e)
388*404b540aSrobert     : base_type(h, e)
389*404b540aSrobert     { base_type::copy_from_range(first, last); }
390*404b540aSrobert 
391*404b540aSrobert     // Constructor taking __iterators to a range of value_types and
392*404b540aSrobert     // some policy objects. The value_types between first_it and
393*404b540aSrobert     // last_it will be inserted into the container object. r_hash_fn
394*404b540aSrobert     // will be copied by the hash_fn object of the container object,
395*404b540aSrobert     // r_eq_fn will be copied by the eq_fn object of the container
396*404b540aSrobert     // object, and r_comb_probe_fn will be copied by the comb_probe_fn
397*404b540aSrobert     // object of the container object.
398*404b540aSrobert     template<typename It>
gp_hash_table(It first,It last,const hash_fn & h,const eq_fn & e,const comb_probe_fn & cp)399*404b540aSrobert     gp_hash_table(It first, It last, const hash_fn& h, const eq_fn& e,
400*404b540aSrobert 		  const comb_probe_fn& cp)
401*404b540aSrobert     : base_type(h, e, cp)
402*404b540aSrobert     { base_type::copy_from_range(first, last); }
403*404b540aSrobert 
404*404b540aSrobert     // Constructor taking __iterators to a range of value_types and
405*404b540aSrobert     // some policy objects. The value_types between first_it and
406*404b540aSrobert     // last_it will be inserted into the container object. r_hash_fn
407*404b540aSrobert     // will be copied by the hash_fn object of the container object,
408*404b540aSrobert     // r_eq_fn will be copied by the eq_fn object of the container
409*404b540aSrobert     // object, r_comb_probe_fn will be copied by the comb_probe_fn
410*404b540aSrobert     // object of the container object, and r_probe_fn will be copied
411*404b540aSrobert     // by the probe_fn object of the container object.
412*404b540aSrobert     template<typename It>
gp_hash_table(It first,It last,const hash_fn & h,const eq_fn & e,const comb_probe_fn & cp,const probe_fn & p)413*404b540aSrobert     gp_hash_table(It first, It last, const hash_fn& h, const eq_fn& e,
414*404b540aSrobert 		  const comb_probe_fn& cp, const probe_fn& p)
415*404b540aSrobert     : base_type(h, e, cp, p)
416*404b540aSrobert     { base_type::copy_from_range(first, last); }
417*404b540aSrobert 
418*404b540aSrobert     // Constructor taking __iterators to a range of value_types and
419*404b540aSrobert     // some policy objects. The value_types between first_it and
420*404b540aSrobert     // last_it will be inserted into the container object. r_hash_fn
421*404b540aSrobert     // will be copied by the hash_fn object of the container object,
422*404b540aSrobert     // r_eq_fn will be copied by the eq_fn object of the container
423*404b540aSrobert     // object, r_comb_probe_fn will be copied by the comb_probe_fn
424*404b540aSrobert     // object of the container object, r_probe_fn will be copied by
425*404b540aSrobert     // the probe_fn object of the container object, and
426*404b540aSrobert     // r_resize_policy will be copied by the resize_policy object of
427*404b540aSrobert     // the container object.
428*404b540aSrobert     template<typename It>
gp_hash_table(It first,It last,const hash_fn & h,const eq_fn & e,const comb_probe_fn & cp,const probe_fn & p,const resize_policy & rp)429*404b540aSrobert     gp_hash_table(It first, It last, const hash_fn& h, const eq_fn& e,
430*404b540aSrobert 		  const comb_probe_fn& cp, const probe_fn& p,
431*404b540aSrobert 		  const resize_policy& rp)
432*404b540aSrobert     : base_type(h, e, cp, p, rp)
433*404b540aSrobert     { base_type::copy_from_range(first, last); }
434*404b540aSrobert 
gp_hash_table(const gp_hash_table & other)435*404b540aSrobert     gp_hash_table(const gp_hash_table& other)
436*404b540aSrobert     : base_type((const base_type&)other)
437*404b540aSrobert     { }
438*404b540aSrobert 
439*404b540aSrobert     virtual
~gp_hash_table()440*404b540aSrobert     ~gp_hash_table() { }
441*404b540aSrobert 
442*404b540aSrobert     gp_hash_table&
operator =(const gp_hash_table & other)443*404b540aSrobert     operator=(const gp_hash_table& other)
444*404b540aSrobert     {
445*404b540aSrobert       if (this != &other)
446*404b540aSrobert 	{
447*404b540aSrobert 	  gp_hash_table tmp(other);
448*404b540aSrobert 	  swap(tmp);
449*404b540aSrobert 	}
450*404b540aSrobert       return *this;
451*404b540aSrobert     }
452*404b540aSrobert 
453*404b540aSrobert     void
swap(gp_hash_table & other)454*404b540aSrobert     swap(gp_hash_table& other)
455*404b540aSrobert     { base_type::swap(other); }
456*404b540aSrobert   };
457*404b540aSrobert 
458*404b540aSrobert #undef PB_DS_BASE_C_DEC
459*404b540aSrobert 
460*404b540aSrobert 
461*404b540aSrobert #define PB_DS_BASE_C_DEC \
462*404b540aSrobert   container_base<Key, Mapped, Tag, Policy_Tl, Allocator>
463*404b540aSrobert 
464*404b540aSrobert   // An abstract basic tree-like (tree, trie) associative container.
465*404b540aSrobert   template<typename Key, typename Mapped, typename Tag,
466*404b540aSrobert 	   typename Node_Update, typename Policy_Tl, typename Allocator>
467*404b540aSrobert   class basic_tree : public PB_DS_BASE_C_DEC
468*404b540aSrobert   {
469*404b540aSrobert   private:
470*404b540aSrobert     typedef PB_DS_BASE_C_DEC 	base_type;
471*404b540aSrobert 
472*404b540aSrobert   public:
473*404b540aSrobert     typedef Node_Update 	node_update;
474*404b540aSrobert 
475*404b540aSrobert     virtual
~basic_tree()476*404b540aSrobert     ~basic_tree() { }
477*404b540aSrobert 
478*404b540aSrobert   protected:
479*404b540aSrobert #define PB_DS_CLASS_NAME 		basic_tree
480*404b540aSrobert #include <ext/pb_ds/detail/constructors_destructor_fn_imps.hpp>
481*404b540aSrobert #undef PB_DS_CLASS_NAME
482*404b540aSrobert   };
483*404b540aSrobert 
484*404b540aSrobert #undef PB_DS_BASE_C_DEC
485*404b540aSrobert 
486*404b540aSrobert 
487*404b540aSrobert #define PB_DS_TREE_NODE_AND_IT_TRAITS_C_DEC \
488*404b540aSrobert   detail::tree_traits<Key, Mapped,Cmp_Fn,Node_Update,Tag, Allocator>
489*404b540aSrobert 
490*404b540aSrobert #define PB_DS_BASE_C_DEC \
491*404b540aSrobert   basic_tree<Key,Mapped,Tag,typename PB_DS_TREE_NODE_AND_IT_TRAITS_C_DEC::node_update, \
492*404b540aSrobert 	     typename __gnu_cxx::typelist::create2<Cmp_Fn, PB_DS_TREE_NODE_AND_IT_TRAITS_C_DEC >::type, Allocator>
493*404b540aSrobert 
494*404b540aSrobert   // A concrete basic tree-based associative container.
495*404b540aSrobert   template<typename Key, typename Mapped, typename Cmp_Fn = std::less<Key>,
496*404b540aSrobert 	   typename Tag = rb_tree_tag,
497*404b540aSrobert 	   template<typename Const_Node_Iterator, typename Node_Iterator, typename Cmp_Fn_, typename Allocator_>
498*404b540aSrobert   class Node_Update = pb_ds::null_tree_node_update,
499*404b540aSrobert 	   typename Allocator = std::allocator<char> >
500*404b540aSrobert   class tree : public PB_DS_BASE_C_DEC
501*404b540aSrobert   {
502*404b540aSrobert   private:
503*404b540aSrobert     typedef PB_DS_BASE_C_DEC 	base_type;
504*404b540aSrobert 
505*404b540aSrobert   public:
506*404b540aSrobert     // Comparison functor type.
507*404b540aSrobert     typedef Cmp_Fn 		cmp_fn;
508*404b540aSrobert 
tree()509*404b540aSrobert     tree() { }
510*404b540aSrobert 
511*404b540aSrobert     // Constructor taking some policy objects. r_cmp_fn will be copied
512*404b540aSrobert     // by the Cmp_Fn object of the container object.
tree(const cmp_fn & c)513*404b540aSrobert     tree(const cmp_fn& c)
514*404b540aSrobert     : base_type(c) { }
515*404b540aSrobert 
516*404b540aSrobert     // Constructor taking __iterators to a range of value_types. The
517*404b540aSrobert     // value_types between first_it and last_it will be inserted into
518*404b540aSrobert     // the container object.
519*404b540aSrobert     template<typename It>
tree(It first,It last)520*404b540aSrobert     tree(It first, It last)
521*404b540aSrobert     { base_type::copy_from_range(first, last); }
522*404b540aSrobert 
523*404b540aSrobert     // Constructor taking __iterators to a range of value_types and
524*404b540aSrobert     // some policy objects The value_types between first_it and
525*404b540aSrobert     // last_it will be inserted into the container object. r_cmp_fn
526*404b540aSrobert     // will be copied by the cmp_fn object of the container object.
527*404b540aSrobert     template<typename It>
tree(It first,It last,const cmp_fn & c)528*404b540aSrobert     tree(It first, It last, const cmp_fn& c)
529*404b540aSrobert       : base_type(c)
530*404b540aSrobert     { base_type::copy_from_range(first, last); }
531*404b540aSrobert 
tree(const tree & other)532*404b540aSrobert     tree(const tree& other)
533*404b540aSrobert     : base_type((const base_type&)other) { }
534*404b540aSrobert 
535*404b540aSrobert     virtual
~tree()536*404b540aSrobert     ~tree() { }
537*404b540aSrobert 
538*404b540aSrobert     tree&
operator =(const tree & other)539*404b540aSrobert     operator=(const tree& other)
540*404b540aSrobert     {
541*404b540aSrobert       if (this != &other)
542*404b540aSrobert 	{
543*404b540aSrobert 	  tree tmp(other);
544*404b540aSrobert 	  swap(tmp);
545*404b540aSrobert 	}
546*404b540aSrobert       return *this;
547*404b540aSrobert     }
548*404b540aSrobert 
549*404b540aSrobert     void
swap(tree & other)550*404b540aSrobert     swap(tree& other)
551*404b540aSrobert     { base_type::swap(other); }
552*404b540aSrobert   };
553*404b540aSrobert 
554*404b540aSrobert #undef PB_DS_BASE_C_DEC
555*404b540aSrobert #undef PB_DS_TREE_NODE_AND_IT_TRAITS_C_DEC
556*404b540aSrobert 
557*404b540aSrobert 
558*404b540aSrobert #define PB_DS_TRIE_NODE_AND_ITS_TRAITS \
559*404b540aSrobert   detail::trie_traits<Key,Mapped,E_Access_Traits,Node_Update,Tag,Allocator>
560*404b540aSrobert 
561*404b540aSrobert #define PB_DS_BASE_C_DEC \
562*404b540aSrobert   basic_tree<Key,Mapped,Tag, typename PB_DS_TRIE_NODE_AND_ITS_TRAITS::node_update, \
563*404b540aSrobert 	     typename __gnu_cxx::typelist::create2<E_Access_Traits, PB_DS_TRIE_NODE_AND_ITS_TRAITS >::type, Allocator>
564*404b540aSrobert 
565*404b540aSrobert   // A concrete basic trie-based associative container.
566*404b540aSrobert   template<typename Key,
567*404b540aSrobert 	   typename Mapped,
568*404b540aSrobert 	   typename E_Access_Traits = typename detail::default_trie_e_access_traits<Key>::type,
569*404b540aSrobert 	   typename Tag = pat_trie_tag,
570*404b540aSrobert 	   template<typename Const_Node_Iterator,
571*404b540aSrobert 		    typename Node_Iterator,
572*404b540aSrobert 		    typename E_Access_Traits_,
573*404b540aSrobert 		    typename Allocator_>
574*404b540aSrobert   class Node_Update = null_trie_node_update,
575*404b540aSrobert 	   typename Allocator = std::allocator<char> >
576*404b540aSrobert   class trie : public PB_DS_BASE_C_DEC
577*404b540aSrobert   {
578*404b540aSrobert   private:
579*404b540aSrobert     typedef PB_DS_BASE_C_DEC base_type;
580*404b540aSrobert 
581*404b540aSrobert   public:
582*404b540aSrobert     // Element access traits type.
583*404b540aSrobert     typedef E_Access_Traits e_access_traits;
584*404b540aSrobert 
trie()585*404b540aSrobert     trie() { }
586*404b540aSrobert 
587*404b540aSrobert     // Constructor taking some policy objects. r_e_access_traits will
588*404b540aSrobert     // be copied by the E_Access_Traits object of the container
589*404b540aSrobert     // object.
trie(const e_access_traits & t)590*404b540aSrobert     trie(const e_access_traits& t)
591*404b540aSrobert     : base_type(t) { }
592*404b540aSrobert 
593*404b540aSrobert     // Constructor taking __iterators to a range of value_types. The
594*404b540aSrobert     // value_types between first_it and last_it will be inserted into
595*404b540aSrobert     // the container object.
596*404b540aSrobert     template<typename It>
trie(It first,It last)597*404b540aSrobert     trie(It first, It last)
598*404b540aSrobert     { base_type::copy_from_range(first, last); }
599*404b540aSrobert 
600*404b540aSrobert     // Constructor taking __iterators to a range of value_types and
601*404b540aSrobert     // some policy objects. The value_types between first_it and
602*404b540aSrobert     // last_it will be inserted into the container object.
603*404b540aSrobert     template<typename It>
trie(It first,It last,const e_access_traits & t)604*404b540aSrobert     trie(It first, It last, const e_access_traits& t)
605*404b540aSrobert     : base_type(t)
606*404b540aSrobert     { base_type::copy_from_range(first, last); }
607*404b540aSrobert 
trie(const trie & other)608*404b540aSrobert     trie(const trie& other)
609*404b540aSrobert     : base_type((const base_type&)other) { }
610*404b540aSrobert 
611*404b540aSrobert     virtual
~trie()612*404b540aSrobert     ~trie() { }
613*404b540aSrobert 
614*404b540aSrobert     trie&
operator =(const trie & other)615*404b540aSrobert     operator=(const trie& other)
616*404b540aSrobert     {
617*404b540aSrobert       if (this != &other)
618*404b540aSrobert 	{
619*404b540aSrobert 	  trie tmp(other);
620*404b540aSrobert 	  swap(tmp);
621*404b540aSrobert 	}
622*404b540aSrobert       return *this;
623*404b540aSrobert     }
624*404b540aSrobert 
625*404b540aSrobert     void
swap(trie & other)626*404b540aSrobert     swap(trie& other)
627*404b540aSrobert     { base_type::swap(other); }
628*404b540aSrobert   };
629*404b540aSrobert 
630*404b540aSrobert #undef PB_DS_BASE_C_DEC
631*404b540aSrobert #undef PB_DS_TRIE_NODE_AND_ITS_TRAITS
632*404b540aSrobert 
633*404b540aSrobert 
634*404b540aSrobert #define PB_DS_BASE_C_DEC \
635*404b540aSrobert   container_base<Key, Mapped, list_update_tag, \
636*404b540aSrobert 		 typename __gnu_cxx::typelist::create2<Eq_Fn, Update_Policy>::type, Allocator>
637*404b540aSrobert 
638*404b540aSrobert   // A list-update based associative container.
639*404b540aSrobert   template<typename Key,
640*404b540aSrobert 	   typename Mapped,
641*404b540aSrobert 	   class Eq_Fn = typename detail::default_eq_fn<Key>::type,
642*404b540aSrobert 	   class Update_Policy = detail::default_update_policy::type,
643*404b540aSrobert 	   class Allocator = std::allocator<char> >
644*404b540aSrobert   class list_update : public PB_DS_BASE_C_DEC
645*404b540aSrobert   {
646*404b540aSrobert   private:
647*404b540aSrobert     typedef PB_DS_BASE_C_DEC 	base_type;
648*404b540aSrobert 
649*404b540aSrobert   public:
650*404b540aSrobert     typedef Eq_Fn 		eq_fn;
651*404b540aSrobert     typedef Update_Policy 	update_policy;
652*404b540aSrobert     typedef Allocator 		allocator;
653*404b540aSrobert 
list_update()654*404b540aSrobert     list_update() { }
655*404b540aSrobert 
656*404b540aSrobert     // Constructor taking __iterators to a range of value_types. The
657*404b540aSrobert     // value_types between first_it and last_it will be inserted into
658*404b540aSrobert     // the container object.
659*404b540aSrobert     template<typename It>
list_update(It first,It last)660*404b540aSrobert     list_update(It first, It last)
661*404b540aSrobert     { base_type::copy_from_range(first, last); }
662*404b540aSrobert 
list_update(const list_update & other)663*404b540aSrobert     list_update(const list_update& other)
664*404b540aSrobert     : base_type((const base_type&)other) { }
665*404b540aSrobert 
666*404b540aSrobert     virtual
~list_update()667*404b540aSrobert     ~list_update() { }
668*404b540aSrobert 
669*404b540aSrobert     list_update&
operator =(const list_update & other)670*404b540aSrobert     operator=(const list_update& other)
671*404b540aSrobert     {
672*404b540aSrobert       if (this !=& other)
673*404b540aSrobert 	{
674*404b540aSrobert 	  list_update tmp(other);
675*404b540aSrobert 	  swap(tmp);
676*404b540aSrobert 	}
677*404b540aSrobert       return *this;
678*404b540aSrobert     }
679*404b540aSrobert 
680*404b540aSrobert     void
swap(list_update & other)681*404b540aSrobert     swap(list_update& other)
682*404b540aSrobert     { base_type::swap(other); }
683*404b540aSrobert   };
684*404b540aSrobert 
685*404b540aSrobert #undef PB_DS_BASE_C_DEC
686*404b540aSrobert 
687*404b540aSrobert } // namespace pb_ds
688*404b540aSrobert 
689*404b540aSrobert #endif
690