libstdc++
|
00001 // -*- C++ -*- 00002 00003 // Copyright (C) 2005-2013 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the terms 00007 // of the GNU General Public License as published by the Free Software 00008 // Foundation; either version 3, or (at your option) any later 00009 // version. 00010 00011 // This library is distributed in the hope that it will be useful, but 00012 // WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 // General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. 00026 00027 // Permission to use, copy, modify, sell, and distribute this software 00028 // is hereby granted without fee, provided that the above copyright 00029 // notice appears in all copies, and that both that copyright notice 00030 // and this permission notice appear in supporting documentation. None 00031 // of the above authors, nor IBM Haifa Research Laboratories, make any 00032 // representation about the suitability of this software for any 00033 // purpose. It is provided "as is" without express or implied 00034 // warranty. 00035 00036 /** 00037 * @file gp_hash_table_map_/constructor_destructor_fn_imps.hpp 00038 * Contains implementations of gp_ht_map_'s constructors, destructor, 00039 * and related functions. 00040 */ 00041 00042 PB_DS_CLASS_T_DEC 00043 typename PB_DS_CLASS_C_DEC::entry_allocator 00044 PB_DS_CLASS_C_DEC::s_entry_allocator; 00045 00046 PB_DS_CLASS_T_DEC 00047 template<typename It> 00048 void 00049 PB_DS_CLASS_C_DEC:: 00050 copy_from_range(It first_it, It last_it) 00051 { 00052 while (first_it != last_it) 00053 insert(*(first_it++)); 00054 } 00055 00056 PB_DS_CLASS_T_DEC 00057 PB_DS_CLASS_C_DEC:: 00058 PB_DS_GP_HASH_NAME() 00059 : ranged_probe_fn_base(resize_base::get_nearest_larger_size(1)), 00060 m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), 00061 m_entries(s_entry_allocator.allocate(m_num_e)) 00062 { 00063 initialize(); 00064 PB_DS_ASSERT_VALID((*this)) 00065 } 00066 00067 PB_DS_CLASS_T_DEC 00068 PB_DS_CLASS_C_DEC:: 00069 PB_DS_GP_HASH_NAME(const Hash_Fn& r_hash_fn) 00070 : ranged_probe_fn_base(resize_base::get_nearest_larger_size(1), r_hash_fn), 00071 m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), 00072 m_entries(s_entry_allocator.allocate(m_num_e)) 00073 { 00074 initialize(); 00075 PB_DS_ASSERT_VALID((*this)) 00076 } 00077 00078 PB_DS_CLASS_T_DEC 00079 PB_DS_CLASS_C_DEC:: 00080 PB_DS_GP_HASH_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn) 00081 : hash_eq_fn_base(r_eq_fn), 00082 ranged_probe_fn_base(resize_base::get_nearest_larger_size(1), r_hash_fn), 00083 m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), 00084 m_entries(s_entry_allocator.allocate(m_num_e)) 00085 { 00086 initialize(); 00087 PB_DS_ASSERT_VALID((*this)) 00088 } 00089 00090 PB_DS_CLASS_T_DEC 00091 PB_DS_CLASS_C_DEC:: 00092 PB_DS_GP_HASH_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, 00093 const Comb_Probe_Fn& r_comb_hash_fn) 00094 : hash_eq_fn_base(r_eq_fn), 00095 ranged_probe_fn_base(resize_base::get_nearest_larger_size(1), 00096 r_hash_fn, r_comb_hash_fn), 00097 m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), 00098 m_entries(s_entry_allocator.allocate(m_num_e)) 00099 { 00100 initialize(); 00101 PB_DS_ASSERT_VALID((*this)) 00102 } 00103 00104 PB_DS_CLASS_T_DEC 00105 PB_DS_CLASS_C_DEC:: 00106 PB_DS_GP_HASH_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, 00107 const Comb_Probe_Fn& comb_hash_fn, const Probe_Fn& prober) 00108 : hash_eq_fn_base(r_eq_fn), 00109 ranged_probe_fn_base(resize_base::get_nearest_larger_size(1), 00110 r_hash_fn, comb_hash_fn, prober), 00111 m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), 00112 m_entries(s_entry_allocator.allocate(m_num_e)) 00113 { 00114 initialize(); 00115 PB_DS_ASSERT_VALID((*this)) 00116 } 00117 00118 PB_DS_CLASS_T_DEC 00119 PB_DS_CLASS_C_DEC:: 00120 PB_DS_GP_HASH_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, 00121 const Comb_Probe_Fn& comb_hash_fn, const Probe_Fn& prober, 00122 const Resize_Policy& r_resize_policy) 00123 : hash_eq_fn_base(r_eq_fn), resize_base(r_resize_policy), 00124 ranged_probe_fn_base(resize_base::get_nearest_larger_size(1), 00125 r_hash_fn, comb_hash_fn, prober), 00126 m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), 00127 m_entries(s_entry_allocator.allocate(m_num_e)) 00128 { 00129 initialize(); 00130 PB_DS_ASSERT_VALID((*this)) 00131 } 00132 00133 PB_DS_CLASS_T_DEC 00134 PB_DS_CLASS_C_DEC:: 00135 PB_DS_GP_HASH_NAME(const PB_DS_CLASS_C_DEC& other) : 00136 #ifdef _GLIBCXX_DEBUG 00137 debug_base(other), 00138 #endif 00139 hash_eq_fn_base(other), 00140 resize_base(other), 00141 ranged_probe_fn_base(other), 00142 m_num_e(other.m_num_e), 00143 m_num_used_e(other.m_num_used_e), 00144 m_entries(s_entry_allocator.allocate(m_num_e)) 00145 { 00146 for (size_type i = 0; i < m_num_e; ++i) 00147 m_entries[i].m_stat = (entry_status)empty_entry_status; 00148 00149 __try 00150 { 00151 for (size_type i = 0; i < m_num_e; ++i) 00152 { 00153 m_entries[i].m_stat = other.m_entries[i].m_stat; 00154 if (m_entries[i].m_stat == valid_entry_status) 00155 new (m_entries + i) entry(other.m_entries[i]); 00156 } 00157 } 00158 __catch(...) 00159 { 00160 deallocate_all(); 00161 __throw_exception_again; 00162 } 00163 PB_DS_ASSERT_VALID((*this)) 00164 } 00165 00166 PB_DS_CLASS_T_DEC 00167 PB_DS_CLASS_C_DEC:: 00168 ~PB_DS_GP_HASH_NAME() 00169 { deallocate_all(); } 00170 00171 PB_DS_CLASS_T_DEC 00172 void 00173 PB_DS_CLASS_C_DEC:: 00174 swap(PB_DS_CLASS_C_DEC& other) 00175 { 00176 PB_DS_ASSERT_VALID((*this)) 00177 PB_DS_ASSERT_VALID(other) 00178 std::swap(m_num_e, other.m_num_e); 00179 std::swap(m_num_used_e, other.m_num_used_e); 00180 std::swap(m_entries, other.m_entries); 00181 ranged_probe_fn_base::swap(other); 00182 hash_eq_fn_base::swap(other); 00183 resize_base::swap(other); 00184 _GLIBCXX_DEBUG_ONLY(debug_base::swap(other)); 00185 PB_DS_ASSERT_VALID((*this)) 00186 PB_DS_ASSERT_VALID(other) 00187 } 00188 00189 PB_DS_CLASS_T_DEC 00190 void 00191 PB_DS_CLASS_C_DEC:: 00192 deallocate_all() 00193 { 00194 clear(); 00195 erase_all_valid_entries(m_entries, m_num_e); 00196 s_entry_allocator.deallocate(m_entries, m_num_e); 00197 } 00198 00199 PB_DS_CLASS_T_DEC 00200 void 00201 PB_DS_CLASS_C_DEC:: 00202 erase_all_valid_entries(entry_array a_entries_resized, size_type len) 00203 { 00204 for (size_type pos = 0; pos < len; ++pos) 00205 { 00206 entry_pointer p_e = &a_entries_resized[pos]; 00207 if (p_e->m_stat == valid_entry_status) 00208 p_e->m_value.~value_type(); 00209 } 00210 } 00211 00212 PB_DS_CLASS_T_DEC 00213 void 00214 PB_DS_CLASS_C_DEC:: 00215 initialize() 00216 { 00217 Resize_Policy::notify_resized(m_num_e); 00218 Resize_Policy::notify_cleared(); 00219 ranged_probe_fn_base::notify_resized(m_num_e); 00220 for (size_type i = 0; i < m_num_e; ++i) 00221 m_entries[i].m_stat = empty_entry_status; 00222 } 00223