libstdc++
|
00001 // -*- C++ -*- 00002 00003 // Copyright (C) 2005-2015 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_/resize_fn_imps.hpp 00038 * Contains implementations of gp_ht_map_'s resize related functions. 00039 */ 00040 00041 PB_DS_CLASS_T_DEC 00042 inline bool 00043 PB_DS_CLASS_C_DEC:: 00044 do_resize_if_needed() 00045 { 00046 if (!resize_base::is_resize_needed()) 00047 return false; 00048 resize_imp(resize_base::get_new_size(m_num_e, m_num_used_e)); 00049 return true; 00050 } 00051 00052 PB_DS_CLASS_T_DEC 00053 void 00054 PB_DS_CLASS_C_DEC:: 00055 do_resize(size_type n) 00056 { resize_imp(resize_base::get_nearest_larger_size(n)); } 00057 00058 PB_DS_CLASS_T_DEC 00059 inline void 00060 PB_DS_CLASS_C_DEC:: 00061 do_resize_if_needed_no_throw() 00062 { 00063 if (!resize_base::is_resize_needed()) 00064 return; 00065 00066 __try 00067 { 00068 resize_imp(resize_base::get_new_size(m_num_e, m_num_used_e)); 00069 } 00070 __catch(...) 00071 { } 00072 00073 PB_DS_ASSERT_VALID((*this)) 00074 } 00075 00076 PB_DS_CLASS_T_DEC 00077 void 00078 PB_DS_CLASS_C_DEC:: 00079 resize_imp(size_type new_size) 00080 { 00081 #ifdef PB_DS_REGRESSION 00082 typename _Alloc::group_adjustor adjust(m_num_e); 00083 #endif 00084 00085 if (new_size == m_num_e) 00086 return; 00087 00088 PB_DS_ASSERT_VALID((*this)) 00089 const size_type old_size = m_num_e; 00090 entry_array a_entries_resized = 0; 00091 00092 // Following line might throw an exception. 00093 a_entries_resized = s_entry_allocator.allocate(new_size); 00094 00095 ranged_probe_fn_base::notify_resized(new_size); 00096 m_num_e = new_size; 00097 00098 for (size_type i = 0; i < m_num_e; ++i) 00099 a_entries_resized[i].m_stat = empty_entry_status; 00100 00101 __try 00102 { 00103 resize_imp(a_entries_resized, old_size); 00104 } 00105 __catch(...) 00106 { 00107 erase_all_valid_entries(a_entries_resized, new_size); 00108 m_num_e = old_size; 00109 s_entry_allocator.deallocate(a_entries_resized, new_size); 00110 ranged_probe_fn_base::notify_resized(old_size); 00111 __throw_exception_again; 00112 } 00113 00114 // At this point no exceptions can be thrown. 00115 _GLIBCXX_DEBUG_ONLY(assert_entry_array_valid(a_entries_resized, 00116 traits_base::m_store_extra_indicator, 00117 __FILE__, __LINE__);) 00118 00119 Resize_Policy::notify_resized(new_size); 00120 erase_all_valid_entries(m_entries, old_size); 00121 s_entry_allocator.deallocate(m_entries, old_size); 00122 m_entries = a_entries_resized; 00123 PB_DS_ASSERT_VALID((*this)) 00124 } 00125 00126 PB_DS_CLASS_T_DEC 00127 void 00128 PB_DS_CLASS_C_DEC:: 00129 resize_imp(entry_array a_entries_resized, size_type old_size) 00130 { 00131 for (size_type pos = 0; pos < old_size; ++pos) 00132 if (m_entries[pos].m_stat == valid_entry_status) 00133 resize_imp_reassign(m_entries + pos, a_entries_resized, 00134 traits_base::m_store_extra_indicator); 00135 } 00136 00137 #include <ext/pb_ds/detail/gp_hash_table_map_/resize_no_store_hash_fn_imps.hpp> 00138 #include <ext/pb_ds/detail/gp_hash_table_map_/resize_store_hash_fn_imps.hpp> 00139