]>
Commit | Line | Data |
---|---|---|
4569a895 AT |
1 | // -*- C++ -*- |
2 | ||
7adcbafe | 3 | // Copyright (C) 2005-2022 Free Software Foundation, Inc. |
4569a895 AT |
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 | |
748086b7 | 8 | // Foundation; either version 3, or (at your option) any later |
4569a895 AT |
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 | ||
748086b7 JJ |
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. | |
4569a895 | 19 | |
748086b7 JJ |
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/>. | |
4569a895 AT |
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 | /** | |
a345e45d | 37 | * @file gp_hash_table_map_/constructor_destructor_fn_imps.hpp |
4569a895 | 38 | * Contains implementations of gp_ht_map_'s constructors, destructor, |
a345e45d | 39 | * and related functions. |
4569a895 AT |
40 | */ |
41 | ||
574dfb67 JW |
42 | #ifdef PB_DS_CLASS_C_DEC |
43 | ||
4569a895 AT |
44 | PB_DS_CLASS_T_DEC |
45 | typename PB_DS_CLASS_C_DEC::entry_allocator | |
46 | PB_DS_CLASS_C_DEC::s_entry_allocator; | |
47 | ||
48 | PB_DS_CLASS_T_DEC | |
49 | template<typename It> | |
50 | void | |
51 | PB_DS_CLASS_C_DEC:: | |
52 | copy_from_range(It first_it, It last_it) | |
53 | { | |
54 | while (first_it != last_it) | |
55 | insert(*(first_it++)); | |
56 | } | |
57 | ||
58 | PB_DS_CLASS_T_DEC | |
59 | PB_DS_CLASS_C_DEC:: | |
a345e45d | 60 | PB_DS_GP_HASH_NAME() |
3441f106 BK |
61 | : ranged_probe_fn_base(resize_base::get_nearest_larger_size(1)), |
62 | m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), | |
63 | m_entries(s_entry_allocator.allocate(m_num_e)) | |
4569a895 AT |
64 | { |
65 | initialize(); | |
f5886803 | 66 | PB_DS_ASSERT_VALID((*this)) |
47bea7b8 | 67 | } |
4569a895 AT |
68 | |
69 | PB_DS_CLASS_T_DEC | |
70 | PB_DS_CLASS_C_DEC:: | |
a345e45d | 71 | PB_DS_GP_HASH_NAME(const Hash_Fn& r_hash_fn) |
3441f106 BK |
72 | : ranged_probe_fn_base(resize_base::get_nearest_larger_size(1), r_hash_fn), |
73 | m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), | |
74 | m_entries(s_entry_allocator.allocate(m_num_e)) | |
4569a895 AT |
75 | { |
76 | initialize(); | |
f5886803 | 77 | PB_DS_ASSERT_VALID((*this)) |
47bea7b8 | 78 | } |
4569a895 AT |
79 | |
80 | PB_DS_CLASS_T_DEC | |
81 | PB_DS_CLASS_C_DEC:: | |
a345e45d | 82 | PB_DS_GP_HASH_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn) |
3441f106 | 83 | : hash_eq_fn_base(r_eq_fn), |
4569a895 | 84 | ranged_probe_fn_base(resize_base::get_nearest_larger_size(1), r_hash_fn), |
3441f106 BK |
85 | m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), |
86 | m_entries(s_entry_allocator.allocate(m_num_e)) | |
4569a895 AT |
87 | { |
88 | initialize(); | |
f5886803 | 89 | PB_DS_ASSERT_VALID((*this)) |
47bea7b8 | 90 | } |
4569a895 AT |
91 | |
92 | PB_DS_CLASS_T_DEC | |
93 | PB_DS_CLASS_C_DEC:: | |
a345e45d | 94 | PB_DS_GP_HASH_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, |
3441f106 BK |
95 | const Comb_Probe_Fn& r_comb_hash_fn) |
96 | : hash_eq_fn_base(r_eq_fn), | |
4569a895 AT |
97 | ranged_probe_fn_base(resize_base::get_nearest_larger_size(1), |
98 | r_hash_fn, r_comb_hash_fn), | |
3441f106 BK |
99 | m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), |
100 | m_entries(s_entry_allocator.allocate(m_num_e)) | |
4569a895 AT |
101 | { |
102 | initialize(); | |
f5886803 | 103 | PB_DS_ASSERT_VALID((*this)) |
47bea7b8 | 104 | } |
4569a895 AT |
105 | |
106 | PB_DS_CLASS_T_DEC | |
107 | PB_DS_CLASS_C_DEC:: | |
a345e45d | 108 | PB_DS_GP_HASH_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, |
1ab79481 | 109 | const Comb_Probe_Fn& comb_hash_fn, const Probe_Fn& prober) |
3441f106 | 110 | : hash_eq_fn_base(r_eq_fn), |
4569a895 | 111 | ranged_probe_fn_base(resize_base::get_nearest_larger_size(1), |
1ab79481 | 112 | r_hash_fn, comb_hash_fn, prober), |
3441f106 BK |
113 | m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), |
114 | m_entries(s_entry_allocator.allocate(m_num_e)) | |
4569a895 AT |
115 | { |
116 | initialize(); | |
f5886803 | 117 | PB_DS_ASSERT_VALID((*this)) |
47bea7b8 | 118 | } |
4569a895 AT |
119 | |
120 | PB_DS_CLASS_T_DEC | |
121 | PB_DS_CLASS_C_DEC:: | |
a345e45d | 122 | PB_DS_GP_HASH_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, |
1ab79481 | 123 | const Comb_Probe_Fn& comb_hash_fn, const Probe_Fn& prober, |
3441f106 BK |
124 | const Resize_Policy& r_resize_policy) |
125 | : hash_eq_fn_base(r_eq_fn), resize_base(r_resize_policy), | |
4569a895 | 126 | ranged_probe_fn_base(resize_base::get_nearest_larger_size(1), |
1ab79481 | 127 | r_hash_fn, comb_hash_fn, prober), |
3441f106 BK |
128 | m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), |
129 | m_entries(s_entry_allocator.allocate(m_num_e)) | |
4569a895 AT |
130 | { |
131 | initialize(); | |
f5886803 | 132 | PB_DS_ASSERT_VALID((*this)) |
47bea7b8 | 133 | } |
4569a895 AT |
134 | |
135 | PB_DS_CLASS_T_DEC | |
136 | PB_DS_CLASS_C_DEC:: | |
a345e45d | 137 | PB_DS_GP_HASH_NAME(const PB_DS_CLASS_C_DEC& other) : |
47bea7b8 | 138 | #ifdef _GLIBCXX_DEBUG |
551fe1a2 | 139 | debug_base(other), |
47bea7b8 | 140 | #endif |
4569a895 AT |
141 | hash_eq_fn_base(other), |
142 | resize_base(other), | |
143 | ranged_probe_fn_base(other), | |
4569a895 | 144 | m_num_e(other.m_num_e), |
3441f106 BK |
145 | m_num_used_e(other.m_num_used_e), |
146 | m_entries(s_entry_allocator.allocate(m_num_e)) | |
4569a895 AT |
147 | { |
148 | for (size_type i = 0; i < m_num_e; ++i) | |
3441f106 | 149 | m_entries[i].m_stat = (entry_status)empty_entry_status; |
4569a895 | 150 | |
bc2631e0 | 151 | __try |
4569a895 AT |
152 | { |
153 | for (size_type i = 0; i < m_num_e; ++i) | |
154 | { | |
3441f106 BK |
155 | m_entries[i].m_stat = other.m_entries[i].m_stat; |
156 | if (m_entries[i].m_stat == valid_entry_status) | |
157 | new (m_entries + i) entry(other.m_entries[i]); | |
4569a895 AT |
158 | } |
159 | } | |
bc2631e0 | 160 | __catch(...) |
4569a895 AT |
161 | { |
162 | deallocate_all(); | |
8fafc2d3 | 163 | __throw_exception_again; |
4569a895 | 164 | } |
f5886803 | 165 | PB_DS_ASSERT_VALID((*this)) |
3441f106 | 166 | } |
4569a895 AT |
167 | |
168 | PB_DS_CLASS_T_DEC | |
169 | PB_DS_CLASS_C_DEC:: | |
a345e45d | 170 | ~PB_DS_GP_HASH_NAME() |
3441f106 | 171 | { deallocate_all(); } |
4569a895 AT |
172 | |
173 | PB_DS_CLASS_T_DEC | |
174 | void | |
175 | PB_DS_CLASS_C_DEC:: | |
176 | swap(PB_DS_CLASS_C_DEC& other) | |
177 | { | |
f5886803 FD |
178 | PB_DS_ASSERT_VALID((*this)) |
179 | PB_DS_ASSERT_VALID(other) | |
4569a895 | 180 | std::swap(m_num_e, other.m_num_e); |
4569a895 | 181 | std::swap(m_num_used_e, other.m_num_used_e); |
3441f106 | 182 | std::swap(m_entries, other.m_entries); |
4569a895 | 183 | ranged_probe_fn_base::swap(other); |
4569a895 | 184 | hash_eq_fn_base::swap(other); |
4569a895 | 185 | resize_base::swap(other); |
551fe1a2 | 186 | _GLIBCXX_DEBUG_ONLY(debug_base::swap(other)); |
f5886803 FD |
187 | PB_DS_ASSERT_VALID((*this)) |
188 | PB_DS_ASSERT_VALID(other) | |
4569a895 AT |
189 | } |
190 | ||
191 | PB_DS_CLASS_T_DEC | |
192 | void | |
193 | PB_DS_CLASS_C_DEC:: | |
194 | deallocate_all() | |
195 | { | |
196 | clear(); | |
3441f106 BK |
197 | erase_all_valid_entries(m_entries, m_num_e); |
198 | s_entry_allocator.deallocate(m_entries, m_num_e); | |
4569a895 AT |
199 | } |
200 | ||
201 | PB_DS_CLASS_T_DEC | |
202 | void | |
203 | PB_DS_CLASS_C_DEC:: | |
1ab79481 | 204 | erase_all_valid_entries(entry_array a_entries_resized, size_type len) |
4569a895 | 205 | { |
1ab79481 | 206 | for (size_type pos = 0; pos < len; ++pos) |
4569a895 | 207 | { |
3441f106 | 208 | entry_pointer p_e = &a_entries_resized[pos]; |
4569a895 AT |
209 | if (p_e->m_stat == valid_entry_status) |
210 | p_e->m_value.~value_type(); | |
211 | } | |
212 | } | |
213 | ||
214 | PB_DS_CLASS_T_DEC | |
215 | void | |
216 | PB_DS_CLASS_C_DEC:: | |
217 | initialize() | |
218 | { | |
219 | Resize_Policy::notify_resized(m_num_e); | |
4569a895 | 220 | Resize_Policy::notify_cleared(); |
4569a895 | 221 | ranged_probe_fn_base::notify_resized(m_num_e); |
4569a895 | 222 | for (size_type i = 0; i < m_num_e; ++i) |
3441f106 | 223 | m_entries[i].m_stat = empty_entry_status; |
4569a895 AT |
224 | } |
225 | ||
574dfb67 | 226 | #endif |