Dead
[official-gcc.git] / gomp-20050608-branch / libstdc++-v3 / include / ext / pb_assoc / detail / gp_ht_map_ / constructor_destructor_fn_imps.hpp
blobcb42444c281ada7652cab860c4d359369a5e7f60
1 // -*- C++ -*-
3 // Copyright (C) 2005 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
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // USA.
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
30 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
32 // Permission to use, copy, modify, sell, and distribute this software
33 // is hereby granted without fee, provided that the above copyright
34 // notice appears in all copies, and that both that copyright notice and
35 // this permission notice appear in supporting documentation. None of
36 // the above authors, nor IBM Haifa Research Laboratories, make any
37 // representation about the suitability of this software for any
38 // purpose. It is provided "as is" without express or implied warranty.
40 /**
41 * @file constructor_destructor_fn_imps.hpp
42 * Contains implementations of gp_ht_map_'s constructors, destructor,
43 * and related functions.
46 PB_ASSOC_CLASS_T_DEC
47 typename PB_ASSOC_CLASS_C_DEC::entry_allocator
48 PB_ASSOC_CLASS_C_DEC::s_entry_allocator;
50 PB_ASSOC_CLASS_T_DEC
51 template<class It>
52 void
53 PB_ASSOC_CLASS_C_DEC::
54 copy_from_range(It first_it, It last_it)
56 while (first_it != last_it)
57 insert(*(first_it++));
60 PB_ASSOC_CLASS_T_DEC
61 PB_ASSOC_CLASS_C_DEC::
62 PB_ASSOC_CLASS_NAME() :
63 my_ranged_probe_fn_base(Resize_Policy::get_init_size()),
64 m_a_entries(s_entry_allocator.allocate(
65 Resize_Policy::get_init_size())),
66 m_num_e(Resize_Policy::get_init_size()),
67 m_num_used_e(0)
69 initialize();
71 PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
74 PB_ASSOC_CLASS_T_DEC
75 PB_ASSOC_CLASS_C_DEC::
76 PB_ASSOC_CLASS_NAME(const Hash_Fn& r_hash_fn) :
77 my_ranged_probe_fn_base(Resize_Policy::get_init_size(), r_hash_fn),
78 m_a_entries(s_entry_allocator.allocate(
79 Resize_Policy::get_init_size())),
80 m_num_e(Resize_Policy::get_init_size()),
81 m_num_used_e(0)
83 initialize();
85 PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
88 PB_ASSOC_CLASS_T_DEC
89 PB_ASSOC_CLASS_C_DEC::
90 PB_ASSOC_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn) :
91 my_hash_eq_fn_base(r_eq_fn),
92 my_ranged_probe_fn_base(Resize_Policy::get_init_size(), r_hash_fn),
93 m_a_entries(s_entry_allocator.allocate(
94 Resize_Policy::get_init_size())),
95 m_num_e(Resize_Policy::get_init_size()),
96 m_num_used_e(0)
98 initialize();
100 PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
103 PB_ASSOC_CLASS_T_DEC
104 PB_ASSOC_CLASS_C_DEC::
105 PB_ASSOC_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, const Comb_Probe_Fn& r_comb_hash_fn) :
106 my_hash_eq_fn_base(r_eq_fn),
107 my_ranged_probe_fn_base(Resize_Policy::get_init_size(),
108 r_hash_fn, r_comb_hash_fn),
109 m_a_entries(s_entry_allocator.allocate(
110 Resize_Policy::get_init_size())),
111 m_num_e(Resize_Policy::get_init_size()),
112 m_num_used_e(0)
114 initialize();
116 PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
119 PB_ASSOC_CLASS_T_DEC
120 PB_ASSOC_CLASS_C_DEC::
121 PB_ASSOC_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, const Comb_Probe_Fn& r_comb_hash_fn, const Probe_Fn& r_probe_fn) :
122 my_hash_eq_fn_base(r_eq_fn),
123 my_ranged_probe_fn_base(Resize_Policy::get_init_size(),
124 r_hash_fn, r_comb_hash_fn, r_probe_fn),
125 m_a_entries(s_entry_allocator.allocate(
126 Resize_Policy::get_init_size())),
127 m_num_e(Resize_Policy::get_init_size()),
128 m_num_used_e(0)
130 initialize();
132 PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
135 PB_ASSOC_CLASS_T_DEC
136 PB_ASSOC_CLASS_C_DEC::
137 PB_ASSOC_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, const Comb_Probe_Fn& r_comb_hash_fn, const Probe_Fn& r_probe_fn, const Resize_Policy& r_resize_policy) :
138 my_hash_eq_fn_base(r_eq_fn),
139 my_resize_base(r_resize_policy),
140 my_ranged_probe_fn_base(Resize_Policy::get_init_size(),
141 r_hash_fn, r_comb_hash_fn, r_probe_fn),
142 m_a_entries(s_entry_allocator.allocate(
143 Resize_Policy::get_init_size())),
144 m_num_e(Resize_Policy::get_init_size()),
145 m_num_used_e(0)
147 initialize();
149 PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_r_valid();)
152 PB_ASSOC_CLASS_T_DEC
153 PB_ASSOC_CLASS_C_DEC::
154 PB_ASSOC_CLASS_NAME(const PB_ASSOC_CLASS_C_DEC& r_other) :
155 my_hash_eq_fn_base(r_other),
156 my_resize_base(r_other),
157 my_ranged_probe_fn_base(r_other),
158 m_a_entries(s_entry_allocator.allocate(
159 r_other.m_num_e)),
160 m_num_e(r_other.m_num_e),
161 m_num_used_e(r_other.m_num_used_e)
163 initialize();
167 for (size_type i = 0; i < m_num_e; ++i)
169 entry_pointer p_e =& r_other.m_a_entries[i];
170 if (p_e->m_stat == VALID_ENTRY_STATUS)
171 constructor_insert_new_imp((const_mapped_reference)p_e->m_value,
173 my_hash_traits_base::s_store_hash_indicator);
176 catch(...)
178 deallocate_all();
180 throw;
183 PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
186 PB_ASSOC_CLASS_T_DEC
187 PB_ASSOC_CLASS_C_DEC::
188 ~PB_ASSOC_CLASS_NAME()
190 deallocate_all();
193 PB_ASSOC_CLASS_T_DEC
194 void
195 PB_ASSOC_CLASS_C_DEC::
196 swap(PB_ASSOC_CLASS_C_DEC& r_other)
198 PB_ASSOC_DBG_ONLY(assert_valid());
199 PB_ASSOC_DBG_ONLY(r_other.assert_valid());
201 std::swap(m_a_entries, r_other.m_a_entries);
203 std::swap(m_num_e, r_other.m_num_e);
205 std::swap(m_num_used_e, r_other.m_num_used_e);
207 my_ranged_probe_fn_base::swap(r_other);
209 my_hash_eq_fn_base::swap(r_other);
211 my_resize_base::swap(r_other);
213 PB_ASSOC_DBG_ONLY(my_cntnr_debug_base::swap(r_other));
215 PB_ASSOC_DBG_ONLY(assert_valid());
216 PB_ASSOC_DBG_ONLY(r_other.assert_valid());
219 PB_ASSOC_CLASS_T_DEC
220 void
221 PB_ASSOC_CLASS_C_DEC::
222 deallocate_all()
224 clear();
226 erase_all_valid_entries(m_a_entries, m_num_e);
228 s_entry_allocator.deallocate(m_a_entries, m_num_e);
231 PB_ASSOC_CLASS_T_DEC
232 void
233 PB_ASSOC_CLASS_C_DEC::
234 erase_all_valid_entries(entry_array a_entries_resized, size_type size)
236 for (size_type pos = 0; pos < size; ++pos)
238 entry_pointer p_e =& a_entries_resized[pos];
240 if (p_e->m_stat == VALID_ENTRY_STATUS)
241 p_e->m_value.~value_type();
245 PB_ASSOC_CLASS_T_DEC
246 void
247 PB_ASSOC_CLASS_C_DEC::
248 initialize()
250 for (size_type i = 0; i < m_num_e; ++i)
251 m_a_entries[i].m_stat = (entry_status)EMPTY_ENTRY_STATUS;
254 #include <ext/pb_assoc/detail/gp_ht_map_/constructor_destructor_store_hash_fn_imps.hpp>
255 #include <ext/pb_assoc/detail/gp_ht_map_/constructor_destructor_no_store_hash_fn_imps.hpp>