3 // Copyright (C) 2005, 2006 Free Software Foundation, Inc.
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
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.
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.
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
31 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
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
43 * @file constructor_destructor_fn_imps.hpp
44 * Contains implementations of gp_ht_map_'s constructors, destructor,
45 * and related functions.
49 typename PB_DS_CLASS_C_DEC::entry_allocator
50 PB_DS_CLASS_C_DEC::s_entry_allocator;
56 copy_from_range(It first_it, It last_it)
58 while (first_it != last_it)
59 insert(*(first_it++));
65 ranged_probe_fn_base(resize_base::get_nearest_larger_size(1)),
66 m_a_entries(s_entry_allocator.allocate(resize_base::get_nearest_larger_size(1))),
67 m_num_e(resize_base::get_nearest_larger_size(1)),
71 _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
76 PB_DS_CLASS_NAME(const Hash_Fn& r_hash_fn) :
77 ranged_probe_fn_base(resize_base::get_nearest_larger_size(1), r_hash_fn),
78 m_a_entries(s_entry_allocator.allocate(resize_base::get_nearest_larger_size(1))),
79 m_num_e(resize_base::get_nearest_larger_size(1)),
83 _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
88 PB_DS_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn) :
89 hash_eq_fn_base(r_eq_fn),
90 ranged_probe_fn_base(resize_base::get_nearest_larger_size(1), r_hash_fn),
91 m_a_entries(s_entry_allocator.allocate(resize_base::get_nearest_larger_size(1))),
92 m_num_e(resize_base::get_nearest_larger_size(1)),
96 _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
101 PB_DS_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, const Comb_Probe_Fn& r_comb_hash_fn) :
102 hash_eq_fn_base(r_eq_fn),
103 ranged_probe_fn_base(resize_base::get_nearest_larger_size(1),
104 r_hash_fn, r_comb_hash_fn),
105 m_a_entries(s_entry_allocator.allocate(resize_base::get_nearest_larger_size(1))),
106 m_num_e(resize_base::get_nearest_larger_size(1)),
110 _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
115 PB_DS_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) :
116 hash_eq_fn_base(r_eq_fn),
117 ranged_probe_fn_base(resize_base::get_nearest_larger_size(1),
118 r_hash_fn, r_comb_hash_fn, r_probe_fn),
119 m_a_entries(s_entry_allocator.allocate(resize_base::get_nearest_larger_size(1))),
120 m_num_e(resize_base::get_nearest_larger_size(1)),
124 _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
129 PB_DS_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) :
130 hash_eq_fn_base(r_eq_fn),
131 resize_base(r_resize_policy),
132 ranged_probe_fn_base(resize_base::get_nearest_larger_size(1),
133 r_hash_fn, r_comb_hash_fn, r_probe_fn),
134 m_a_entries(s_entry_allocator.allocate(resize_base::get_nearest_larger_size(1))),
135 m_num_e(resize_base::get_nearest_larger_size(1)),
139 _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
144 PB_DS_CLASS_NAME(const PB_DS_CLASS_C_DEC& other) :
145 #ifdef _GLIBCXX_DEBUG
146 map_debug_base(other),
148 hash_eq_fn_base(other),
150 ranged_probe_fn_base(other),
151 m_a_entries(s_entry_allocator.allocate(other.m_num_e)),
152 m_num_e(other.m_num_e),
153 m_num_used_e(other.m_num_used_e)
155 for (size_type i = 0; i < m_num_e; ++i)
156 m_a_entries[i].m_stat = (entry_status)empty_entry_status;
160 for (size_type i = 0; i < m_num_e; ++i)
162 m_a_entries[i].m_stat = other.m_a_entries[i].m_stat;
163 if (m_a_entries[i].m_stat == valid_entry_status)
164 new (m_a_entries + i) entry(other.m_a_entries[i]);
173 _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
186 swap(PB_DS_CLASS_C_DEC& other)
188 _GLIBCXX_DEBUG_ONLY(assert_valid());
189 _GLIBCXX_DEBUG_ONLY(other.assert_valid());
190 std::swap(m_a_entries, other.m_a_entries);
191 std::swap(m_num_e, other.m_num_e);
192 std::swap(m_num_used_e, other.m_num_used_e);
193 ranged_probe_fn_base::swap(other);
194 hash_eq_fn_base::swap(other);
195 resize_base::swap(other);
196 _GLIBCXX_DEBUG_ONLY(map_debug_base::swap(other));
197 _GLIBCXX_DEBUG_ONLY(assert_valid());
198 _GLIBCXX_DEBUG_ONLY(other.assert_valid());
207 erase_all_valid_entries(m_a_entries, m_num_e);
208 s_entry_allocator.deallocate(m_a_entries, m_num_e);
214 erase_all_valid_entries(entry_array a_entries_resized, size_type size)
216 for (size_type pos = 0; pos < size; ++pos)
218 entry_pointer p_e =& a_entries_resized[pos];
219 if (p_e->m_stat == valid_entry_status)
220 p_e->m_value.~value_type();
229 Resize_Policy::notify_resized(m_num_e);
230 Resize_Policy::notify_cleared();
231 ranged_probe_fn_base::notify_resized(m_num_e);
232 for (size_type i = 0; i < m_num_e; ++i)
233 m_a_entries[i].m_stat = (entry_status)empty_entry_status;