]>
Commit | Line | Data |
---|---|---|
4569a895 AT |
1 | // -*- C++ -*- |
2 | ||
3 | // Copyright (C) 2005, 2006 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 2, 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 | // You should have received a copy of the GNU General Public License | |
17 | // along with this library; see the file COPYING. If not, write to | |
18 | // the Free Software Foundation, 59 Temple Place - Suite 330, Boston, | |
19 | // MA 02111-1307, USA. | |
20 | ||
21 | // As a special exception, you may use this file as part of a free | |
22 | // software library without restriction. Specifically, if other files | |
23 | // instantiate templates or use macros or inline functions from this | |
24 | // file, or you compile this file and link it with other files to | |
25 | // produce an executable, this file does not by itself cause the | |
26 | // resulting executable to be covered by the GNU General Public | |
27 | // License. This exception does not however invalidate any other | |
28 | // reasons why the executable file might be covered by the GNU General | |
29 | // Public License. | |
30 | ||
31 | // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. | |
32 | ||
33 | // Permission to use, copy, modify, sell, and distribute this software | |
34 | // is hereby granted without fee, provided that the above copyright | |
35 | // notice appears in all copies, and that both that copyright notice | |
36 | // and this permission notice appear in supporting documentation. None | |
37 | // of the above authors, nor IBM Haifa Research Laboratories, make any | |
38 | // representation about the suitability of this software for any | |
39 | // purpose. It is provided "as is" without express or implied | |
40 | // warranty. | |
41 | ||
42 | /** | |
43 | * @file constructor_destructor_fn_imps.hpp | |
44 | * Contains implementations of gp_ht_map_'s constructors, destructor, | |
45 | * and related functions. | |
46 | */ | |
47 | ||
48 | PB_DS_CLASS_T_DEC | |
49 | typename PB_DS_CLASS_C_DEC::entry_allocator | |
50 | PB_DS_CLASS_C_DEC::s_entry_allocator; | |
51 | ||
52 | PB_DS_CLASS_T_DEC | |
53 | template<typename It> | |
54 | void | |
55 | PB_DS_CLASS_C_DEC:: | |
56 | copy_from_range(It first_it, It last_it) | |
57 | { | |
58 | while (first_it != last_it) | |
59 | insert(*(first_it++)); | |
60 | } | |
61 | ||
62 | PB_DS_CLASS_T_DEC | |
63 | PB_DS_CLASS_C_DEC:: | |
3441f106 BK |
64 | PB_DS_CLASS_NAME() |
65 | : ranged_probe_fn_base(resize_base::get_nearest_larger_size(1)), | |
66 | m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), | |
67 | m_entries(s_entry_allocator.allocate(m_num_e)) | |
4569a895 AT |
68 | { |
69 | initialize(); | |
47bea7b8 BK |
70 | _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) |
71 | } | |
4569a895 AT |
72 | |
73 | PB_DS_CLASS_T_DEC | |
74 | PB_DS_CLASS_C_DEC:: | |
3441f106 BK |
75 | PB_DS_CLASS_NAME(const Hash_Fn& r_hash_fn) |
76 | : ranged_probe_fn_base(resize_base::get_nearest_larger_size(1), r_hash_fn), | |
77 | m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), | |
78 | m_entries(s_entry_allocator.allocate(m_num_e)) | |
4569a895 AT |
79 | { |
80 | initialize(); | |
47bea7b8 BK |
81 | _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) |
82 | } | |
4569a895 AT |
83 | |
84 | PB_DS_CLASS_T_DEC | |
85 | PB_DS_CLASS_C_DEC:: | |
3441f106 BK |
86 | PB_DS_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn) |
87 | : hash_eq_fn_base(r_eq_fn), | |
4569a895 | 88 | ranged_probe_fn_base(resize_base::get_nearest_larger_size(1), r_hash_fn), |
3441f106 BK |
89 | m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), |
90 | m_entries(s_entry_allocator.allocate(m_num_e)) | |
4569a895 AT |
91 | { |
92 | initialize(); | |
47bea7b8 BK |
93 | _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) |
94 | } | |
4569a895 AT |
95 | |
96 | PB_DS_CLASS_T_DEC | |
97 | PB_DS_CLASS_C_DEC:: | |
3441f106 BK |
98 | PB_DS_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, |
99 | const Comb_Probe_Fn& r_comb_hash_fn) | |
100 | : hash_eq_fn_base(r_eq_fn), | |
4569a895 AT |
101 | ranged_probe_fn_base(resize_base::get_nearest_larger_size(1), |
102 | r_hash_fn, r_comb_hash_fn), | |
3441f106 BK |
103 | m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), |
104 | m_entries(s_entry_allocator.allocate(m_num_e)) | |
4569a895 AT |
105 | { |
106 | initialize(); | |
47bea7b8 BK |
107 | _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) |
108 | } | |
4569a895 AT |
109 | |
110 | PB_DS_CLASS_T_DEC | |
111 | PB_DS_CLASS_C_DEC:: | |
3441f106 BK |
112 | PB_DS_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, |
113 | const Comb_Probe_Fn& comb_hash_fn, const Probe_Fn& probe_fn) | |
114 | : hash_eq_fn_base(r_eq_fn), | |
4569a895 | 115 | ranged_probe_fn_base(resize_base::get_nearest_larger_size(1), |
3441f106 BK |
116 | r_hash_fn, comb_hash_fn, probe_fn), |
117 | m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), | |
118 | m_entries(s_entry_allocator.allocate(m_num_e)) | |
4569a895 AT |
119 | { |
120 | initialize(); | |
47bea7b8 BK |
121 | _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) |
122 | } | |
4569a895 AT |
123 | |
124 | PB_DS_CLASS_T_DEC | |
125 | PB_DS_CLASS_C_DEC:: | |
3441f106 BK |
126 | PB_DS_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, |
127 | const Comb_Probe_Fn& comb_hash_fn, const Probe_Fn& probe_fn, | |
128 | const Resize_Policy& r_resize_policy) | |
129 | : hash_eq_fn_base(r_eq_fn), resize_base(r_resize_policy), | |
4569a895 | 130 | ranged_probe_fn_base(resize_base::get_nearest_larger_size(1), |
3441f106 BK |
131 | r_hash_fn, comb_hash_fn, probe_fn), |
132 | m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), | |
133 | m_entries(s_entry_allocator.allocate(m_num_e)) | |
4569a895 AT |
134 | { |
135 | initialize(); | |
47bea7b8 BK |
136 | _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) |
137 | } | |
4569a895 AT |
138 | |
139 | PB_DS_CLASS_T_DEC | |
140 | PB_DS_CLASS_C_DEC:: | |
141 | PB_DS_CLASS_NAME(const PB_DS_CLASS_C_DEC& other) : | |
47bea7b8 BK |
142 | #ifdef _GLIBCXX_DEBUG |
143 | map_debug_base(other), | |
144 | #endif | |
4569a895 AT |
145 | hash_eq_fn_base(other), |
146 | resize_base(other), | |
147 | ranged_probe_fn_base(other), | |
4569a895 | 148 | m_num_e(other.m_num_e), |
3441f106 BK |
149 | m_num_used_e(other.m_num_used_e), |
150 | m_entries(s_entry_allocator.allocate(m_num_e)) | |
4569a895 AT |
151 | { |
152 | for (size_type i = 0; i < m_num_e; ++i) | |
3441f106 | 153 | m_entries[i].m_stat = (entry_status)empty_entry_status; |
4569a895 AT |
154 | |
155 | try | |
156 | { | |
157 | for (size_type i = 0; i < m_num_e; ++i) | |
158 | { | |
3441f106 BK |
159 | m_entries[i].m_stat = other.m_entries[i].m_stat; |
160 | if (m_entries[i].m_stat == valid_entry_status) | |
161 | new (m_entries + i) entry(other.m_entries[i]); | |
4569a895 AT |
162 | } |
163 | } | |
1b24692f | 164 | catch(...) |
4569a895 AT |
165 | { |
166 | deallocate_all(); | |
8fafc2d3 | 167 | __throw_exception_again; |
4569a895 | 168 | } |
47bea7b8 | 169 | _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) |
3441f106 | 170 | } |
4569a895 AT |
171 | |
172 | PB_DS_CLASS_T_DEC | |
173 | PB_DS_CLASS_C_DEC:: | |
174 | ~PB_DS_CLASS_NAME() | |
3441f106 | 175 | { deallocate_all(); } |
4569a895 AT |
176 | |
177 | PB_DS_CLASS_T_DEC | |
178 | void | |
179 | PB_DS_CLASS_C_DEC:: | |
180 | swap(PB_DS_CLASS_C_DEC& other) | |
181 | { | |
47bea7b8 BK |
182 | _GLIBCXX_DEBUG_ONLY(assert_valid()); |
183 | _GLIBCXX_DEBUG_ONLY(other.assert_valid()); | |
4569a895 | 184 | std::swap(m_num_e, other.m_num_e); |
4569a895 | 185 | std::swap(m_num_used_e, other.m_num_used_e); |
3441f106 | 186 | std::swap(m_entries, other.m_entries); |
4569a895 | 187 | ranged_probe_fn_base::swap(other); |
4569a895 | 188 | hash_eq_fn_base::swap(other); |
4569a895 | 189 | resize_base::swap(other); |
47bea7b8 BK |
190 | _GLIBCXX_DEBUG_ONLY(map_debug_base::swap(other)); |
191 | _GLIBCXX_DEBUG_ONLY(assert_valid()); | |
192 | _GLIBCXX_DEBUG_ONLY(other.assert_valid()); | |
4569a895 AT |
193 | } |
194 | ||
195 | PB_DS_CLASS_T_DEC | |
196 | void | |
197 | PB_DS_CLASS_C_DEC:: | |
198 | deallocate_all() | |
199 | { | |
200 | clear(); | |
3441f106 BK |
201 | erase_all_valid_entries(m_entries, m_num_e); |
202 | s_entry_allocator.deallocate(m_entries, m_num_e); | |
4569a895 AT |
203 | } |
204 | ||
205 | PB_DS_CLASS_T_DEC | |
206 | void | |
207 | PB_DS_CLASS_C_DEC:: | |
208 | erase_all_valid_entries(entry_array a_entries_resized, size_type size) | |
209 | { | |
210 | for (size_type pos = 0; pos < size; ++pos) | |
211 | { | |
3441f106 | 212 | entry_pointer p_e = &a_entries_resized[pos]; |
4569a895 AT |
213 | if (p_e->m_stat == valid_entry_status) |
214 | p_e->m_value.~value_type(); | |
215 | } | |
216 | } | |
217 | ||
218 | PB_DS_CLASS_T_DEC | |
219 | void | |
220 | PB_DS_CLASS_C_DEC:: | |
221 | initialize() | |
222 | { | |
223 | Resize_Policy::notify_resized(m_num_e); | |
4569a895 | 224 | Resize_Policy::notify_cleared(); |
4569a895 | 225 | ranged_probe_fn_base::notify_resized(m_num_e); |
4569a895 | 226 | for (size_type i = 0; i < m_num_e; ++i) |
3441f106 | 227 | m_entries[i].m_stat = empty_entry_status; |
4569a895 AT |
228 | } |
229 |