]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/constructor_destructor_fn_imps.hpp
re PR libstdc++/29367 (pb_ds hash containers vs. _GLIBCXX_DEBUG)
[thirdparty/gcc.git] / libstdc++-v3 / include / ext / pb_ds / detail / gp_hash_table_map_ / constructor_destructor_fn_imps.hpp
CommitLineData
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
48PB_DS_CLASS_T_DEC
49typename PB_DS_CLASS_C_DEC::entry_allocator
50PB_DS_CLASS_C_DEC::s_entry_allocator;
51
52PB_DS_CLASS_T_DEC
53template<typename It>
54void
55PB_DS_CLASS_C_DEC::
56copy_from_range(It first_it, It last_it)
57{
58 while (first_it != last_it)
59 insert(*(first_it++));
60}
61
62PB_DS_CLASS_T_DEC
63PB_DS_CLASS_C_DEC::
3441f106
BK
64PB_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
73PB_DS_CLASS_T_DEC
74PB_DS_CLASS_C_DEC::
3441f106
BK
75PB_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
84PB_DS_CLASS_T_DEC
85PB_DS_CLASS_C_DEC::
3441f106
BK
86PB_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
96PB_DS_CLASS_T_DEC
97PB_DS_CLASS_C_DEC::
3441f106
BK
98PB_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
110PB_DS_CLASS_T_DEC
111PB_DS_CLASS_C_DEC::
3441f106 112PB_DS_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn,
1ab79481 113 const Comb_Probe_Fn& comb_hash_fn, const Probe_Fn& prober)
3441f106 114: hash_eq_fn_base(r_eq_fn),
4569a895 115 ranged_probe_fn_base(resize_base::get_nearest_larger_size(1),
1ab79481 116 r_hash_fn, comb_hash_fn, prober),
3441f106
BK
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
124PB_DS_CLASS_T_DEC
125PB_DS_CLASS_C_DEC::
3441f106 126PB_DS_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn,
1ab79481 127 const Comb_Probe_Fn& comb_hash_fn, const Probe_Fn& prober,
3441f106
BK
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),
1ab79481 131 r_hash_fn, comb_hash_fn, prober),
3441f106
BK
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
139PB_DS_CLASS_T_DEC
140PB_DS_CLASS_C_DEC::
141PB_DS_CLASS_NAME(const PB_DS_CLASS_C_DEC& other) :
47bea7b8 142#ifdef _GLIBCXX_DEBUG
551fe1a2 143 debug_base(other),
47bea7b8 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
172PB_DS_CLASS_T_DEC
173PB_DS_CLASS_C_DEC::
174~PB_DS_CLASS_NAME()
3441f106 175{ deallocate_all(); }
4569a895
AT
176
177PB_DS_CLASS_T_DEC
178void
179PB_DS_CLASS_C_DEC::
180swap(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);
551fe1a2 190 _GLIBCXX_DEBUG_ONLY(debug_base::swap(other));
47bea7b8
BK
191 _GLIBCXX_DEBUG_ONLY(assert_valid());
192 _GLIBCXX_DEBUG_ONLY(other.assert_valid());
4569a895
AT
193}
194
195PB_DS_CLASS_T_DEC
196void
197PB_DS_CLASS_C_DEC::
198deallocate_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
205PB_DS_CLASS_T_DEC
206void
207PB_DS_CLASS_C_DEC::
1ab79481 208erase_all_valid_entries(entry_array a_entries_resized, size_type len)
4569a895 209{
1ab79481 210 for (size_type pos = 0; pos < len; ++pos)
4569a895 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
218PB_DS_CLASS_T_DEC
219void
220PB_DS_CLASS_C_DEC::
221initialize()
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