Import gcc-4.4.1
[dragonfly.git] / contrib / gcc-4.4 / libstdc++-v3 / include / ext / pb_ds / detail / gp_hash_table_map_ / constructor_destructor_fn_imps.hpp
1 // -*- C++ -*-
2
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
4 //
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 3, or (at your option) any later
9 // version.
10
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.
15
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23 // <http://www.gnu.org/licenses/>.
24
25 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
26
27 // Permission to use, copy, modify, sell, and distribute this software
28 // is hereby granted without fee, provided that the above copyright
29 // notice appears in all copies, and that both that copyright notice
30 // and this permission notice appear in supporting documentation. None
31 // of the above authors, nor IBM Haifa Research Laboratories, make any
32 // representation about the suitability of this software for any
33 // purpose. It is provided "as is" without express or implied
34 // warranty.
35
36 /**
37  * @file constructor_destructor_fn_imps.hpp
38  * Contains implementations of gp_ht_map_'s constructors, destructor,
39  *    and related functions.
40  */
41
42 PB_DS_CLASS_T_DEC
43 typename PB_DS_CLASS_C_DEC::entry_allocator
44 PB_DS_CLASS_C_DEC::s_entry_allocator;
45
46 PB_DS_CLASS_T_DEC
47 template<typename It>
48 void
49 PB_DS_CLASS_C_DEC::
50 copy_from_range(It first_it, It last_it)
51 {
52   while (first_it != last_it)
53     insert(*(first_it++));
54 }
55
56 PB_DS_CLASS_T_DEC
57 PB_DS_CLASS_C_DEC::
58 PB_DS_CLASS_NAME() 
59 : ranged_probe_fn_base(resize_base::get_nearest_larger_size(1)),
60   m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0),
61   m_entries(s_entry_allocator.allocate(m_num_e))
62 {
63   initialize();
64   _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
65 }
66
67 PB_DS_CLASS_T_DEC
68 PB_DS_CLASS_C_DEC::
69 PB_DS_CLASS_NAME(const Hash_Fn& r_hash_fn)    
70 : ranged_probe_fn_base(resize_base::get_nearest_larger_size(1), r_hash_fn),
71   m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0),
72   m_entries(s_entry_allocator.allocate(m_num_e))
73 {
74   initialize();
75   _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
76 }
77
78 PB_DS_CLASS_T_DEC
79 PB_DS_CLASS_C_DEC::
80 PB_DS_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn) 
81 : hash_eq_fn_base(r_eq_fn),
82   ranged_probe_fn_base(resize_base::get_nearest_larger_size(1), r_hash_fn),
83   m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0),
84   m_entries(s_entry_allocator.allocate(m_num_e))
85 {
86   initialize();
87   _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
88 }
89
90 PB_DS_CLASS_T_DEC
91 PB_DS_CLASS_C_DEC::
92 PB_DS_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, 
93                  const Comb_Probe_Fn& r_comb_hash_fn) 
94 : hash_eq_fn_base(r_eq_fn),
95   ranged_probe_fn_base(resize_base::get_nearest_larger_size(1),
96                        r_hash_fn, r_comb_hash_fn),
97   m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0),
98   m_entries(s_entry_allocator.allocate(m_num_e))
99 {
100   initialize();
101   _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
102 }
103
104 PB_DS_CLASS_T_DEC
105 PB_DS_CLASS_C_DEC::
106 PB_DS_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, 
107                  const Comb_Probe_Fn& comb_hash_fn, const Probe_Fn& prober) 
108 : hash_eq_fn_base(r_eq_fn),
109   ranged_probe_fn_base(resize_base::get_nearest_larger_size(1),
110                        r_hash_fn, comb_hash_fn, prober),
111   m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0),
112   m_entries(s_entry_allocator.allocate(m_num_e))
113 {
114   initialize();
115   _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
116 }
117
118 PB_DS_CLASS_T_DEC
119 PB_DS_CLASS_C_DEC::
120 PB_DS_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, 
121                  const Comb_Probe_Fn& comb_hash_fn, const Probe_Fn& prober, 
122                  const Resize_Policy& r_resize_policy) 
123 : hash_eq_fn_base(r_eq_fn), resize_base(r_resize_policy),
124   ranged_probe_fn_base(resize_base::get_nearest_larger_size(1),
125                        r_hash_fn, comb_hash_fn, prober),
126   m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0),
127   m_entries(s_entry_allocator.allocate(m_num_e))
128 {
129   initialize();
130   _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
131 }
132
133 PB_DS_CLASS_T_DEC
134 PB_DS_CLASS_C_DEC::
135 PB_DS_CLASS_NAME(const PB_DS_CLASS_C_DEC& other) :
136 #ifdef _GLIBCXX_DEBUG
137   debug_base(other),
138 #endif 
139   hash_eq_fn_base(other),
140   resize_base(other),
141   ranged_probe_fn_base(other),
142   m_num_e(other.m_num_e),
143   m_num_used_e(other.m_num_used_e),
144   m_entries(s_entry_allocator.allocate(m_num_e))
145 {
146   for (size_type i = 0; i < m_num_e; ++i)
147     m_entries[i].m_stat = (entry_status)empty_entry_status;
148
149   __try
150     {
151       for (size_type i = 0; i < m_num_e; ++i)
152         {
153           m_entries[i].m_stat = other.m_entries[i].m_stat;
154           if (m_entries[i].m_stat == valid_entry_status)
155             new (m_entries + i) entry(other.m_entries[i]);
156         }
157     }
158   __catch(...)
159     {
160       deallocate_all();
161       __throw_exception_again;
162     }
163   _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
164 }
165
166 PB_DS_CLASS_T_DEC
167 PB_DS_CLASS_C_DEC::
168 ~PB_DS_CLASS_NAME()
169 { deallocate_all(); }
170
171 PB_DS_CLASS_T_DEC
172 void
173 PB_DS_CLASS_C_DEC::
174 swap(PB_DS_CLASS_C_DEC& other)
175 {
176   _GLIBCXX_DEBUG_ONLY(assert_valid());
177   _GLIBCXX_DEBUG_ONLY(other.assert_valid());
178   std::swap(m_num_e, other.m_num_e);
179   std::swap(m_num_used_e, other.m_num_used_e);
180   std::swap(m_entries, other.m_entries);
181   ranged_probe_fn_base::swap(other);
182   hash_eq_fn_base::swap(other);
183   resize_base::swap(other);
184   _GLIBCXX_DEBUG_ONLY(debug_base::swap(other));
185   _GLIBCXX_DEBUG_ONLY(assert_valid());
186   _GLIBCXX_DEBUG_ONLY(other.assert_valid());
187 }
188
189 PB_DS_CLASS_T_DEC
190 void
191 PB_DS_CLASS_C_DEC::
192 deallocate_all()
193 {
194   clear();
195   erase_all_valid_entries(m_entries, m_num_e);
196   s_entry_allocator.deallocate(m_entries, m_num_e);
197 }
198
199 PB_DS_CLASS_T_DEC
200 void
201 PB_DS_CLASS_C_DEC::
202 erase_all_valid_entries(entry_array a_entries_resized, size_type len)
203 {
204   for (size_type pos = 0; pos < len; ++pos)
205     {
206       entry_pointer p_e = &a_entries_resized[pos];
207       if (p_e->m_stat == valid_entry_status)
208         p_e->m_value.~value_type();
209     }
210 }
211
212 PB_DS_CLASS_T_DEC
213 void
214 PB_DS_CLASS_C_DEC::
215 initialize()
216 {
217   Resize_Policy::notify_resized(m_num_e);
218   Resize_Policy::notify_cleared();
219   ranged_probe_fn_base::notify_resized(m_num_e);
220   for (size_type i = 0; i < m_num_e; ++i)
221     m_entries[i].m_stat = empty_entry_status;
222 }
223