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 cc_hash_table_map_/constructor_destructor_fn_imps.hpp 00038 * Contains implementations of cc_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 typename PB_DS_CLASS_C_DEC::entry_pointer_allocator 00048 PB_DS_CLASS_C_DEC::s_entry_pointer_allocator; 00049 00050 PB_DS_CLASS_T_DEC 00051 template<typename It> 00052 void 00053 PB_DS_CLASS_C_DEC:: 00054 copy_from_range(It first_it, It last_it) 00055 { 00056 while (first_it != last_it) 00057 insert(*(first_it++)); 00058 } 00059 00060 PB_DS_CLASS_T_DEC 00061 PB_DS_CLASS_C_DEC:: 00062 PB_DS_CC_HASH_NAME() : 00063 ranged_hash_fn_base(resize_base::get_nearest_larger_size(1)), 00064 m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), 00065 m_entries(s_entry_pointer_allocator.allocate(m_num_e)) 00066 { 00067 initialize(); 00068 PB_DS_ASSERT_VALID((*this)) 00069 } 00070 00071 PB_DS_CLASS_T_DEC 00072 PB_DS_CLASS_C_DEC:: 00073 PB_DS_CC_HASH_NAME(const Hash_Fn& r_hash_fn) : 00074 ranged_hash_fn_base(resize_base::get_nearest_larger_size(1), r_hash_fn), 00075 m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), 00076 m_entries(s_entry_pointer_allocator.allocate(m_num_e)) 00077 { 00078 initialize(); 00079 PB_DS_ASSERT_VALID((*this)) 00080 } 00081 00082 PB_DS_CLASS_T_DEC 00083 PB_DS_CLASS_C_DEC:: 00084 PB_DS_CC_HASH_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn) : 00085 PB_DS_HASH_EQ_FN_C_DEC(r_eq_fn), 00086 ranged_hash_fn_base(resize_base::get_nearest_larger_size(1), r_hash_fn), 00087 m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), 00088 m_entries(s_entry_pointer_allocator.allocate(m_num_e)) 00089 { 00090 std::fill(m_entries, m_entries + m_num_e, (entry_pointer)0); 00091 Resize_Policy::notify_cleared(); 00092 ranged_hash_fn_base::notify_resized(m_num_e); 00093 PB_DS_ASSERT_VALID((*this)) 00094 } 00095 00096 PB_DS_CLASS_T_DEC 00097 PB_DS_CLASS_C_DEC:: 00098 PB_DS_CC_HASH_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, 00099 const Comb_Hash_Fn& r_comb_hash_fn) : 00100 PB_DS_HASH_EQ_FN_C_DEC(r_eq_fn), 00101 ranged_hash_fn_base(resize_base::get_nearest_larger_size(1), 00102 r_hash_fn, r_comb_hash_fn), 00103 m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), 00104 m_entries(s_entry_pointer_allocator.allocate(m_num_e)) 00105 { 00106 initialize(); 00107 PB_DS_ASSERT_VALID((*this)) 00108 } 00109 00110 PB_DS_CLASS_T_DEC 00111 PB_DS_CLASS_C_DEC:: 00112 PB_DS_CC_HASH_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, 00113 const Comb_Hash_Fn& r_comb_hash_fn, 00114 const Resize_Policy& r_resize_policy) : 00115 PB_DS_HASH_EQ_FN_C_DEC(r_eq_fn), 00116 Resize_Policy(r_resize_policy), 00117 ranged_hash_fn_base(resize_base::get_nearest_larger_size(1), 00118 r_hash_fn, r_comb_hash_fn), 00119 m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), 00120 m_entries(s_entry_pointer_allocator.allocate(m_num_e)) 00121 { 00122 initialize(); 00123 PB_DS_ASSERT_VALID((*this)) 00124 } 00125 00126 PB_DS_CLASS_T_DEC 00127 PB_DS_CLASS_C_DEC:: 00128 PB_DS_CC_HASH_NAME(const PB_DS_CLASS_C_DEC& other) : 00129 PB_DS_HASH_EQ_FN_C_DEC(other), 00130 resize_base(other), ranged_hash_fn_base(other), 00131 m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), 00132 m_entries(s_entry_pointer_allocator.allocate(m_num_e)) 00133 { 00134 initialize(); 00135 PB_DS_ASSERT_VALID((*this)) 00136 __try 00137 { 00138 copy_from_range(other.begin(), other.end()); 00139 } 00140 __catch(...) 00141 { 00142 deallocate_all(); 00143 __throw_exception_again; 00144 } 00145 PB_DS_ASSERT_VALID((*this)) 00146 } 00147 00148 PB_DS_CLASS_T_DEC 00149 PB_DS_CLASS_C_DEC:: 00150 ~PB_DS_CC_HASH_NAME() 00151 { deallocate_all(); } 00152 00153 PB_DS_CLASS_T_DEC 00154 void 00155 PB_DS_CLASS_C_DEC:: 00156 swap(PB_DS_CLASS_C_DEC& other) 00157 { 00158 PB_DS_ASSERT_VALID((*this)) 00159 PB_DS_ASSERT_VALID(other) 00160 00161 std::swap(m_entries, other.m_entries); 00162 std::swap(m_num_e, other.m_num_e); 00163 std::swap(m_num_used_e, other.m_num_used_e); 00164 ranged_hash_fn_base::swap(other); 00165 hash_eq_fn_base::swap(other); 00166 resize_base::swap(other); 00167 00168 _GLIBCXX_DEBUG_ONLY(debug_base::swap(other)); 00169 PB_DS_ASSERT_VALID((*this)) 00170 PB_DS_ASSERT_VALID(other) 00171 } 00172 00173 PB_DS_CLASS_T_DEC 00174 void 00175 PB_DS_CLASS_C_DEC:: 00176 deallocate_all() 00177 { 00178 clear(); 00179 s_entry_pointer_allocator.deallocate(m_entries, m_num_e); 00180 } 00181 00182 PB_DS_CLASS_T_DEC 00183 void 00184 PB_DS_CLASS_C_DEC:: 00185 initialize() 00186 { 00187 std::fill(m_entries, m_entries + m_num_e, entry_pointer(0)); 00188 Resize_Policy::notify_resized(m_num_e); 00189 Resize_Policy::notify_cleared(); 00190 ranged_hash_fn_base::notify_resized(m_num_e); 00191 }